Search in sources :

Example 41 with ServerEndpointConfig

use of javax.websocket.server.ServerEndpointConfig in project tomcat70 by apache.

the class TestWsServerContainer method testDuplicatePaths_03.

@Test(expected = javax.websocket.DeploymentException.class)
public void testDuplicatePaths_03() throws Exception {
    WsServerContainer sc = new WsServerContainer(new TesterServletContext());
    ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(Object.class, "/a/b/{var1}").build();
    ServerEndpointConfig configB = ServerEndpointConfig.Builder.create(Object.class, "/a/b/{var2}").build();
    sc.addEndpoint(configA);
    sc.addEndpoint(configB);
}
Also used : TesterServletContext(org.apache.tomcat.unittest.TesterServletContext) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) Test(org.junit.Test) WebSocketBaseTest(org.apache.tomcat.websocket.WebSocketBaseTest)

Example 42 with ServerEndpointConfig

use of javax.websocket.server.ServerEndpointConfig in project tomcat70 by apache.

the class TestWsServerContainer method testSpecExample4.

@Test
public void testSpecExample4() throws Exception {
    WsServerContainer sc = new WsServerContainer(new TesterServletContext());
    ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(Object.class, "/{var1}/d").build();
    ServerEndpointConfig configB = ServerEndpointConfig.Builder.create(Object.class, "/b/{var2}").build();
    sc.addEndpoint(configA);
    sc.addEndpoint(configB);
    Assert.assertEquals(configB, sc.findMapping("/b/d").getConfig());
}
Also used : TesterServletContext(org.apache.tomcat.unittest.TesterServletContext) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) Test(org.junit.Test) WebSocketBaseTest(org.apache.tomcat.websocket.WebSocketBaseTest)

Example 43 with ServerEndpointConfig

use of javax.websocket.server.ServerEndpointConfig in project tomcat70 by apache.

the class TestWsServerContainer method testDuplicatePaths_04.

@Test
public void testDuplicatePaths_04() throws Exception {
    WsServerContainer sc = new WsServerContainer(new TesterServletContext());
    ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(Object.class, "/a/{var1}/{var2}").build();
    ServerEndpointConfig configB = ServerEndpointConfig.Builder.create(Object.class, "/a/b/{var2}").build();
    sc.addEndpoint(configA);
    sc.addEndpoint(configB);
    Assert.assertEquals(configA, sc.findMapping("/a/x/y").getConfig());
    Assert.assertEquals(configB, sc.findMapping("/a/b/y").getConfig());
}
Also used : TesterServletContext(org.apache.tomcat.unittest.TesterServletContext) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) Test(org.junit.Test) WebSocketBaseTest(org.apache.tomcat.websocket.WebSocketBaseTest)

Example 44 with ServerEndpointConfig

use of javax.websocket.server.ServerEndpointConfig in project minijax by minijax.

the class MinijaxWebSocketUtils method init.

public static void init(final DeploymentInfo deploymentInfo, final MinijaxApplication application) {
    final WebSocketDeploymentInfo webSockets = new WebSocketDeploymentInfo();
    for (final Class<?> endpoint : application.getWebSockets()) {
        final ServerEndpoint serverEndpoint = endpoint.getAnnotation(ServerEndpoint.class);
        final MinijaxWebSocketConfigurator configurator = new MinijaxWebSocketConfigurator(application, endpoint);
        final ServerEndpointConfig endpointConfig = ServerEndpointConfig.Builder.create(AnnotatedEndpoint.class, serverEndpoint.value()).configurator(configurator).build();
        webSockets.addEndpoint(endpointConfig);
    }
    deploymentInfo.addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, webSockets);
}
Also used : ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) ServerEndpoint(javax.websocket.server.ServerEndpoint)

Example 45 with ServerEndpointConfig

use of javax.websocket.server.ServerEndpointConfig 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

ServerEndpointConfig (javax.websocket.server.ServerEndpointConfig)49 DeploymentException (javax.websocket.DeploymentException)17 ServerEndpoint (javax.websocket.server.ServerEndpoint)14 Test (org.junit.Test)13 ServletException (javax.servlet.ServletException)10 TesterServletContext (org.apache.tomcat.unittest.TesterServletContext)10 WebSocketBaseTest (org.apache.tomcat.websocket.WebSocketBaseTest)10 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)7 Endpoint (javax.websocket.Endpoint)6 ServerContainer (javax.websocket.server.ServerContainer)6 Server (org.eclipse.jetty.server.Server)6 ServerConnector (org.eclipse.jetty.server.ServerConnector)6 IOException (java.io.IOException)5 EndpointInstance (org.eclipse.jetty.websocket.jsr356.endpoints.EndpointInstance)5 Before (org.junit.Before)5 HandshakeResponse (javax.websocket.HandshakeResponse)4 HandshakeRequest (javax.websocket.server.HandshakeRequest)4 WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3