diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java index 3d31408048e..314125d8e89 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java @@ -97,14 +97,14 @@ public class ServletContextHandler extends ContextHandler public final static int NO_SESSIONS=0; public final static int NO_SECURITY=0; - public static ServletContextHandler getServletContextHandler(ServletContext servletContext, String purpose) throws ServletException + public static ServletContextHandler getServletContextHandler(ServletContext servletContext, String purpose) { ContextHandler contextHandler = ContextHandler.getContextHandler(servletContext); if (contextHandler == null) - throw new ServletException("Not running on Jetty, " + purpose+ " unavailable"); + throw new IllegalStateException("No Jetty ContextHandler, " + purpose+ " unavailable"); if (!(contextHandler instanceof ServletContextHandler)) - throw new ServletException("Not running in Jetty ServletContextHandler, " + purpose + " unavailable"); + throw new IllegalStateException("No Jetty ServletContextHandler, " + purpose + " unavailable"); return (ServletContextHandler)contextHandler; } diff --git a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketServlet.java b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketServlet.java index 46f4a510f15..394688689f3 100644 --- a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketServlet.java +++ b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketServlet.java @@ -29,6 +29,7 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.http.pathmap.PathSpec; import org.eclipse.jetty.server.handler.ContextHandler; +import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.core.FrameHandler; @@ -153,10 +154,9 @@ public abstract class WebSocketServlet extends HttpServlet protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - // Typically this servlet is used together with the WebSocketUpgradeFilter, + // Often this servlet is used together with the WebSocketUpgradeFilter, // so upgrade requests will normally be upgraded by the filter. But we // can do it here as well if for some reason the filter did not match. - if (mapping.upgrade(req, resp, null)) return; @@ -256,7 +256,7 @@ public abstract class WebSocketServlet extends HttpServlet { // TODO a bit fragile. This code knows that only the JettyFHF is added directly as a been ServletContext servletContext = getServletContext(); - ContextHandler contextHandler = ContextHandler.getContextHandler(servletContext); + ContextHandler contextHandler = ServletContextHandler.getServletContextHandler(servletContext, "WebSocketServlet"); FrameHandlerFactory frameHandlerFactory = contextHandler.getBean(FrameHandlerFactory.class); if (frameHandlerFactory==null)