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 2013/01/10 13:06:51 UTC
svn commit: r1431308 - in /tomcat/trunk:
java/org/apache/catalina/deploy/LocalStrings.properties
java/org/apache/catalina/deploy/WebXml.java
test/org/apache/catalina/deploy/TestWebXml.java
Author: markt
Date: Thu Jan 10 12:06:50 2013
New Revision: 1431308
URL: http://svn.apache.org/viewvc?rev=1431308&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/trunk/java/org/apache/catalina/deploy/LocalStrings.properties
tomcat/trunk/java/org/apache/catalina/deploy/WebXml.java
tomcat/trunk/test/org/apache/catalina/deploy/TestWebXml.java
Modified: tomcat/trunk/java/org/apache/catalina/deploy/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/deploy/LocalStrings.properties?rev=1431308&r1=1431307&r2=1431308&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/deploy/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/deploy/LocalStrings.properties Thu Jan 10 12:06:50 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/trunk/java/org/apache/catalina/deploy/WebXml.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/deploy/WebXml.java?rev=1431308&r1=1431307&r2=1431308&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/deploy/WebXml.java (original)
+++ tomcat/trunk/java/org/apache/catalina/deploy/WebXml.java Thu Jan 10 12:06:50 2013
@@ -327,7 +327,14 @@ public class WebXml {
private final Map<String,String> servletMappings = new HashMap<>();
private final Set<String> servletMappingNames = new HashSet<>();
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/trunk/test/org/apache/catalina/deploy/TestWebXml.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/deploy/TestWebXml.java?rev=1431308&r1=1431307&r2=1431308&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/deploy/TestWebXml.java (original)
+++ tomcat/trunk/test/org/apache/catalina/deploy/TestWebXml.java Thu Jan 10 12:06:50 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);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org