Author: markt
Date: Thu Jan 10 12:09:13 2013
New Revision: 1431309
URL: http://svn.apache.org/viewvc?rev=1431309&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=54387
Multiple servlets may not be mapped to the same url-pattern
Modified:
tomcat/tc7.0.x/trunk/ (props changed)
tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/LocalStrings.properties
tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/WebXml.java
tomcat/tc7.0.x/trunk/test/org/apache/catalina/deploy/TestWebXml.java
tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
Merged /tomcat/trunk:r1431308
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/LocalStrings.properties
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/LocalStrings.properties?rev=1431309&r1=1431308&r2=1431309&view=diff
==============================================================================
---
tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/LocalStrings.properties
(original)
+++
tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/LocalStrings.properties
Thu Jan 10 12:09:13 2013
@@ -22,6 +22,7 @@ webXml.duplicateMessageDestination=Dupli
webXml.duplicateMessageDestinationRef=Duplicate message-destination-ref name
[{0}]
webXml.duplicateResourceEnvRef=Duplicate resource-env-ref name [{0}]
webXml.duplicateResourceRef=Duplicate resource-ref name [{0}]
+webXml.duplicateServletMapping=The servlets named [{0}] and [{1}] are both
mapped to the url-pattern [{2}] which is not permitted
webXml.duplicateTaglibUri=Duplicate tag library URI [{0}]
webXml.reservedName=A web.xml file was detected using a reserved name [{0}].
The name element will be ignored for this fragment.
webXml.mergeConflictDisplayName=The display name was defined in multiple
fragments with different values including fragment with name [{0}] located at
[{1}]
Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/WebXml.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/WebXml.java?rev=1431309&r1=1431308&r2=1431309&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/WebXml.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/WebXml.java Thu Jan 10
12:09:13 2013
@@ -328,7 +328,14 @@ public class WebXml {
private Map<String,String> servletMappings = new HashMap<String,String>();
private Set<String> servletMappingNames = new HashSet<String>();
public void addServletMapping(String urlPattern, String servletName) {
- servletMappings.put(urlPattern, servletName);
+ String oldServletName = servletMappings.put(urlPattern, servletName);
+ if (oldServletName != null) {
+ // Duplicate mapping. As per clarification from the Servlet EG,
+ // deployment should fail.
+ throw new IllegalArgumentException(sm.getString(
+ "webXml.duplicateServletMapping", oldServletName,
+ servletName, urlPattern));
+ }
servletMappingNames.add(servletName);
}
public Map<String,String> getServletMappings() { return servletMappings; }
Modified: tomcat/tc7.0.x/trunk/test/org/apache/catalina/deploy/TestWebXml.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/catalina/deploy/TestWebXml.java?rev=1431309&r1=1431308&r2=1431309&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/catalina/deploy/TestWebXml.java
(original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/catalina/deploy/TestWebXml.java Thu
Jan 10 12:09:13 2013
@@ -219,4 +219,48 @@ public class TestWebXml {
Assert.assertEquals(0, webxml.getPreDestroyMethods().size());
}
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testBug54387a() {
+ // Multiple servlets may not be mapped to the same url-pattern
+ WebXml webxml = new WebXml();
+ webxml.addServletMapping("/foo", "a");
+ webxml.addServletMapping("/foo", "b");
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testBug54387b() {
+ // Multiple servlets may not be mapped to the same url-pattern
+ WebXml webxml = new WebXml();
+ WebXml f1 = new WebXml();
+ WebXml f2 = new WebXml();
+
+ HashSet<WebXml> fragments = new HashSet<>();
+ fragments.add(f1);
+ fragments.add(f2);
+
+ f1.addServletMapping("/foo", "a");
+ f2.addServletMapping("/foo", "b");
+
+ webxml.merge(fragments);
+ }
+
+ @Test
+ public void testBug54387c() {
+ // Multiple servlets may not be mapped to the same url-pattern but main
+ // web.xml takes priority
+ WebXml webxml = new WebXml();
+ WebXml f1 = new WebXml();
+ WebXml f2 = new WebXml();
+
+ HashSet<WebXml> fragments = new HashSet<>();
+ fragments.add(f1);
+ fragments.add(f2);
+
+ f1.addServletMapping("/foo", "a");
+ f2.addServletMapping("/foo", "b");
+ webxml.addServletMapping("/foo", "main");
+
+ webxml.merge(fragments);
+ }
}
Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1431309&r1=1431308&r2=1431309&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Thu Jan 10 12:09:13 2013
@@ -138,6 +138,10 @@
<code>HttpParser</code> when parsing incorrect HTTP headers. (kkolinko)
</fix>
<fix>
+ <bug>54387</bug>: Deployment must fail when multiple servlets are
mapped
+ to the same url-pattern. (markt)
+ </fix>
+ <fix>
<bug>54391</bug>: Provide a value for the
<code>javax.servlet.context.orderedLibs</code> attribute. (markt)
</fix>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]