diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/WebSocketJsrServer.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/WebSocketJsrServer.java index 9c621ff0e29..9ee7a465ca2 100644 --- a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/WebSocketJsrServer.java +++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/WebSocketJsrServer.java @@ -23,6 +23,8 @@ import javax.websocket.Session; import javax.websocket.server.ServerEndpoint; import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.handler.DefaultHandler; +import org.eclipse.jetty.server.handler.HandlerList; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.websocket.jsr356.server.ServerContainer; import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer; @@ -49,10 +51,12 @@ public class WebSocketJsrServer { Server server = new Server(8080); + HandlerList handlers = new HandlerList(); + ServletContextHandler context = new ServletContextHandler( ServletContextHandler.SESSIONS); context.setContextPath("/"); - server.setHandler(context); + handlers.addHandler(context); // Enable javax.websocket configuration for the context ServerContainer wsContainer = WebSocketServerContainerInitializer @@ -61,6 +65,9 @@ public class WebSocketJsrServer // Add your websockets to the container wsContainer.addEndpoint(EchoJsrSocket.class); + handlers.addHandler(new DefaultHandler()); + + server.setHandler(handlers); server.start(); context.dumpStdErr(); server.join(); diff --git a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/WebSocketServerContainerInitializer.java b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/WebSocketServerContainerInitializer.java index 2eee8b7ed44..fabb5b82cbc 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/WebSocketServerContainerInitializer.java +++ b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/WebSocketServerContainerInitializer.java @@ -143,7 +143,7 @@ public class WebSocketServerContainerInitializer implements ServletContainerInit // Build HttpClient HttpClient httpClient = (HttpClient) context.getServletContext().getAttribute(HTTPCLIENT_ATTRIBUTE); - if(httpClient == null) + if ((httpClient == null) && (context.getServer() != null)) { httpClient = (HttpClient) context.getServer().getAttribute(HTTPCLIENT_ATTRIBUTE); } diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/ConfiguratorTest.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/ConfiguratorTest.java index f8ce31c0ce0..bbf0ed9a61a 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/ConfiguratorTest.java +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/ConfiguratorTest.java @@ -58,6 +58,8 @@ import org.eclipse.jetty.http.HttpFields; import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.server.handler.DefaultHandler; +import org.eclipse.jetty.server.handler.HandlerList; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -403,9 +405,11 @@ public class ConfiguratorTest connector.setPort(0); server.addConnector(connector); + HandlerList handlers = new HandlerList(); + ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); - server.setHandler(context); + handlers.addHandler(context); ServerContainer container = WebSocketServerContainerInitializer.configureContext(context); container.addEndpoint(CaptureHeadersSocket.class); @@ -423,6 +427,9 @@ public class ConfiguratorTest .build(); container.addEndpoint(overrideEndpointConfig); + handlers.addHandler(new DefaultHandler()); + + server.setHandler(handlers); server.start(); String host = connector.getHost(); if (host == null)