Search in sources :

Example 1 with EmbeddedCdiHandler

use of org.eclipse.jetty.cdi.servlet.EmbeddedCdiHandler 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 2 with EmbeddedCdiHandler

use of org.eclipse.jetty.cdi.servlet.EmbeddedCdiHandler 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)

Aggregations

File (java.io.File)2 URI (java.net.URI)2 ServerContainer (javax.websocket.server.ServerContainer)2 EmbeddedCdiHandler (org.eclipse.jetty.cdi.servlet.EmbeddedCdiHandler)2 Server (org.eclipse.jetty.server.Server)2 ServerConnector (org.eclipse.jetty.server.ServerConnector)2 BeforeClass (org.junit.BeforeClass)2 Matchers.containsString (org.hamcrest.Matchers.containsString)1