Search in sources :

Example 11 with ServerEndpoint

use of javax.websocket.server.ServerEndpoint in project wildfly by wildfly.

the class UndertowJSRWebSocketDeploymentProcessor method doDeployment.

private void doDeployment(DeploymentUnit deploymentUnit, final WebSocketDeploymentInfo container, final Set<Class<?>> annotatedEndpoints, final Set<Class<? extends ServerApplicationConfig>> serverApplicationConfigClasses, final Set<Class<? extends Endpoint>> endpoints) throws DeploymentUnitProcessingException {
    Set<Class<? extends Endpoint>> allScannedEndpointImplementations = new HashSet<>(endpoints);
    Set<Class<?>> allScannedAnnotatedEndpoints = new HashSet<>(annotatedEndpoints);
    Set<Class<?>> newAnnotatatedEndpoints = new HashSet<>();
    Set<ServerEndpointConfig> serverEndpointConfigurations = new HashSet<>();
    final Set<ServerApplicationConfig> configInstances = new HashSet<>();
    for (Class<? extends ServerApplicationConfig> clazz : serverApplicationConfigClasses) {
        try {
            configInstances.add(clazz.newInstance());
        } catch (InstantiationException | IllegalAccessException e) {
            JsrWebSocketLogger.ROOT_LOGGER.couldNotInitializeConfiguration(clazz, e);
        }
    }
    if (!configInstances.isEmpty()) {
        for (ServerApplicationConfig config : configInstances) {
            Set<Class<?>> returnedEndpoints = config.getAnnotatedEndpointClasses(allScannedAnnotatedEndpoints);
            if (returnedEndpoints != null) {
                newAnnotatatedEndpoints.addAll(returnedEndpoints);
            }
            Set<ServerEndpointConfig> endpointConfigs = config.getEndpointConfigs(allScannedEndpointImplementations);
            if (endpointConfigs != null) {
                serverEndpointConfigurations.addAll(endpointConfigs);
            }
        }
    } else {
        newAnnotatatedEndpoints.addAll(allScannedAnnotatedEndpoints);
    }
    //annotated endpoints first
    for (Class<?> endpoint : newAnnotatatedEndpoints) {
        if (endpoint != null) {
            container.addEndpoint(endpoint);
            ServerEndpoint annotation = endpoint.getAnnotation(ServerEndpoint.class);
            if (annotation != null) {
                String path = annotation.value();
                addManagementWebsocket(deploymentUnit, endpoint, path);
            }
        }
    }
    for (final ServerEndpointConfig endpoint : serverEndpointConfigurations) {
        if (endpoint != null) {
            container.addEndpoint(endpoint);
            addManagementWebsocket(deploymentUnit, endpoint.getEndpointClass(), endpoint.getPath());
        }
    }
}
Also used : ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) ServerApplicationConfig(javax.websocket.server.ServerApplicationConfig) ServerEndpoint(javax.websocket.server.ServerEndpoint) Endpoint(javax.websocket.Endpoint) ServerEndpoint(javax.websocket.server.ServerEndpoint) ClientEndpoint(javax.websocket.ClientEndpoint) HashSet(java.util.HashSet)

Aggregations

ServerEndpoint (javax.websocket.server.ServerEndpoint)11 ServerEndpointConfig (javax.websocket.server.ServerEndpointConfig)9 DeploymentException (javax.websocket.DeploymentException)4 AnnotatedEndpointScanner (org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointScanner)4 Endpoint (javax.websocket.Endpoint)3 SimpleContainerScope (org.eclipse.jetty.websocket.common.scopes.SimpleContainerScope)3 WebSocketContainerScope (org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope)3 EndpointInstance (org.eclipse.jetty.websocket.jsr356.endpoints.EndpointInstance)3 HashSet (java.util.HashSet)2 ServletException (javax.servlet.ServletException)2 ClientEndpoint (javax.websocket.ClientEndpoint)2 ServerApplicationConfig (javax.websocket.server.ServerApplicationConfig)2 Test (org.junit.Test)2 InstanceFactory (io.undertow.servlet.api.InstanceFactory)1 ConstructorInstanceFactory (io.undertow.servlet.util.ConstructorInstanceFactory)1 PathTemplate (io.undertow.util.PathTemplate)1 AnnotatedEndpointFactory (io.undertow.websockets.jsr.annotated.AnnotatedEndpointFactory)1 IOException (java.io.IOException)1 URI (java.net.URI)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1