Search in sources :

Example 16 with ServerEndpointConfig

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

the class TestWsServerContainer method testDuplicatePaths_01.

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

Example 17 with ServerEndpointConfig

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

the class TestWsServerContainer method testDuplicatePaths_02.

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

Example 18 with ServerEndpointConfig

use of javax.websocket.server.ServerEndpointConfig in project AngularBeans by bessemHmidi.

the class SockJsServlet method configuratorFor.

private ServerEndpointConfig.Configurator configuratorFor(final String prefix, final boolean isRaw) {
    return new ServerEndpointConfig.Configurator() {

        @Override
        public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException {
            try {
                return endpointClass.getConstructor(SockJsServer.class, String.class, String.class).newInstance(sockJsServer, getServletContext().getContextPath(), prefix);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
            if (isRaw) {
                // headers with for raw websocket requests
                return;
            }
            String path = request.getRequestURI().getPath();
            Matcher matcher = SESSION_PATTERN.matcher(path);
            if (matcher.matches()) {
                String sessionId = matcher.group(1);
                saveHeaders(sessionId, request.getHeaders());
            }
        }
    };
}
Also used : HandshakeResponse(javax.websocket.HandshakeResponse) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) Matcher(java.util.regex.Matcher) SockJsServer(org.projectodd.sockjs.SockJsServer) SockJsException(org.projectodd.sockjs.SockJsException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) HandshakeRequest(javax.websocket.server.HandshakeRequest)

Example 19 with ServerEndpointConfig

use of javax.websocket.server.ServerEndpointConfig in project AngularBeans by bessemHmidi.

the class AngularBeansServletContextListener method initJSR356.

public void initJSR356() throws ServletException {
    sockJsServer = new SockJsServer();
    sockJsServer.init();
    if (sockJsServer.options.websocket) {
        // Make sure we listen on all possible mappings of the servlet
        // for (String mapping :
        // getServletContext().getServletRegistration(context.getServletName()).getMappings())
        // {
        final String commonPrefix = extractPrefixFromMapping("/rt-service/*");
        // 
        String websocketPath = commonPrefix + "/{server}/{session}/websocket";
        ServerEndpointConfig sockJsConfig = ServerEndpointConfig.Builder.create(SockJsEndpoint.class, websocketPath).configurator(configuratorFor(commonPrefix, false)).build();
        // rt-service/websocket
        String rawWebsocketPath = commonPrefix + "/websocket";
        ServerEndpointConfig rawWsConfig = ServerEndpointConfig.Builder.create(RawWebsocketEndpoint.class, rawWebsocketPath).configurator(configuratorFor(commonPrefix, true)).build();
        ServerContainer serverContainer = (ServerContainer) context.getAttribute("javax.websocket.server.ServerContainer");
        try {
            serverContainer.addEndpoint(sockJsConfig);
            serverContainer.addEndpoint(rawWsConfig);
            Logger.getLogger(this.getClass().getSimpleName()).info("deployement of programmatic Web socket EndPoint :" + rawWebsocketPath);
        } catch (DeploymentException ex) {
            throw new ServletException("Error deploying websocket endpoint:", ex);
        }
    }
}
Also used : ServletException(javax.servlet.ServletException) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) DeploymentException(javax.websocket.DeploymentException) SockJsServer(org.projectodd.sockjs.SockJsServer) ServerContainer(javax.websocket.server.ServerContainer)

Example 20 with ServerEndpointConfig

use of javax.websocket.server.ServerEndpointConfig in project AngularBeans by bessemHmidi.

the class AngularBeansServletContextListener method configuratorFor.

private ServerEndpointConfig.Configurator configuratorFor(final String prefix, final boolean isRaw) {
    return new ServerEndpointConfig.Configurator() {

        @Override
        public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException {
            try {
                return endpointClass.getConstructor(SockJsServer.class, String.class, String.class).newInstance(sockJsServer, context.getContextPath(), prefix);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
            if (isRaw) {
                // headers with for raw websocket requests
                return;
            }
            String path = request.getRequestURI().getPath();
            Matcher matcher = SESSION_PATTERN.matcher(path);
            if (matcher.matches()) {
                String sessionId = matcher.group(1);
                saveHeaders(sessionId, request.getHeaders());
            }
        }
    };
}
Also used : HandshakeResponse(javax.websocket.HandshakeResponse) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) Matcher(java.util.regex.Matcher) SockJsServer(org.projectodd.sockjs.SockJsServer) ServletException(javax.servlet.ServletException) DeploymentException(javax.websocket.DeploymentException) HandshakeRequest(javax.websocket.server.HandshakeRequest)

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