Search in sources :

Example 6 with ServerEndpointConfig

use of jakarta.websocket.server.ServerEndpointConfig in project tomcat by apache.

the class TestWsServerContainer method testDuplicatePaths02.

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

Example 7 with ServerEndpointConfig

use of jakarta.websocket.server.ServerEndpointConfig in project tomcat by apache.

the class TestWsServerContainer method testDuplicatePaths12.

/*
     * POJO auto deployment followed by programmatic duplicate. Keep POJO.
     */
@Test
public void testDuplicatePaths12() throws Exception {
    WsServerContainer sc = new WsServerContainer(new TesterServletContext());
    ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(Pojo.class, "/foo").build();
    sc.addEndpoint(Pojo.class, true);
    sc.addEndpoint(configA);
    Assert.assertNotEquals(configA, sc.findMapping("/foo").getConfig());
}
Also used : TesterServletContext(org.apache.tomcat.unittest.TesterServletContext) ServerEndpointConfig(jakarta.websocket.server.ServerEndpointConfig) Test(org.junit.Test) WebSocketBaseTest(org.apache.tomcat.websocket.WebSocketBaseTest)

Example 8 with ServerEndpointConfig

use of jakarta.websocket.server.ServerEndpointConfig in project tomcat by apache.

the class TestWsServerContainer method testSpecExample3.

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

Example 9 with ServerEndpointConfig

use of jakarta.websocket.server.ServerEndpointConfig in project tomcat by apache.

the class TestWsServerContainer method testDuplicatePaths24.

/*
     * POJO auto deployment followed by programmatic on same path.
     */
@Test(expected = DeploymentException.class)
public void testDuplicatePaths24() throws Exception {
    WsServerContainer sc = new WsServerContainer(new TesterServletContext());
    ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(Object.class, "/foo/{a}").build();
    sc.addEndpoint(PojoTemplate.class, true);
    sc.addEndpoint(configA);
}
Also used : TesterServletContext(org.apache.tomcat.unittest.TesterServletContext) ServerEndpointConfig(jakarta.websocket.server.ServerEndpointConfig) Test(org.junit.Test) WebSocketBaseTest(org.apache.tomcat.websocket.WebSocketBaseTest)

Example 10 with ServerEndpointConfig

use of jakarta.websocket.server.ServerEndpointConfig in project spring-framework by spring-projects.

the class ServerEndpointExporter method registerEndpoints.

/**
 * Actually register the endpoints. Called by {@link #afterSingletonsInstantiated()}.
 */
protected void registerEndpoints() {
    Set<Class<?>> endpointClasses = new LinkedHashSet<>();
    if (this.annotatedEndpointClasses != null) {
        endpointClasses.addAll(this.annotatedEndpointClasses);
    }
    ApplicationContext context = getApplicationContext();
    if (context != null) {
        String[] endpointBeanNames = context.getBeanNamesForAnnotation(ServerEndpoint.class);
        for (String beanName : endpointBeanNames) {
            endpointClasses.add(context.getType(beanName));
        }
    }
    for (Class<?> endpointClass : endpointClasses) {
        registerEndpoint(endpointClass);
    }
    if (context != null) {
        Map<String, ServerEndpointConfig> endpointConfigMap = context.getBeansOfType(ServerEndpointConfig.class);
        for (ServerEndpointConfig endpointConfig : endpointConfigMap.values()) {
            registerEndpoint(endpointConfig);
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ApplicationContext(org.springframework.context.ApplicationContext) ServerEndpointConfig(jakarta.websocket.server.ServerEndpointConfig)

Aggregations

ServerEndpointConfig (jakarta.websocket.server.ServerEndpointConfig)20 TesterServletContext (org.apache.tomcat.unittest.TesterServletContext)14 WebSocketBaseTest (org.apache.tomcat.websocket.WebSocketBaseTest)14 Test (org.junit.Test)14 DeploymentException (jakarta.websocket.DeploymentException)4 ServerEndpoint (jakarta.websocket.server.ServerEndpoint)2 ServletException (jakarta.servlet.ServletException)1 Endpoint (jakarta.websocket.Endpoint)1 ServerApplicationConfig (jakarta.websocket.server.ServerApplicationConfig)1 ServerContainer (jakarta.websocket.server.ServerContainer)1 Configurator (jakarta.websocket.server.ServerEndpointConfig.Configurator)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 ApplicationContext (org.springframework.context.ApplicationContext)1