Search in sources :

Example 6 with ServerContainer

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

the class BasicAppTest method startServer.

@BeforeClass
public static void startServer() throws Exception {
    JettyLogHandler.config();
    server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(0);
    server.addConnector(connector);
    EmbeddedCdiHandler context = new EmbeddedCdiHandler();
    File baseDir = MavenTestingUtils.getTestResourcesDir();
    context.setBaseResource(Resource.newResource(baseDir));
    context.setContextPath("/");
    server.setHandler(context);
    // Add some websockets
    ServerContainer container = WebSocketServerContainerInitializer.configureContext(context);
    container.addEndpoint(EchoSocket.class);
    container.addEndpoint(InfoSocket.class);
    server.start();
    String host = connector.getHost();
    if (host == null) {
        host = "localhost";
    }
    int port = connector.getLocalPort();
    serverHttpURI = new URI(String.format("http://%s:%d/", host, port));
    serverWebsocketURI = new URI(String.format("ws://%s:%d/", host, port));
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) EmbeddedCdiHandler(org.eclipse.jetty.cdi.servlet.EmbeddedCdiHandler) Server(org.eclipse.jetty.server.Server) File(java.io.File) URI(java.net.URI) ServerContainer(javax.websocket.server.ServerContainer) BeforeClass(org.junit.BeforeClass)

Example 7 with ServerContainer

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

the class CdiAppTest method startServer.

@BeforeClass
public static void startServer() throws Exception {
    JettyLogHandler.config();
    server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(0);
    server.addConnector(connector);
    EmbeddedCdiHandler context = new EmbeddedCdiHandler();
    WebSocketCdiInitializer.configureContext(context);
    File baseDir = MavenTestingUtils.getTestResourcesDir();
    context.setBaseResource(Resource.newResource(baseDir));
    context.setContextPath("/");
    server.setHandler(context);
    // Add some websockets
    ServerContainer container = WebSocketServerContainerInitializer.configureContext(context);
    container.addEndpoint(EchoSocket.class);
    container.addEndpoint(InfoSocket.class);
    server.start();
    String host = connector.getHost();
    if (host == null) {
        host = "localhost";
    }
    int port = connector.getLocalPort();
    serverWebsocketURI = new URI(String.format("ws://%s:%d/", host, port));
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) EmbeddedCdiHandler(org.eclipse.jetty.cdi.servlet.EmbeddedCdiHandler) Server(org.eclipse.jetty.server.Server) Matchers.containsString(org.hamcrest.Matchers.containsString) File(java.io.File) URI(java.net.URI) ServerContainer(javax.websocket.server.ServerContainer) BeforeClass(org.junit.BeforeClass)

Example 8 with ServerContainer

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

the class BasicEchoSocketConfigContextListener method contextInitialized.

@Override
public void contextInitialized(ServletContextEvent sce) {
    ServerContainer container = (ServerContainer) sce.getServletContext().getAttribute(ServerContainer.class.getName());
    // Build up a configuration with a specific path
    // Intentionally using alternate path in config (which differs from @ServerEndpoint declaration)
    String path = "/echo-alt";
    ServerEndpointConfig.Builder builder = ServerEndpointConfig.Builder.create(BasicEchoSocket.class, path);
    try {
        container.addEndpoint(builder.build());
    } catch (DeploymentException e) {
        throw new RuntimeException("Unable to add endpoint via config file", e);
    }
}
Also used : ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) DeploymentException(javax.websocket.DeploymentException) ServerContainer(javax.websocket.server.ServerContainer)

Example 9 with ServerContainer

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

the class LargeEchoContextListener method contextInitialized.

@Override
public void contextInitialized(ServletContextEvent sce) {
    ServerContainer container = (ServerContainer) sce.getServletContext().getAttribute(ServerContainer.class.getName());
    container.setDefaultMaxTextMessageBufferSize(128 * 1024);
}
Also used : ServerContainer(javax.websocket.server.ServerContainer)

Example 10 with ServerContainer

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

the class IdleTimeoutContextListener method contextInitialized.

@Override
public void contextInitialized(ServletContextEvent sce) {
    ServerContainer container = (ServerContainer) sce.getServletContext().getAttribute(ServerContainer.class.getName());
    // Build up a configuration with a specific path
    String path = "/idle-onopen-endpoint";
    ServerEndpointConfig.Builder builder = ServerEndpointConfig.Builder.create(OnOpenIdleTimeoutEndpoint.class, path);
    try {
        container.addEndpoint(builder.build());
    } catch (DeploymentException e) {
        throw new RuntimeException("Unable to add endpoint via config file", e);
    }
}
Also used : ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) DeploymentException(javax.websocket.DeploymentException) ServerContainer(javax.websocket.server.ServerContainer)

Aggregations

ServerContainer (javax.websocket.server.ServerContainer)16 DeploymentException (javax.websocket.DeploymentException)11 ServerEndpointConfig (javax.websocket.server.ServerEndpointConfig)9 ServletException (javax.servlet.ServletException)4 ServerConnector (org.eclipse.jetty.server.ServerConnector)4 File (java.io.File)3 Server (org.eclipse.jetty.server.Server)3 IOException (java.io.IOException)2 URI (java.net.URI)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 ServletContext (javax.servlet.ServletContext)2 EmbeddedCdiHandler (org.eclipse.jetty.cdi.servlet.EmbeddedCdiHandler)2 BeforeClass (org.junit.BeforeClass)2 BufferedReader (java.io.BufferedReader)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStream (java.io.OutputStream)1 PrintWriter (java.io.PrintWriter)1