Author: markt
Date: Sat Apr  3 12:41:31 2010
New Revision: 930514

URL: http://svn.apache.org/viewvc?rev=930514&view=rev
Log:
TCK failures: If a servlet/filter has any mappings in the main web.xml, these 
override rather than replace the mappings defined in the fragments. The same 
goes for fragments and annotations.

Modified:
    tomcat/trunk/java/org/apache/catalina/deploy/WebXml.java
    tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java

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=930514&r1=930513&r2=930514&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/deploy/WebXml.java (original)
+++ tomcat/trunk/java/org/apache/catalina/deploy/WebXml.java Sat Apr  3 
12:41:31 2010
@@ -272,8 +272,10 @@ public class WebXml {
     
     // filter-mapping
     private Set<FilterMap> filterMaps = new LinkedHashSet<FilterMap>();
+    private Set<String> filterMappingNames = new HashSet<String>();
     public void addFilterMapping(FilterMap filterMap) {
         filterMaps.add(filterMap);
+        filterMappingNames.add(filterMap.getFilterName());
     }
     public Set<FilterMap> getFilterMappings() { return filterMaps; }
     
@@ -301,8 +303,10 @@ public class WebXml {
     
     // servlet-mapping
     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);
+        servletMappingNames.add(servletName);
     }
     public Map<String,String> getServletMappings() { return servletMappings; }
     
@@ -1407,9 +1411,22 @@ public class WebXml {
         }
         errorPages.putAll(temp.getErrorPages());
 
+        // As per 'clarification' from the Servlet EG, filter mappings in the
+        // main web.xml override those in fragments and those in fragments
+        // override mappings in annotations
+        for (WebXml fragment : fragments) {
+            Iterator<FilterMap> iterFilterMaps =
+                fragment.getFilterMappings().iterator();
+            while (iterFilterMaps.hasNext()) {
+                FilterMap filterMap = iterFilterMaps.next();
+                if (filterMappingNames.contains(filterMap.getFilterName())) {
+                    iterFilterMaps.remove();
+                }
+            }
+        }
         for (WebXml fragment : fragments) {
             for (FilterMap filterMap : fragment.getFilterMappings()) {
-                // Always additive
+                // Additive
                 addFilterMapping(filterMap);
             }
         }
@@ -1550,10 +1567,23 @@ 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
+        for (WebXml fragment : fragments) {
+            Iterator<Map.Entry<String,String>> iterServletMaps =
+                fragment.getServletMappings().entrySet().iterator();
+            while (iterServletMaps.hasNext()) {
+                Map.Entry<String,String> servletMap = iterServletMaps.next();
+                if (servletMappingNames.contains(servletMap.getValue())) {
+                    iterServletMaps.remove();
+                }
+            }
+        }
         for (WebXml fragment : fragments) {
             for (Map.Entry<String,String> mapping :
                     fragment.getServletMappings().entrySet()) {
-                // Always additive
+                // Additive
                 addServletMapping(mapping.getKey(), mapping.getValue());
             }
         }

Modified: tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java?rev=930514&r1=930513&r2=930514&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java Sat Apr  3 
12:41:31 2010
@@ -32,6 +32,7 @@ import java.net.URLConnection;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
@@ -1210,7 +1211,7 @@ public class ContextConfig
             // Have to process JARs for fragments
             Map<String,WebXml> fragments = processJarsForWebFragments();
             
-            // Merge the fragments into the main web.xml
+            // Order the fragments
             Set<WebXml> orderedFragments =
                 WebXml.orderWebFragments(webXml, fragments);
 
@@ -1454,8 +1455,13 @@ public class ContextConfig
     protected void processAnnotations(Set<WebXml> fragments) {
         for(WebXml fragment : fragments) {
             if (!fragment.isMetadataComplete()) {
+                WebXml annotations = new WebXml();
                 URL url = fragment.getURL();
-                processAnnotationsUrl(url, fragment);
+                processAnnotationsUrl(url, annotations);
+                Set<WebXml> set = new HashSet<WebXml>();
+                set.add(annotations);
+                // Merge annotations into fragment - fragment takes priority
+                fragment.merge(set);
             }
         }
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to