Search in sources :

Example 31 with ServerEndpointConfig

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

the class OnPartialTest method toEventDriver.

public EventDriver toEventDriver(Object websocket) throws Throwable {
    WebSocketPolicy policy = WebSocketPolicy.newServerPolicy();
    policy.setInputBufferSize(1024);
    policy.setMaxBinaryMessageBufferSize(1024);
    policy.setMaxTextMessageBufferSize(1024);
    // Create EventDriver
    EventDriverImpl driverImpl = new JsrServerEndpointImpl();
    Class<?> endpoint = websocket.getClass();
    ServerEndpoint anno = endpoint.getAnnotation(ServerEndpoint.class);
    Assert.assertThat("Endpoint: " + endpoint + " should be annotated with @ServerEndpoint", anno, notNullValue());
    WebSocketContainerScope containerScope = new SimpleContainerScope(policy);
    // Event Driver Factory
    EventDriverFactory factory = new EventDriverFactory(containerScope);
    factory.addImplementation(new JsrServerEndpointImpl());
    ServerEndpointConfig config = new BasicServerEndpointConfig(containerScope, endpoint, "/");
    AnnotatedServerEndpointMetadata metadata = new AnnotatedServerEndpointMetadata(containerScope, endpoint, config);
    AnnotatedEndpointScanner<ServerEndpoint, ServerEndpointConfig> scanner = new AnnotatedEndpointScanner<>(metadata);
    scanner.scan();
    EndpointInstance ei = new EndpointInstance(websocket, config, metadata);
    EventDriver driver = driverImpl.create(ei, policy);
    Assert.assertThat("EventDriver", driver, notNullValue());
    // Create Local JsrSession
    String id = testname.getMethodName();
    URI requestURI = URI.create("ws://localhost/" + id);
    DummyConnection connection = new DummyConnection();
    ClientContainer container = new ClientContainer();
    container.start();
    @SuppressWarnings("resource") JsrSession session = new JsrSession(container, id, requestURI, driver, connection);
    session.setPolicy(policy);
    session.start();
    session.open();
    return driver;
}
Also used : WebSocketPolicy(org.eclipse.jetty.websocket.api.WebSocketPolicy) EventDriverFactory(org.eclipse.jetty.websocket.common.events.EventDriverFactory) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) WebSocketContainerScope(org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope) DummyConnection(org.eclipse.jetty.websocket.common.test.DummyConnection) ClientContainer(org.eclipse.jetty.websocket.jsr356.ClientContainer) EndpointInstance(org.eclipse.jetty.websocket.jsr356.endpoints.EndpointInstance) JsrSession(org.eclipse.jetty.websocket.jsr356.JsrSession) ServerEndpoint(javax.websocket.server.ServerEndpoint) URI(java.net.URI) EventDriver(org.eclipse.jetty.websocket.common.events.EventDriver) AnnotatedEndpointScanner(org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointScanner) SimpleContainerScope(org.eclipse.jetty.websocket.common.scopes.SimpleContainerScope) EventDriverImpl(org.eclipse.jetty.websocket.common.events.EventDriverImpl)

Example 32 with ServerEndpointConfig

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

the class ServerAnnotatedEndpointScanner_GoodSignaturesTest method testScan_Basic.

@Test
public void testScan_Basic() throws Exception {
    WebSocketContainerScope container = new SimpleContainerScope(WebSocketPolicy.newClientPolicy());
    AnnotatedServerEndpointMetadata metadata = new AnnotatedServerEndpointMetadata(container, testcase.pojo, null);
    AnnotatedEndpointScanner<ServerEndpoint, ServerEndpointConfig> scanner = new AnnotatedEndpointScanner<>(metadata);
    scanner.scan();
    Assert.assertThat("Metadata", metadata, notNullValue());
    JsrCallable method = (JsrCallable) testcase.metadataField.get(metadata);
    Assert.assertThat(testcase.metadataField.toString(), method, notNullValue());
    int len = testcase.expectedParameters.length;
    for (int i = 0; i < len; i++) {
        Class<?> expectedParam = testcase.expectedParameters[i];
        Class<?> actualParam = method.getParamTypes()[i];
        Assert.assertTrue("Parameter[" + i + "] - expected:[" + expectedParam + "], actual:[" + actualParam + "]", actualParam.equals(expectedParam));
    }
}
Also used : ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) WebSocketContainerScope(org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope) JsrCallable(org.eclipse.jetty.websocket.jsr356.annotations.JsrCallable) AnnotatedEndpointScanner(org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointScanner) SimpleContainerScope(org.eclipse.jetty.websocket.common.scopes.SimpleContainerScope) ServerEndpoint(javax.websocket.server.ServerEndpoint) ServerEndpoint(javax.websocket.server.ServerEndpoint) Test(org.junit.Test)

Example 33 with ServerEndpointConfig

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

the class ExtensionStackProcessingTest method prepare.

@Before
public void prepare() throws Exception {
    server = new Server();
    connector = new ServerConnector(server);
    server.addConnector(connector);
    servletContextHandler = new ServletContextHandler(server, "/", true, false);
    ServerContainer container = WebSocketServerContainerInitializer.configureContext(servletContextHandler);
    ServerEndpointConfig config = ServerEndpointConfig.Builder.create(BasicEchoEndpoint.class, "/").build();
    container.addEndpoint(config);
    client = ContainerProvider.getWebSocketContainer();
    server.addBean(client, true);
    server.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) BasicEchoEndpoint(org.eclipse.jetty.websocket.jsr356.server.samples.echo.BasicEchoEndpoint) Server(org.eclipse.jetty.server.Server) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Before(org.junit.Before)

Example 34 with ServerEndpointConfig

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

the class BinaryStreamTest method prepare.

@Before
public void prepare() throws Exception {
    server = new Server();
    connector = new ServerConnector(server);
    server.addConnector(connector);
    ServletContextHandler context = new ServletContextHandler(server, "/", true, false);
    ServerContainer container = WebSocketServerContainerInitializer.configureContext(context);
    ServerEndpointConfig config = ServerEndpointConfig.Builder.create(ServerBinaryStreamer.class, PATH).build();
    container.addEndpoint(config);
    server.start();
    wsClient = ContainerProvider.getWebSocketContainer();
    server.addBean(wsClient, true);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Before(org.junit.Before)

Example 35 with ServerEndpointConfig

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

the class ServerContainerInitializeListener method createEventbusServerEndpointConfig.

protected ServerEndpointConfig createEventbusServerEndpointConfig(ServletContext servletContext) {
    final List<Class<? extends Encoder>> encoders = new LinkedList<>();
    final List<Class<? extends Decoder>> decoders = new LinkedList<>();
    encoders.add(OutputMessageEncoder.class);
    decoders.add(InputMessageDecoder.class);
    final ServerEndpointConfig endpointConfig = create(CheWSConnection.class, websocketContext + eventBusEndPoint).configurator(createConfigurator()).encoders(encoders).decoders(decoders).build();
    endpointConfig.getUserProperties().put(EVERREST_PROCESSOR_ATTRIBUTE, getEverrestProcessor(servletContext));
    endpointConfig.getUserProperties().put(EVERREST_CONFIG_ATTRIBUTE, getEverrestConfiguration(servletContext));
    endpointConfig.getUserProperties().put(EXECUTOR_ATTRIBUTE, createExecutor(servletContext));
    return endpointConfig;
}
Also used : ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) Encoder(javax.websocket.Encoder) BaseTextEncoder(org.everrest.websockets.message.BaseTextEncoder) Decoder(javax.websocket.Decoder) BaseTextDecoder(org.everrest.websockets.message.BaseTextDecoder) LinkedList(java.util.LinkedList)

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