Fix regression in welcome file processing
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 8 Jun 2011 00:44:14 +0000 (00:44 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 8 Jun 2011 00:44:14 +0000 (00:44 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1133221 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/deploy/WebXml.java
java/org/apache/catalina/startup/ContextConfig.java
webapps/docs/changelog.xml

index 4ddc308..a2ecbb6 100644 (file)
@@ -346,13 +346,25 @@ public class WebXml {
     }
     public Map<String,String> getMimeMappings() { return mimeMappings; }
     
-    // welcome-file-list
-    // When merging web.xml files it may be necessary for any new welcome files
-    // to completely replace the current set
+    // welcome-file-list merge control
     private boolean replaceWelcomeFiles = false;
+    private boolean alwaysAddWelcomeFiles = true;
+    /**
+     * When merging/parsing web.xml files into this web.xml should the current
+     * set be completely replaced?
+     */
     public void setReplaceWelcomeFiles(boolean replaceWelcomeFiles) {
         this.replaceWelcomeFiles = replaceWelcomeFiles;
     }
+    /**
+     * When merging from this web.xml, should the welcome files be added to the
+     * target web.xml even if it already contains welcome file definitions.
+     */
+    public void setAlwaysAddWelcomeFiles(boolean alwaysAddWelcomeFiles) {
+        this.alwaysAddWelcomeFiles = alwaysAddWelcomeFiles;
+    }
+
+    // welcome-file-list
     private Set<String> welcomeFiles = new LinkedHashSet<String>();
     public void addWelcomeFile(String welcomeFile) {
         if (replaceWelcomeFiles) {
@@ -1322,7 +1334,16 @@ public class WebXml {
         // Context doesn't use version directly
         
         for (String welcomeFile : welcomeFiles) {
-            context.addWelcomeFile(welcomeFile);
+            /*
+             * The following will result in a welcome file of "" so don't add
+             * that to the context 
+             * <welcome-file-list>
+             *   <welcome-file/>
+             * </welcome-file-list>
+             */
+            if (welcomeFile != null && welcomeFile.length() > 0) {
+                context.addWelcomeFile(welcomeFile);
+            }
         }
 
         // Do this last as it depends on servlets
@@ -1848,9 +1869,10 @@ public class WebXml {
         taglibs.putAll(temp.getTaglibs());
 
         for (WebXml fragment : fragments) {
-            for (String welcomeFile : fragment.getWelcomeFiles()) {
-                // Always additive
-                addWelcomeFile(welcomeFile);
+            if (fragment.alwaysAddWelcomeFiles || welcomeFiles.size() == 0) {
+                for (String welcomeFile : fragment.getWelcomeFiles()) {
+                    addWelcomeFile(welcomeFile);
+                }
             }
         }
 
index 140329f..adecb5f 100644 (file)
@@ -1199,6 +1199,9 @@ public class ContextConfig
         // distributable when the default fragment is merged with the main
         // web.xml
         webXmlDefaultFragment.setDistributable(true);
+        // When merging, the default welcome files are only used if the app has
+        // not defined any welcomes files.
+        webXmlDefaultFragment.setAlwaysAddWelcomeFiles(false);
 
         // Parse global web.xml if present
         InputSource globalWebXml = getGlobalWebXmlSource();
@@ -1211,7 +1214,7 @@ public class ContextConfig
 
         // Parse host level web.xml if present
         // Additive apart from welcome pages
-        webXml.setReplaceWelcomeFiles(true);
+        webXmlDefaultFragment.setReplaceWelcomeFiles(true);
         InputSource hostWebXml = getHostWebXmlSource();
         parseWebXml(hostWebXml, webXmlDefaultFragment, false);
         
index 485dd54..39db3c8 100644 (file)
         web application from being marked as distributable. (kfujino/mark)
       </fix>
       <fix>
+        Correct a regression in the fix for <bug>51278</bug> that prevented a
+        web application from overriding the default welcome files. (mark)
+      </fix>
+      <fix>
         Enable remaining valves for Servlet 3 asynchronous processing support.
         (markt)
       </fix>