Fix TCK failure exposed by the fix for https://issues.apache.org/bugzilla/show_bug...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 3 Jun 2011 18:07:24 +0000 (18:07 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 3 Jun 2011 18:07:24 +0000 (18:07 +0000)
A previous change to ensure web.xml had precedence over fragments and annotations was not complete. It handled filter definitions and servlet definitions but not servlet mappings.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1131126 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/deploy/WebXml.java

index 99ec991..4ddc308 100644 (file)
@@ -1429,9 +1429,9 @@ public class WebXml {
         }
         errorPages.putAll(temp.getErrorPages());
 
-        // As per 'clarification' from the Servlet EG, filter mappings in the
+        // As per 'clarification' from the Servlet EG, filter definitions in the
         // main web.xml override those in fragments and those in fragments
-        // override mappings in annotations
+        // override those in annotations
         for (WebXml fragment : fragments) {
             Iterator<FilterMap> iterFilterMaps =
                 fragment.getFilterMappings().iterator();
@@ -1585,19 +1585,25 @@ public class WebXml {
         serviceRefs.putAll(temp.getServiceRefs());
         mergeInjectionFlags.clear();
 
-        // As per 'clarification' from the Servlet EG, servlet mappings in the
-        // main web.xml override those in fragments and those in fragments
-        // override mappings in annotations
+        // As per 'clarification' from the Servlet EG, servlet definitions and
+        // mappings in the main web.xml override those in fragments and those in
+        // fragments override those in annotations
+        // Remove servlet definitions and mappings from fragments that are
+        // defined in web.xml
         for (WebXml fragment : fragments) {
-            Iterator<Map.Entry<String,String>> iterServletMaps =
+            Iterator<Map.Entry<String,String>> iterFragmentServletMaps =
                 fragment.getServletMappings().entrySet().iterator();
-            while (iterServletMaps.hasNext()) {
-                Map.Entry<String,String> servletMap = iterServletMaps.next();
-                if (servletMappingNames.contains(servletMap.getValue())) {
-                    iterServletMaps.remove();
+            while (iterFragmentServletMaps.hasNext()) {
+                Map.Entry<String,String> servletMap =
+                    iterFragmentServletMaps.next();
+                if (servletMappingNames.contains(servletMap.getValue()) ||
+                        servletMappings.containsKey(servletMap.getKey())) {
+                    iterFragmentServletMaps.remove();
                 }
             }
         }
+        
+        // Add fragment mappings
         for (WebXml fragment : fragments) {
             for (Map.Entry<String,String> mapping :
                     fragment.getServletMappings().entrySet()) {