Issue #3167 cleanups from review

Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Greg Wilkins 2019-01-12 10:26:09 +11:00
parent d89e797a1b
commit 392412b2d0
2 changed files with 6 additions and 6 deletions

View File

@ -97,14 +97,14 @@ public class ServletContextHandler extends ContextHandler
public final static int NO_SESSIONS=0; public final static int NO_SESSIONS=0;
public final static int NO_SECURITY=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); ContextHandler contextHandler = ContextHandler.getContextHandler(servletContext);
if (contextHandler == null) if (contextHandler == null)
throw new ServletException("Not running on Jetty, " + purpose+ " unavailable"); throw new IllegalStateException("No Jetty ContextHandler, " + purpose+ " unavailable");
if (!(contextHandler instanceof ServletContextHandler)) 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; return (ServletContextHandler)contextHandler;
} }

View File

@ -29,6 +29,7 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.pathmap.PathSpec; import org.eclipse.jetty.http.pathmap.PathSpec;
import org.eclipse.jetty.server.handler.ContextHandler; 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.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.core.FrameHandler; import org.eclipse.jetty.websocket.core.FrameHandler;
@ -153,10 +154,9 @@ public abstract class WebSocketServlet extends HttpServlet
protected void service(HttpServletRequest req, HttpServletResponse resp) protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException 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 // 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. // can do it here as well if for some reason the filter did not match.
if (mapping.upgrade(req, resp, null)) if (mapping.upgrade(req, resp, null))
return; 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 // TODO a bit fragile. This code knows that only the JettyFHF is added directly as a been
ServletContext servletContext = getServletContext(); ServletContext servletContext = getServletContext();
ContextHandler contextHandler = ContextHandler.getContextHandler(servletContext); ContextHandler contextHandler = ServletContextHandler.getServletContextHandler(servletContext, "WebSocketServlet");
FrameHandlerFactory frameHandlerFactory = contextHandler.getBean(FrameHandlerFactory.class); FrameHandlerFactory frameHandlerFactory = contextHandler.getBean(FrameHandlerFactory.class);
if (frameHandlerFactory==null) if (frameHandlerFactory==null)