Java Code Examples for javax.websocket.server.ServerEndpoint

The following are top voted examples for showing how to use javax.websocket.server.ServerEndpoint. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: spring4-understanding   File:   View source code 6 votes vote down vote up
 * Actually register the endpoints. Called by {@link #afterSingletonsInstantiated()}.
protected void registerEndpoints() {
	Set<Class<?>> endpointClasses = new LinkedHashSet<Class<?>>();
	if (this.annotatedEndpointClasses != null) {

	ApplicationContext context = getApplicationContext();
	if (context != null) {
		String[] endpointBeanNames = context.getBeanNamesForAnnotation(ServerEndpoint.class);
		for (String beanName : endpointBeanNames) {

	for (Class<?> endpointClass : endpointClasses) {

	if (context != null) {
		Map<String, ServerEndpointConfig> endpointConfigMap = context.getBeansOfType(ServerEndpointConfig.class);
		for (ServerEndpointConfig endpointConfig : endpointConfigMap.values()) {
Example 2
Project: guice-websocket   File:   View source code 5 votes vote down vote up
private ServerEndpointConfig createEndpointConfig(Class<?> endpointClass) throws DeploymentException {
    ServerEndpoint annotation = endpointClass.getAnnotation(ServerEndpoint.class);
    if (annotation == null) {
        throw new InvalidWebSocketException("Unsupported WebSocket object, missing @" + ServerEndpoint.class + " annotation");

    return ServerEndpointConfig.Builder.create(endpointClass, annotation.value())
Example 3
Project: jboot   File:   View source code 5 votes vote down vote up
private JbootWebsocketManager() {
    List<Class> endPointClasses = ClassScanner.scanClassByAnnotation(ServerEndpoint.class, false);
    if (endPointClasses != null && endPointClasses.size() != 0) {
        for (Class entry : endPointClasses) {
            ServerEndpoint serverEndpoint = (ServerEndpoint) entry.getAnnotation(ServerEndpoint.class);
            String value = serverEndpoint.value();
            if (!StringUtils.isBlank(value)) {
Example 4
Project: minijax   File:   View source code 5 votes vote down vote up
public static void init(final ServletContextHandler context, final MinijaxApplication application)
        throws ServletException, DeploymentException {

    final ServerContainer container = WebSocketServerContainerInitializer.configureContext(context);
    final Configurator configurator = new MinijaxWebSocketConfigurator(application);

    for (final Class<?> c : application.getWebSockets()) {
        final ServerEndpointConfig config = ServerEndpointConfig.Builder
                .create(c, c.getAnnotation(ServerEndpoint.class).value())
Example 5
Project: dropwizard-websocket-jee7-bundle   File:   View source code 5 votes vote down vote up
private String determineAnnotatedEndpointPath(Class<?> endpointClass) {
    if (endpointClass.isAnnotationPresent(ServerEndpoint.class)) {
        return endpointClass.getAnnotation(ServerEndpoint.class).value();
    } else {
        throw new IllegalArgumentException(String.format("@ServerEndpoint annotation not found on Websocket-class: '%s'. Either annotate the class or register it as a programmatic endpoint using ServerEndpointConfig.class", endpointClass));
Example 6
Project: msf4j   File:   View source code 5 votes vote down vote up
 * Validate the endpoint against the {@link ServerEndpoint} since without {@link ServerEndpoint} definition
 * there can't be a WebSocket endpoint.
 * @param websocketEndpoint endpoint which should be validated.
public boolean validateEndpointUri(Object websocketEndpoint) {
    if (websocketEndpoint != null) {
        return websocketEndpoint.getClass().isAnnotationPresent(ServerEndpoint.class);
    return false;
Example 7
Project: dropwizard-websockets   File:   View source code 5 votes vote down vote up
public EventDriver create(Object websocket, WebSocketPolicy policy) throws Throwable {
    if (!(websocket instanceof EndpointInstance)) {
        throw new IllegalStateException(String.format("Websocket %s must be an %s", websocket.getClass().getName(), EndpointInstance.class.getName()));

    EndpointInstance ei = (EndpointInstance) websocket;
    AnnotatedServerEndpointMetadata metadata = (AnnotatedServerEndpointMetadata) ei.getMetadata();
    JsrEvents<ServerEndpoint, ServerEndpointConfig> events = new JsrEvents<>(metadata);

    // Handle @OnMessage maxMessageSizes
    int maxBinaryMessage = getMaxMessageSize(policy.getMaxBinaryMessageSize(), metadata.onBinary, metadata.onBinaryStream);
    int maxTextMessage = getMaxMessageSize(policy.getMaxTextMessageSize(), metadata.onText, metadata.onTextStream);


    //////// instrumentation is here
    JsrAnnotatedEventDriver driver = new InstJsrAnnotatedEventDriver(policy, ei, events, metrics);
    // Handle @PathParam values
    ServerEndpointConfig config = (ServerEndpointConfig) ei.getConfig();
    if (config instanceof PathParamServerEndpointConfig) {
        PathParamServerEndpointConfig ppconfig = (PathParamServerEndpointConfig) config;

    return driver;
Example 8
Project: dropwizard-websockets   File:   View source code 5 votes vote down vote up
public void addEndpoint(Class<?> clazz) {
    ServerEndpoint anno = clazz.getAnnotation(ServerEndpoint.class);
    if(anno == null){
        throw new RuntimeException(clazz.getCanonicalName()+" does not have a "+ServerEndpoint.class.getCanonicalName()+" annotation");
    ServerEndpointConfig.Builder bldr =  ServerEndpointConfig.Builder.create(clazz, anno.value());
    if(defaultConfigurator != null){
        bldr = bldr.configurator(defaultConfigurator);
    if (starting)
        throw new RuntimeException("can't add endpoint after starting lifecycle");
Example 9
Project: ccow   File:   View source code 4 votes vote down vote up
protected boolean isEndpoint(final Class<?> cls) {
  return cls.isAnnotationPresent(ServerEndpoint.class);
Example 10
Project: msf4j   File:   View source code 4 votes vote down vote up
private boolean validateURI(Object webSocketEndpoint) throws WebSocketEndpointAnnotationException {
    if (webSocketEndpoint.getClass().isAnnotationPresent(ServerEndpoint.class)) {
        return true;
    throw new WebSocketEndpointAnnotationException("Server Endpoint is not defined.");
Example 11
Project: dropwizard-websockets   File:   View source code 4 votes vote down vote up
public InstJsrAnnotatedEventDriver(WebSocketPolicy policy, EndpointInstance ei, JsrEvents<ServerEndpoint, ServerEndpointConfig> events, MetricRegistry metrics) {
    super(policy, ei, events);
    this.edm = new EventDriverMetrics(metadata.getEndpointClass(), metrics);
Example 12
Project: hammock   File:   View source code 4 votes vote down vote up
public void findWebSocketServers(@Observes @WithAnnotations(ServerEndpoint.class)ProcessAnnotatedType<?> pat) {
Example 13
Project: feathercon   File:   View source code 4 votes vote down vote up
private void requireServerEndPointAnnotation(Class c) {
    Annotation annotation = c.getAnnotation(ServerEndpoint.class);
    if (annotation == null) {
        throw new IllegalArgumentException(String.format("Endpoint class must be annotated with javax.websocket.server.ServerEndpoint"));
Example 14
Project: msf4j   File:   View source code 2 votes vote down vote up
 * Extract the URI from the endpoint.
 * <b>Note that it is better use validateEndpointUri method to validate the endpoint uri
 * before getting it out if needed. Otherwise it will cause issues. Use this method only and only if
 * it is sure that endpoint contains {@link ServerEndpoint} defined.</b>
 * @param webSocketEndpoint WebSocket endpoint which the URI should be extracted.
 * @return the URI of the Endpoint as a String.
public String getUri(Object webSocketEndpoint) {
    return webSocketEndpoint.getClass().getAnnotation(ServerEndpoint.class).value();