Search in sources :

Example 1 with ServerEndpointConfig

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

the class PojoEndpointServer method onOpen.

@Override
public void onOpen(Session session, EndpointConfig endpointConfig) {
    ServerEndpointConfig sec = (ServerEndpointConfig) endpointConfig;
    PojoMethodMapping methodMapping = (PojoMethodMapping) sec.getUserProperties().get(Constants.POJO_METHOD_MAPPING_KEY);
    setMethodMapping(methodMapping);
    doOnOpen(session, endpointConfig);
}
Also used : ServerEndpointConfig(jakarta.websocket.server.ServerEndpointConfig)

Example 2 with ServerEndpointConfig

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

the class WsServerContainer method findMapping.

public WsMappingResult findMapping(String path) {
    // been made to use one
    if (addAllowed) {
        addAllowed = false;
    }
    // Check an exact match. Simple case as there are no templates.
    ExactPathMatch match = configExactMatchMap.get(path);
    if (match != null) {
        return new WsMappingResult(match.getConfig(), Collections.<String, String>emptyMap());
    }
    // No exact match. Need to look for template matches.
    UriTemplate pathUriTemplate = null;
    try {
        pathUriTemplate = new UriTemplate(path);
    } catch (DeploymentException e) {
        // Path is not valid so can't be matched to a WebSocketEndpoint
        return null;
    }
    // Number of segments has to match
    Integer key = Integer.valueOf(pathUriTemplate.getSegmentCount());
    ConcurrentSkipListMap<String, TemplatePathMatch> templateMatches = configTemplateMatchMap.get(key);
    if (templateMatches == null) {
        // no matches
        return null;
    }
    // List is in alphabetical order of normalised templates.
    // Correct match is the first one that matches.
    ServerEndpointConfig sec = null;
    Map<String, String> pathParams = null;
    for (TemplatePathMatch templateMatch : templateMatches.values()) {
        pathParams = templateMatch.getUriTemplate().match(pathUriTemplate);
        if (pathParams != null) {
            sec = templateMatch.getConfig();
            break;
        }
    }
    if (sec == null) {
        // No match
        return null;
    }
    return new WsMappingResult(sec, pathParams);
}
Also used : ServerEndpointConfig(jakarta.websocket.server.ServerEndpointConfig) DeploymentException(jakarta.websocket.DeploymentException)

Example 3 with ServerEndpointConfig

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

the class TestWsServerContainer method testDuplicatePaths13.

/*
     * POJO programmatic followed by programmatic duplicate.
     */
@Test(expected = DeploymentException.class)
public void testDuplicatePaths13() throws Exception {
    WsServerContainer sc = new WsServerContainer(new TesterServletContext());
    ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(Pojo.class, "/foo").build();
    sc.addEndpoint(Pojo.class);
    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 4 with ServerEndpointConfig

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

the class TestWsServerContainer method testDuplicatePaths01.

@Test(expected = DeploymentException.class)
public void testDuplicatePaths01() throws Exception {
    WsServerContainer sc = new WsServerContainer(new TesterServletContext());
    ServerEndpointConfig configA = ServerEndpointConfig.Builder.create(Object.class, "/a/b/c").build();
    ServerEndpointConfig configB = ServerEndpointConfig.Builder.create(Object.class, "/a/b/c").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 5 with ServerEndpointConfig

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

the class TestWsServerContainer method testDuplicatePaths03.

@Test(expected = DeploymentException.class)
public void testDuplicatePaths03() 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(jakarta.websocket.server.ServerEndpointConfig) Test(org.junit.Test) WebSocketBaseTest(org.apache.tomcat.websocket.WebSocketBaseTest)

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