Search in sources :

Example 6 with WebSocketServletFactory

use of org.eclipse.jetty.websocket.servlet.WebSocketServletFactory in project jetty.project by eclipse.

the class BrowserDebugTool method prepare.

public void prepare(int port) {
    server = new Server();
    connector = new ServerConnector(server);
    connector.setPort(port);
    server.addConnector(connector);
    WebSocketHandler wsHandler = new WebSocketHandler() {

        @Override
        public void configure(WebSocketServletFactory factory) {
            LOG.debug("Configuring WebSocketServerFactory ...");
            // Registering Frame Debug
            factory.getExtensionFactory().register("@frame-capture", FrameCaptureExtension.class);
            // Setup the desired Socket to use for all incoming upgrade requests
            factory.setCreator(BrowserDebugTool.this);
            // Set the timeout
            factory.getPolicy().setIdleTimeout(30000);
            // Set top end message size
            factory.getPolicy().setMaxTextMessageSize(15 * 1024 * 1024);
        }
    };
    server.setHandler(wsHandler);
    String resourceBase = "src/test/resources/browser-debug-tool";
    ResourceHandler rHandler = new ResourceHandler();
    rHandler.setDirectoriesListed(true);
    rHandler.setResourceBase(resourceBase);
    wsHandler.setHandler(rHandler);
    LOG.info("{} setup on port {}", this.getClass().getName(), port);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) WebSocketServletFactory(org.eclipse.jetty.websocket.servlet.WebSocketServletFactory) Server(org.eclipse.jetty.server.Server) WebSocketHandler(org.eclipse.jetty.websocket.server.WebSocketHandler) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler)

Example 7 with WebSocketServletFactory

use of org.eclipse.jetty.websocket.servlet.WebSocketServletFactory in project buck by facebook.

the class StreamingWebSocketServlet method configure.

@Override
public void configure(WebSocketServletFactory factory) {
    // Most implementations of this method simply invoke factory.register(DispatchSocket.class);
    // however, that requires DispatchSocket to have a no-arg constructor. That does not work for
    // us because we would like all WebSockets created by this factory to have a reference to this
    // parent class. This is why we override the default WebSocketCreator for the factory.
    WebSocketCreator wrapperCreator = (req, resp) -> new MyWebSocket();
    factory.setCreator(wrapperCreator);
}
Also used : WebSocketServlet(org.eclipse.jetty.websocket.servlet.WebSocketServlet) Session(org.eclipse.jetty.websocket.api.Session) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WebSocketServletFactory(org.eclipse.jetty.websocket.servlet.WebSocketServletFactory) Set(java.util.Set) IOException(java.io.IOException) BuckEventExternalInterface(com.facebook.buck.event.external.events.BuckEventExternalInterface) Maps(com.google.common.collect.Maps) Collections(java.util.Collections) WebSocketAdapter(org.eclipse.jetty.websocket.api.WebSocketAdapter) WebSocketCreator(org.eclipse.jetty.websocket.servlet.WebSocketCreator) WebSocketCreator(org.eclipse.jetty.websocket.servlet.WebSocketCreator)

Example 8 with WebSocketServletFactory

use of org.eclipse.jetty.websocket.servlet.WebSocketServletFactory in project jetty.project by eclipse.

the class AnnotatedMaxMessageSizeTest method startServer.

@BeforeClass
public static void startServer() throws Exception {
    server = new Server();
    connector = new ServerConnector(server);
    server.addConnector(connector);
    WebSocketHandler wsHandler = new WebSocketHandler() {

        @Override
        public void configure(WebSocketServletFactory factory) {
            factory.register(BigEchoSocket.class);
        }
    };
    server.setHandler(wsHandler);
    server.start();
    String host = connector.getHost();
    if (host == null) {
        host = "localhost";
    }
    int port = connector.getLocalPort();
    serverUri = new URI(String.format("ws://%s:%d/", host, port));
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) WebSocketServletFactory(org.eclipse.jetty.websocket.servlet.WebSocketServletFactory) Server(org.eclipse.jetty.server.Server) URI(java.net.URI) BeforeClass(org.junit.BeforeClass)

Example 9 with WebSocketServletFactory

use of org.eclipse.jetty.websocket.servlet.WebSocketServletFactory in project jetty.project by eclipse.

the class BatchModeTest method prepare.

@Before
public void prepare() throws Exception {
    server = new Server();
    connector = new ServerConnector(server);
    server.addConnector(connector);
    WebSocketHandler handler = new WebSocketHandler() {

        @Override
        public void configure(WebSocketServletFactory factory) {
            factory.register(EchoSocket.class);
        }
    };
    server.setHandler(handler);
    client = new WebSocketClient();
    server.addBean(client, true);
    server.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) WebSocketServletFactory(org.eclipse.jetty.websocket.servlet.WebSocketServletFactory) Server(org.eclipse.jetty.server.Server) WebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient) Before(org.junit.Before)

Example 10 with WebSocketServletFactory

use of org.eclipse.jetty.websocket.servlet.WebSocketServletFactory in project camel by apache.

the class WebsocketEndpointConfigurationTest method testSetServletNoMinThreadsNoMaxThreadsNoThreadPool.

@Test
public void testSetServletNoMinThreadsNoMaxThreadsNoThreadPool() throws Exception {
    port = AvailablePortFinder.getNextAvailable(16331);
    String uri = "websocket://localhost:" + port + "/bar?bufferSize=25000&maxIdleTime=3000";
    WebsocketEndpoint websocketEndpoint = (WebsocketEndpoint) context.getEndpoint(uri);
    WebsocketComponent component = websocketEndpoint.getComponent();
    Consumer consumer = websocketEndpoint.createConsumer(processor);
    component.connect((WebsocketProducerConsumer) consumer);
    assertNotNull(consumer);
    assertEquals(WebsocketConsumer.class, consumer.getClass());
    // just check the servlet initial parameters
    ConnectorRef conector = WebsocketComponent.getConnectors().values().iterator().next();
    ServletContextHandler context = (ServletContextHandler) conector.server.getHandler();
    String buffersize = context.getInitParameter("bufferSize");
    assertEquals("Got a wrong buffersize", "25000", buffersize);
    String maxIdleTime = context.getInitParameter("maxIdleTime");
    assertEquals("Got a wrong maxIdleTime", "3000", maxIdleTime);
    WebSocketServletFactory factory = (WebSocketServletFactory) context.getServletContext().getAttribute(WebSocketServletFactory.class.getName());
    int factoryBufferSize = factory.getPolicy().getInputBufferSize();
    assertEquals("Got a wrong buffersize", 25000, factoryBufferSize);
    long factoryMaxIdleTime = factory.getPolicy().getIdleTimeout();
    assertEquals("Got a wrong maxIdleTime", 3000, factoryMaxIdleTime);
}
Also used : WebSocketServletFactory(org.eclipse.jetty.websocket.servlet.WebSocketServletFactory) Consumer(org.apache.camel.Consumer) ConnectorRef(org.apache.camel.component.websocket.WebsocketComponent.ConnectorRef) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Test(org.junit.Test)

Aggregations

WebSocketServletFactory (org.eclipse.jetty.websocket.servlet.WebSocketServletFactory)11 Server (org.eclipse.jetty.server.Server)4 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)4 WebSocketCreator (org.eclipse.jetty.websocket.servlet.WebSocketCreator)4 Consumer (org.apache.camel.Consumer)3 ConnectorRef (org.apache.camel.component.websocket.WebsocketComponent.ConnectorRef)3 ServerConnector (org.eclipse.jetty.server.ServerConnector)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 WebSocketHandler (org.eclipse.jetty.websocket.server.WebSocketHandler)2 ServletUpgradeRequest (org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest)2 WebSocketServlet (org.eclipse.jetty.websocket.servlet.WebSocketServlet)2 InstrumentedQueuedThreadPool (com.codahale.metrics.jetty9.InstrumentedQueuedThreadPool)1 BuckEventExternalInterface (com.facebook.buck.event.external.events.BuckEventExternalInterface)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Maps (com.google.common.collect.Maps)1 InstrumentedHandler (com.kixeye.chassis.transport.http.InstrumentedHandler)1 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1