[Bug 359309] fix unit test to use HttpServlet*Wrappers and reformat the resourcehandler a bit to debug last two issues
This commit is contained in:
parent
e7af27ad34
commit
45e6cfa790
|
@ -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"))
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue