Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2013-10-23 00:28:55 +0000
committerGreg Wilkins2013-10-23 00:28:55 +0000
commit353357e816ecb6400bf27cf76dfe04454ea0e285 (patch)
tree92cfaeb236797633bba3b13e3467bafd55ad8e72 /jetty-servlet
parent61dcf9895e645480d5ea3d52513cea84c62a64eb (diff)
parent55b279cc3da989d850aa6f8b63a4a3905dbca6da (diff)
downloadorg.eclipse.jetty.project-353357e816ecb6400bf27cf76dfe04454ea0e285.tar.gz
org.eclipse.jetty.project-353357e816ecb6400bf27cf76dfe04454ea0e285.tar.xz
org.eclipse.jetty.project-353357e816ecb6400bf27cf76dfe04454ea0e285.zip
Merge remote-tracking branch 'origin/master' into jetty-9.1
Diffstat (limited to 'jetty-servlet')
-rw-r--r--jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java6
-rw-r--r--jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletTest.java36
2 files changed, 42 insertions, 0 deletions
diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java
index 8743cd7948..62d0c99dc7 100644
--- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java
+++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java
@@ -354,6 +354,12 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
if (_resourceBase!=null)
{
r = _resourceBase.addPath(pathInContext);
+ if (!_contextHandler.checkAlias(pathInContext,r))
+ r=null;
+ }
+ else if (_servletContext instanceof ContextHandler.Context)
+ {
+ r = _contextHandler.getResource(pathInContext);
}
else
{
diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletTest.java
index 9ccbe9b387..039065add8 100644
--- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletTest.java
+++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletTest.java
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.nio.file.Files;
import java.util.EnumSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -40,6 +41,7 @@ import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.LocalConnector;
import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.toolchain.test.OS;
@@ -416,6 +418,40 @@ public class DefaultServletTest
}
@Test
+ public void testResourceBase() throws Exception
+ {
+ testdir.ensureEmpty();
+ File resBase = testdir.getFile("docroot");
+ FS.ensureDirExists(resBase);
+ File foobar = new File(resBase, "foobar.txt");
+ File link = new File(resBase, "link.txt");
+ createFile(foobar, "Foo Bar");
+
+ String resBasePath = resBase.getAbsolutePath();
+
+ ServletHolder defholder = context.addServlet(DefaultServlet.class, "/");
+ defholder.setInitParameter("resourceBase", resBasePath);
+ defholder.setInitParameter("gzip", "false");
+
+ String response;
+
+ response = connector.getResponses("GET /context/foobar.txt HTTP/1.0\r\n\r\n");
+ assertResponseContains("Foo Bar", response);
+
+ if (!OS.IS_WINDOWS)
+ {
+ Files.createSymbolicLink(link.toPath(),foobar.toPath());
+ response = connector.getResponses("GET /context/link.txt HTTP/1.0\r\n\r\n");
+ assertResponseContains("404", response);
+
+ context.addAliasCheck(new ContextHandler.ApproveAliases());
+
+ response = connector.getResponses("GET /context/link.txt HTTP/1.0\r\n\r\n");
+ assertResponseContains("Foo Bar", response);
+ }
+ }
+
+ @Test
public void testWelcomeExactServlet() throws Exception
{
testdir.ensureEmpty();

Back to the top