Search in sources :

Example 6 with ServerEndpointConfig

use of javax.websocket.server.ServerEndpointConfig in project jetty.project by eclipse.

the class JsrServerEndpointImpl method create.

@Override
public EventDriver create(Object websocket, WebSocketPolicy policy) throws Throwable {
    if (!(websocket instanceof EndpointInstance)) {
        throw new IllegalStateException(String.format("Websocket %s must be an %s", websocket.getClass().getName(), EndpointInstance.class.getName()));
    }
    EndpointInstance ei = (EndpointInstance) websocket;
    AnnotatedServerEndpointMetadata metadata = (AnnotatedServerEndpointMetadata) ei.getMetadata();
    JsrEvents<ServerEndpoint, ServerEndpointConfig> events = new JsrEvents<>(metadata);
    // Handle @OnMessage maxMessageSizes
    int maxBinaryMessage = getMaxMessageSize(policy.getMaxBinaryMessageSize(), metadata.onBinary, metadata.onBinaryStream);
    int maxTextMessage = getMaxMessageSize(policy.getMaxTextMessageSize(), metadata.onText, metadata.onTextStream);
    policy.setMaxBinaryMessageSize(maxBinaryMessage);
    policy.setMaxTextMessageSize(maxTextMessage);
    JsrAnnotatedEventDriver driver = new JsrAnnotatedEventDriver(policy, ei, events);
    // Handle @PathParam values
    ServerEndpointConfig config = (ServerEndpointConfig) ei.getConfig();
    if (config instanceof PathParamServerEndpointConfig) {
        PathParamServerEndpointConfig ppconfig = (PathParamServerEndpointConfig) config;
        driver.setPathParameters(ppconfig.getPathParamMap());
    }
    return driver;
}
Also used : JsrEvents(org.eclipse.jetty.websocket.jsr356.annotations.JsrEvents) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) EndpointInstance(org.eclipse.jetty.websocket.jsr356.endpoints.EndpointInstance) ServerEndpoint(javax.websocket.server.ServerEndpoint) JsrAnnotatedEventDriver(org.eclipse.jetty.websocket.jsr356.endpoints.JsrAnnotatedEventDriver) ServerEndpoint(javax.websocket.server.ServerEndpoint)

Example 7 with ServerEndpointConfig

use of javax.websocket.server.ServerEndpointConfig in project jetty.project by eclipse.

the class JsrServerExtendsEndpointImpl method create.

@Override
public EventDriver create(Object websocket, WebSocketPolicy policy) {
    if (!(websocket instanceof EndpointInstance)) {
        throw new IllegalStateException(String.format("Websocket %s must be an %s", websocket.getClass().getName(), EndpointInstance.class.getName()));
    }
    EndpointInstance ei = (EndpointInstance) websocket;
    JsrEndpointEventDriver driver = new JsrEndpointEventDriver(policy, ei);
    ServerEndpointConfig config = (ServerEndpointConfig) ei.getConfig();
    if (config instanceof PathParamServerEndpointConfig) {
        PathParamServerEndpointConfig ppconfig = (PathParamServerEndpointConfig) config;
        driver.setPathParameters(ppconfig.getPathParamMap());
    }
    return driver;
}
Also used : JsrEndpointEventDriver(org.eclipse.jetty.websocket.jsr356.endpoints.JsrEndpointEventDriver) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) EndpointInstance(org.eclipse.jetty.websocket.jsr356.endpoints.EndpointInstance)

Example 8 with ServerEndpointConfig

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

the class WsServerContainer method addEndpoint.

/**
     * Provides the equivalent of {@link #addEndpoint(ServerEndpointConfig)}
     * for publishing plain old java objects (POJOs) that have been annotated as
     * WebSocket endpoints.
     *
     * @param pojo   The annotated POJO
     */
@Override
public void addEndpoint(Class<?> pojo) throws DeploymentException {
    ServerEndpoint annotation = pojo.getAnnotation(ServerEndpoint.class);
    if (annotation == null) {
        throw new DeploymentException(sm.getString("serverContainer.missingAnnotation", pojo.getName()));
    }
    String path = annotation.value();
    // Validate encoders
    validateEncoders(annotation.encoders());
    // ServerEndpointConfig
    ServerEndpointConfig sec;
    Class<? extends Configurator> configuratorClazz = annotation.configurator();
    Configurator configurator = null;
    if (!configuratorClazz.equals(Configurator.class)) {
        try {
            configurator = annotation.configurator().newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new DeploymentException(sm.getString("serverContainer.configuratorFail", annotation.configurator().getName(), pojo.getClass().getName()), e);
        }
    }
    sec = ServerEndpointConfig.Builder.create(pojo, path).decoders(Arrays.asList(annotation.decoders())).encoders(Arrays.asList(annotation.encoders())).subprotocols(Arrays.asList(annotation.subprotocols())).configurator(configurator).build();
    addEndpoint(sec);
}
Also used : ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) Configurator(javax.websocket.server.ServerEndpointConfig.Configurator) DeploymentException(javax.websocket.DeploymentException) ServerEndpoint(javax.websocket.server.ServerEndpoint)

Example 9 with ServerEndpointConfig

use of javax.websocket.server.ServerEndpointConfig in project tomcat 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 10 with ServerEndpointConfig

use of javax.websocket.server.ServerEndpointConfig in project tomcat 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)

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