417023 Add Default404Servlet if no default servlet set

This commit is contained in:
Greg Wilkins 2013-09-12 10:15:19 +10:00
parent 4b3541b7d1
commit c21ce1183e
2 changed files with 21 additions and 7 deletions

View File

@ -54,12 +54,6 @@ public class WebSocketJsrServer
context.setContextPath("/");
server.setHandler(context);
// Add a servlet to your context.
// It is required that you provide at least 1 servlet.
// Recommended that this servlet mere provide a
// "This is a websocket only server" style response
context.addServlet(new ServletHolder(new DumpServlet()),"/*");
// Enable javax.websocket configuration for the context
ServerContainer wsContainer = WebSocketConfiguration.configureContext(context);

View File

@ -47,6 +47,7 @@ import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.ServletSecurityElement;
import javax.servlet.UnavailableException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -147,7 +148,15 @@ public class ServletHandler extends ScopedHandler
}
updateNameMappings();
updateMappings();
updateMappings();
if (getServletMapping("/")==null)
{
LOG.debug("Adding Default404Servlet to {}",this);
addServletWithMapping(Default404Servlet.class,"/");
updateMappings();
getServletMapping("/").setDefault(true);
}
if(_filterChainsCached)
{
@ -1694,4 +1703,15 @@ public class ServletHandler extends ScopedHandler
_contextHandler.destroyFilter(filter);
}
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
public static class Default404Servlet extends HttpServlet
{
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
resp.sendError(HttpServletResponse.SC_NOT_FOUND);
}
}
}