From 050afb8d57ee38d2c384a81f821677d76d340fe3 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Fri, 2 Dec 2011 11:09:11 +1100 Subject: [PATCH] 365370 ServletHandler can fall through to nested handler --- .../eclipse/jetty/servlet/ServletHandler.java | 60 ++++++++++++------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java index 1129ed50bec..50912613853 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java @@ -394,22 +394,19 @@ public class ServletHandler extends ScopedHandler try { // Do the filter/handling thang - if (servlet_holder!=null) - { - old_scope=baseRequest.getUserIdentityScope(); - baseRequest.setUserIdentityScope(servlet_holder); + old_scope=baseRequest.getUserIdentityScope(); + baseRequest.setUserIdentityScope(servlet_holder); - // start manual inline of nextScope(target,baseRequest,request,response); - if (never()) - nextScope(target,baseRequest,request,response); - else if (_nextScope!=null) - _nextScope.doScope(target,baseRequest,request, response); - else if (_outerScope!=null) - _outerScope.doHandle(target,baseRequest,request, response); - else - doHandle(target,baseRequest,request, response); - // end manual inline (pathentic attempt to reduce stack depth) - } + // start manual inline of nextScope(target,baseRequest,request,response); + if (never()) + nextScope(target,baseRequest,request,response); + else if (_nextScope!=null) + _nextScope.doScope(target,baseRequest,request, response); + else if (_outerScope!=null) + _outerScope.doHandle(target,baseRequest,request, response); + else + doHandle(target,baseRequest,request, response); + // end manual inline (pathentic attempt to reduce stack depth) } finally { @@ -460,7 +457,10 @@ public class ServletHandler extends ScopedHandler { if (servlet_holder==null) { - notFound(request, response); + if (getHandler()==null) + notFound(request, response); + else + nextHandle(target,baseRequest,request,response); } else { @@ -1230,6 +1230,7 @@ public class ServletHandler extends ScopedHandler HttpServletResponse response) throws IOException { + new Throwable().printStackTrace(); if(LOG.isDebugEnabled()) LOG.debug("Not Found "+request.getRequestURI()); response.sendError(HttpServletResponse.SC_NOT_FOUND); @@ -1318,7 +1319,9 @@ public class ServletHandler extends ScopedHandler /* ------------------------------------------------------------ */ public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException - { + { + final Request baseRequest=(request instanceof Request)?((Request)request):AbstractHttpConnection.getCurrentConnection().getRequest(); + // pass to next filter if (_filterHolder!=null) { @@ -1329,7 +1332,6 @@ public class ServletHandler extends ScopedHandler filter.doFilter(request, response, _next); else { - final Request baseRequest=(request instanceof Request)?((Request)request):AbstractHttpConnection.getCurrentConnection().getRequest(); final boolean suspendable=baseRequest.isAsyncSupported(); if (suspendable) { @@ -1350,15 +1352,20 @@ public class ServletHandler extends ScopedHandler } // Call servlet + + HttpServletRequest srequest = (HttpServletRequest)request; if (_servletHolder != null) { if (LOG.isDebugEnabled()) LOG.debug("call servlet " + _servletHolder); - final Request baseRequest=(request instanceof Request)?((Request)request):AbstractHttpConnection.getCurrentConnection().getRequest(); _servletHolder.handle(baseRequest,request, response); } - else // Not found - notFound((HttpServletRequest)request, (HttpServletResponse)response); + else if (getHandler()==null) + notFound(srequest, (HttpServletResponse)response); + else + nextHandle(URIUtil.addPaths(srequest.getServletPath(),srequest.getPathInfo()), + baseRequest,srequest,(HttpServletResponse)response); + } public String toString() @@ -1424,14 +1431,21 @@ public class ServletHandler extends ScopedHandler } // Call servlet + HttpServletRequest srequest = (HttpServletRequest)request; if (_servletHolder != null) { if (LOG.isDebugEnabled()) LOG.debug("call servlet " + _servletHolder); _servletHolder.handle(_baseRequest,request, response); } - else // Not found - notFound((HttpServletRequest)request, (HttpServletResponse)response); + else if (getHandler()==null) + notFound(srequest, (HttpServletResponse)response); + else + { + Request baseRequest=(request instanceof Request)?((Request)request):AbstractHttpConnection.getCurrentConnection().getRequest(); + nextHandle(URIUtil.addPaths(srequest.getServletPath(),srequest.getPathInfo()), + baseRequest,srequest,(HttpServletResponse)response); + } } /* ------------------------------------------------------------ */