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 9d35954972c..5b066af38c0 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 @@ -57,6 +57,8 @@ public class WebSocketJsrServer ServletContextHandler.SESSIONS); context.setContextPath("/"); handlers.addHandler(context); + handlers.addHandler(new DefaultHandler()); + server.setHandler(handlers); // Enable javax.websocket configuration for the context ServerContainer wsContainer = JavaxWebSocketServletContainerInitializer @@ -65,9 +67,6 @@ 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/src/main/java/org/eclipse/jetty/websocket/javax/server/JavaxWebSocketServerContainer.java b/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/JavaxWebSocketServerContainer.java index e21c7078335..ebf9e9b6bb9 100644 --- a/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/JavaxWebSocketServerContainer.java +++ b/jetty-websocket/javax-websocket-server/src/main/java/org/eclipse/jetty/websocket/javax/server/JavaxWebSocketServerContainer.java @@ -83,6 +83,8 @@ public class JavaxWebSocketServerContainer public static JavaxWebSocketServerContainer ensureContainer(ServletContext servletContext) throws ServletException { ContextHandler contextHandler = ServletContextHandler.getServletContextHandler(servletContext, "Javax Websocket"); + if (contextHandler.getServer() == null) + throw new IllegalStateException("Server has not been set on the ServletContextHandler"); JavaxWebSocketServerContainer container = contextHandler.getBean(JavaxWebSocketServerContainer.class); if (container==null) @@ -95,8 +97,7 @@ public class JavaxWebSocketServerContainer Executor executor = httpClient == null?null:httpClient.getExecutor(); if (executor == null) - executor = (Executor)servletContext - .getAttribute("org.eclipse.jetty.server.Executor"); + executor = (Executor)servletContext.getAttribute("org.eclipse.jetty.server.Executor"); if (executor == null) executor = contextHandler.getServer().getThreadPool();