You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2015/02/24 10:11:01 UTC
svn commit: r1661867 - in /tomcat/trunk:
java/org/apache/catalina/core/ApplicationContext.java
test/org/apache/catalina/core/TestApplicationContext.java
Author: markt
Date: Tue Feb 24 09:11:01 2015
New Revision: 1661867
URL: http://svn.apache.org/r1661867
Log:
Relax the restriction added in r1644989. Expand the unit tests.
While the Javadoc for getContext(String) could be clearer, the intended behaviour appears to mapping rather than an exact match because:
- there is no way with an excat match to obtain the ROOT context
- "Returns a ServletContext object that corresponds to a specified URL on the server."
Modified:
tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java
tomcat/trunk/test/org/apache/catalina/core/TestApplicationContext.java
Modified: tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java?rev=1661867&r1=1661866&r2=1661867&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java Tue Feb 24 09:11:01 2015
@@ -248,8 +248,9 @@ public class ApplicationContext
public ServletContext getContext(String uri) {
// Validate the format of the specified argument
- if ((uri == null) || (!uri.startsWith("/")))
- return (null);
+ if (uri == null || !uri.startsWith("/")) {
+ return null;
+ }
Context child = null;
try {
@@ -280,12 +281,7 @@ public class ApplicationContext
MappingData mappingData = new MappingData();
((Engine) host.getParent()).getService().getMapper().map(hostMB, pathMB, null, mappingData);
-
- // Must be an exact match. It is no good returning the ROOT
- // context if the caller is looking for "/something-else"
- if (mappingData.context.getPath().equals(uri)) {
- child = mappingData.context;
- }
+ child = mappingData.context;
}
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
Modified: tomcat/trunk/test/org/apache/catalina/core/TestApplicationContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/core/TestApplicationContext.java?rev=1661867&r1=1661866&r2=1661867&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/core/TestApplicationContext.java (original)
+++ tomcat/trunk/test/org/apache/catalina/core/TestApplicationContext.java Tue Feb 24 09:11:01 2015
@@ -185,6 +185,7 @@ public class TestApplicationContext exte
bar.addLifecycleListener(new SetIdListener("bar"));
Context ctx = tomcat.addContext("", null);
+ ctx.addLifecycleListener(new SetIdListener("ROOT"));
ctx.setCrossContext(true);
Tomcat.addServlet(ctx, "Bug57190Servlet", new Bug57190Servlet());
@@ -200,7 +201,10 @@ public class TestApplicationContext exte
Assert.assertTrue(body, body.contains("03-foo1"));
Assert.assertTrue(body, body.contains("04-foo2"));
Assert.assertTrue(body, body.contains("05-foo2"));
- Assert.assertTrue(body, body.contains("06-null"));
+ Assert.assertTrue(body, body.contains("06-ROOT"));
+ Assert.assertTrue(body, body.contains("07-ROOT"));
+ Assert.assertTrue(body, body.contains("08-foo2"));
+ Assert.assertTrue(body, body.contains("09-ROOT"));
}
@@ -219,7 +223,10 @@ public class TestApplicationContext exte
pw.println("03-" + sc.getContext("/foo##1").getInitParameter("id"));
pw.println("04-" + sc.getContext("/foo##2").getInitParameter("id"));
pw.println("05-" + sc.getContext("/foo##3").getInitParameter("id"));
- pw.println("06-" + sc.getContext("/unknown"));
+ pw.println("06-" + sc.getContext("/unknown").getInitParameter("id"));
+ pw.println("07-" + sc.getContext("/").getInitParameter("id"));
+ pw.println("08-" + sc.getContext("/foo/bar").getInitParameter("id"));
+ pw.println("09-" + sc.getContext("/football").getInitParameter("id"));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org