Fix #1486
This commit is contained in:
parent
64fc778f30
commit
f5631a9f1b
|
@ -587,7 +587,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
|
|||
else
|
||||
{
|
||||
// Forward to the index
|
||||
RequestDispatcher dispatcher=request.getRequestDispatcher(welcome);
|
||||
RequestDispatcher dispatcher=_servletContext.getRequestDispatcher(welcome);
|
||||
if (dispatcher!=null)
|
||||
{
|
||||
if (included)
|
||||
|
@ -673,7 +673,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
|
|||
String welcome_in_context=URIUtil.addPaths(pathInContext,_welcomes[i]);
|
||||
Resource welcome=getResource(welcome_in_context);
|
||||
if (welcome!=null && welcome.exists())
|
||||
return _welcomes[i];
|
||||
return welcome_in_context;
|
||||
|
||||
if ((_welcomeServlets || _welcomeExactServlets) && welcome_servlet==null)
|
||||
{
|
||||
|
|
|
@ -326,11 +326,13 @@ public class DefaultServletTest
|
|||
testdir.ensureEmpty();
|
||||
File resBase = testdir.getPathFile("docroot").toFile();
|
||||
FS.ensureDirExists(resBase);
|
||||
File inde = new File(resBase, "index.htm");
|
||||
File index = new File(resBase, "index.html");
|
||||
|
||||
File dir = new File(resBase, "dir");
|
||||
assertTrue(dir.mkdirs());
|
||||
File inde = new File(dir, "index.htm");
|
||||
File index = new File(dir, "index.html");
|
||||
|
||||
String resBasePath = resBase.getAbsolutePath();
|
||||
|
||||
ServletHolder defholder = context.addServlet(DefaultServlet.class, "/");
|
||||
defholder.setInitParameter("dirAllowed", "false");
|
||||
defholder.setInitParameter("redirectWelcome", "false");
|
||||
|
@ -344,26 +346,74 @@ public class DefaultServletTest
|
|||
@SuppressWarnings("unused")
|
||||
ServletHolder jspholder = context.addServlet(NoJspServlet.class, "*.jsp");
|
||||
|
||||
String response = connector.getResponses("GET /context/ HTTP/1.0\r\n\r\n");
|
||||
String response = connector.getResponses("GET /context/dir/ HTTP/1.0\r\n\r\n");
|
||||
assertResponseContains("403", response);
|
||||
|
||||
createFile(index, "<h1>Hello Index</h1>");
|
||||
response = connector.getResponses("GET /context/ HTTP/1.0\r\n\r\n");
|
||||
response = connector.getResponses("GET /context/dir/ HTTP/1.0\r\n\r\n");
|
||||
assertResponseContains("<h1>Hello Index</h1>", response);
|
||||
|
||||
createFile(inde, "<h1>Hello Inde</h1>");
|
||||
response = connector.getResponses("GET /context/ HTTP/1.0\r\n\r\n");
|
||||
response = connector.getResponses("GET /context/dir/ HTTP/1.0\r\n\r\n");
|
||||
assertResponseContains("<h1>Hello Index</h1>", response);
|
||||
|
||||
assertTrue(index.delete());
|
||||
response = connector.getResponses("GET /context/ HTTP/1.0\r\n\r\n");
|
||||
response = connector.getResponses("GET /context/dir/ HTTP/1.0\r\n\r\n");
|
||||
assertResponseContains("<h1>Hello Inde</h1>", response);
|
||||
|
||||
assertTrue(inde.delete());
|
||||
response = connector.getResponses("GET /context/ HTTP/1.0\r\n\r\n");
|
||||
response = connector.getResponses("GET /context/dir/ HTTP/1.0\r\n\r\n");
|
||||
assertResponseContains("403", response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWelcomeRedirect() throws Exception
|
||||
{
|
||||
testdir.ensureEmpty();
|
||||
File resBase = testdir.getPathFile("docroot").toFile();
|
||||
FS.ensureDirExists(resBase);
|
||||
|
||||
File dir = new File(resBase, "dir");
|
||||
assertTrue(dir.mkdirs());
|
||||
File inde = new File(dir, "index.htm");
|
||||
File index = new File(dir, "index.html");
|
||||
|
||||
String resBasePath = resBase.getAbsolutePath();
|
||||
ServletHolder defholder = context.addServlet(DefaultServlet.class, "/");
|
||||
defholder.setInitParameter("dirAllowed", "false");
|
||||
defholder.setInitParameter("redirectWelcome", "true");
|
||||
defholder.setInitParameter("welcomeServlets", "false");
|
||||
defholder.setInitParameter("gzip", "false");
|
||||
defholder.setInitParameter("resourceBase", resBasePath);
|
||||
defholder.setInitParameter("maxCacheSize", "1024000");
|
||||
defholder.setInitParameter("maxCachedFileSize", "512000");
|
||||
defholder.setInitParameter("maxCachedFiles", "100");
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
ServletHolder jspholder = context.addServlet(NoJspServlet.class, "*.jsp");
|
||||
|
||||
String response = connector.getResponses("GET /context/dir/ HTTP/1.0\r\n\r\n");
|
||||
assertResponseContains("403", response);
|
||||
|
||||
createFile(index, "<h1>Hello Index</h1>");
|
||||
response = connector.getResponses("GET /context/dir/ HTTP/1.0\r\n\r\n");
|
||||
assertResponseContains("Location: http://0.0.0.0/context/dir/index.html", response);
|
||||
|
||||
createFile(inde, "<h1>Hello Inde</h1>");
|
||||
response = connector.getResponses("GET /context/dir/ HTTP/1.0\r\n\r\n");
|
||||
assertResponseContains("Location: http://0.0.0.0/context/dir/index.html", response);
|
||||
|
||||
assertTrue(index.delete());
|
||||
response = connector.getResponses("GET /context/dir/ HTTP/1.0\r\n\r\n");
|
||||
assertResponseContains("Location: http://0.0.0.0/context/dir/index.htm", response);
|
||||
|
||||
assertTrue(inde.delete());
|
||||
response = connector.getResponses("GET /context/dir/ HTTP/1.0\r\n\r\n");
|
||||
assertResponseContains("403", response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testWelcomeServlet() throws Exception
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue