From 45e6cfa790ad978d489f3ea68a493fcd32dc30ba Mon Sep 17 00:00:00 2001 From: Jesse McConnell Date: Wed, 28 Sep 2011 18:02:27 -0500 Subject: [PATCH] [Bug 359309] fix unit test to use HttpServlet*Wrappers and reformat the resourcehandler a bit to debug last two issues --- .../jetty/server/handler/ResourceHandler.java | 20 ++++++++----- .../eclipse/jetty/servlet/DispatcherTest.java | 30 +++++++++++-------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java index 1d3f196c127..8372e64450c 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java @@ -295,15 +295,15 @@ public class ResourceHandler extends AbstractHandler { String servletPath; String pathInfo; - Boolean included =request.getAttribute(Dispatcher.INCLUDE_REQUEST_URI)!=null; - if (included!=null && included.booleanValue()) + Boolean included = request.getAttribute(Dispatcher.INCLUDE_REQUEST_URI) != null; + if (included != null && included.booleanValue()) { - servletPath=(String)request.getAttribute(Dispatcher.INCLUDE_SERVLET_PATH); - pathInfo=(String)request.getAttribute(Dispatcher.INCLUDE_PATH_INFO); - if (servletPath==null) + servletPath = (String)request.getAttribute(Dispatcher.INCLUDE_SERVLET_PATH); + pathInfo = (String)request.getAttribute(Dispatcher.INCLUDE_PATH_INFO); + if (servletPath == null) { - servletPath=request.getServletPath(); - pathInfo=request.getPathInfo(); + servletPath = request.getServletPath(); + pathInfo = request.getPathInfo(); } } else @@ -312,7 +312,7 @@ public class ResourceHandler extends AbstractHandler servletPath = request.getServletPath(); pathInfo = request.getPathInfo(); } - + String pathInContext=URIUtil.addPaths(servletPath,pathInfo); return getResource(pathInContext); } @@ -353,14 +353,18 @@ public class ResourceHandler extends AbstractHandler return; boolean skipContentBody = false; + if(!HttpMethods.GET.equals(request.getMethod())) { if(!HttpMethods.HEAD.equals(request.getMethod())) + { return; + } skipContentBody = true; } Resource resource = getResource(request); + if (resource==null || !resource.exists()) { if (target.endsWith("/jetty-dir.css")) diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DispatcherTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DispatcherTest.java index 967ecc7849c..871bd7da6c6 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DispatcherTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DispatcherTest.java @@ -37,6 +37,8 @@ import javax.servlet.http.HttpServletRequestWrapper; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponseWrapper; +import junit.framework.Assert; + import org.eclipse.jetty.server.Dispatcher; import org.eclipse.jetty.server.LocalConnector; import org.eclipse.jetty.server.Server; @@ -202,14 +204,17 @@ public class DispatcherTest } @Test - @Ignore("currently fails") + @Ignore("failing") public void testIncludeToResourceHandler() throws Exception { _contextHandler.addServlet(DispatchToResourceServlet.class, "/resourceServlet/*"); - String responses = _connector.getResponses("GET /context/resourceServlet/content.txt?type=include HTTP/1.0\n" + "Host: localhost\n\n"); + String responses = _connector.getResponses("GET /context/resourceServlet/content.txt?do=include HTTP/1.0\n" + "Host: localhost\n\n"); // from inside the context.txt file + Assert.assertNotNull(responses); + + System.out.println(responses); assertTrue(responses.contains("content goes here")); } @@ -218,31 +223,30 @@ public class DispatcherTest { _contextHandler.addServlet(DispatchToResourceServlet.class, "/resourceServlet/*"); - String responses = _connector.getResponses("GET /context/resourceServlet/content.txt?type=forward HTTP/1.0\n" + "Host: localhost\n\n"); + String responses = _connector.getResponses("GET /context/resourceServlet/content.txt?do=forward HTTP/1.0\n" + "Host: localhost\n\n"); // from inside the context.txt file assertTrue(responses.contains("content goes here")); } @Test - @Ignore("currently fails") + @Ignore("failing") public void testWrappedIncludeToResourceHandler() throws Exception { _contextHandler.addServlet(DispatchToResourceServlet.class, "/resourceServlet/*"); - String responses = _connector.getResponses("GET /context/resourceServlet/content.txt?type=include&wrapped=true HTTP/1.0\n" + "Host: localhost\n\n"); + String responses = _connector.getResponses("GET /context/resourceServlet/content.txt?do=include&wrapped=true HTTP/1.0\n" + "Host: localhost\n\n"); // from inside the context.txt file assertTrue(responses.contains("content goes here")); } @Test - @Ignore("currently fails") public void testWrappedForwardToResourceHandler() throws Exception { _contextHandler.addServlet(DispatchToResourceServlet.class, "/resourceServlet/*"); - String responses = _connector.getResponses("GET /context/resourceServlet/content.txt?type=forward&wrapped=true HTTP/1.0\n" + "Host: localhost\n\n"); + String responses = _connector.getResponses("GET /context/resourceServlet/content.txt?do=forward&wrapped=true HTTP/1.0\n" + "Host: localhost\n\n"); // from inside the context.txt file assertTrue(responses.contains("content goes here")); @@ -318,13 +322,13 @@ public class DispatcherTest if ( "true".equals(req.getParameter("wrapped"))) { - if (req.getParameter("type").equals("forward")) + if (req.getParameter("do").equals("forward")) { - dispatcher.forward(new ServletRequestWrapper(req),new ServletResponseWrapper(res)); + dispatcher.forward(new HttpServletRequestWrapper(req),new HttpServletResponseWrapper(res)); } - else if (req.getParameter("type").equals("include")) + else if (req.getParameter("do").equals("include")) { - dispatcher.include(new ServletRequestWrapper(req),new ServletResponseWrapper(res)); + dispatcher.include(new HttpServletRequestWrapper(req),new HttpServletResponseWrapper(res)); } else { @@ -333,11 +337,11 @@ public class DispatcherTest } else { - if (req.getParameter("type").equals("forward")) + if (req.getParameter("do").equals("forward")) { dispatcher.forward(req,res); } - else if (req.getParameter("type").equals("include")) + else if (req.getParameter("do").equals("include")) { dispatcher.include(req,res); }