Followup to r1138573
authorkkolinko <kkolinko@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 22 Jun 2011 23:39:58 +0000 (23:39 +0000)
committerkkolinko <kkolinko@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 22 Jun 2011 23:39:58 +0000 (23:39 +0000)
Improve support for embedding Tomcat 7.

Expose the string that was used to suppress loading default web.xml as a constant. Short-circuit the attempt to load the web.xml file when this magic value is used. Thus saving us from unneeded getResourceAsStream() call.

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

java/org/apache/catalina/startup/Constants.java
java/org/apache/catalina/startup/ContextConfig.java
java/org/apache/catalina/startup/Tomcat.java
test/org/apache/catalina/core/TestStandardContextResources.java
webapps/docs/changelog.xml

index c9c8041..5a8067f 100644 (file)
@@ -38,6 +38,18 @@ public final class Constants {
     public static final String HostContextXml = "context.xml.default";
     public static final String HostWebXml = "web.xml.default";
 
+    /**
+     * A dummy value used to suppress loading the default web.xml file.
+     *
+     * <p>
+     * It is useful when embedding Tomcat, when the default configuration is
+     * done programmatically, e.g. by calling
+     * <code>Tomcat.initWebappDefaults(context)</code>.
+     *
+     * @see Tomcat
+     */
+    public static final String NoDefaultWebXml = "org/apache/catalina/startup/NO_DEFAULT_XML";
+
     // J2EE
     public static final String J2eeSchemaPublicId_14 =
         "j2ee_1_4.xsd";
index bf83949..4bff0c2 100644 (file)
@@ -1589,6 +1589,10 @@ public class ContextConfig
         // Set the default if we don't have any overrides
         if (defaultWebXml == null) getDefaultWebXml();
 
+        // Is it explicitly suppressed, e.g. in embedded environment?
+        if (Constants.NoDefaultWebXml.equals(defaultWebXml)) {
+            return null;
+        }
         return getWebXmlSource(defaultWebXml, getBaseDir());
     }
     
index f5c6332..7004e3b 100644 (file)
@@ -531,8 +531,8 @@ public class Tomcat {
         ctx.addLifecycleListener(ctxCfg);
         
         // prevent it from looking ( if it finds one - it'll have dup error )
-        ctxCfg.setDefaultWebXml("org/apache/catalin/startup/NO_DEFAULT_XML");
-        
+        ctxCfg.setDefaultWebXml(noDefaultWebXmlPath());
+
         if (host == null) {
             getHost().addChild(ctx);
         } else {
@@ -560,7 +560,7 @@ public class Tomcat {
      * {@link #getDefaultWebXmlListener()}.
      */
     public String noDefaultWebXmlPath() {
-        return "org/apache/catalin/startup/NO_DEFAULT_XML";
+        return Constants.NoDefaultWebXml;
     }
     
     /**
index d0b0fa3..9a22ee5 100644 (file)
@@ -33,6 +33,7 @@ import org.apache.catalina.Lifecycle;
 import org.apache.catalina.LifecycleEvent;
 import org.apache.catalina.LifecycleListener;
 import org.apache.catalina.deploy.WebXml;
+import org.apache.catalina.startup.Constants;
 import org.apache.catalina.startup.ContextConfig;
 import org.apache.catalina.startup.Tomcat;
 import org.apache.catalina.startup.TomcatBaseTest;
@@ -124,7 +125,7 @@ public class TestStandardContextResources extends TomcatBaseTest {
             }
         };
         // prevent it from looking ( if it finds one - it'll have dup error )
-        config.setDefaultWebXml("org/apache/catalin/startup/NO_DEFAULT_XML");
+        config.setDefaultWebXml(Constants.NoDefaultWebXml);
         listener[1] = config;
         Tomcat.addServlet(ctx, "getresource", new GetResourceServlet());
         ctx.addServletMapping("/getresource", "getresource");
@@ -149,7 +150,7 @@ public class TestStandardContextResources extends TomcatBaseTest {
             }
         };
         // prevent it from looking ( if it finds one - it'll have dup error )
-        config1.setDefaultWebXml("org/apache/catalin/startup/NO_DEFAULT_XML");
+        config1.setDefaultWebXml(Constants.NoDefaultWebXml);
         listener1[1] = config1;
         // Need to init since context won't call init
         config1.lifecycleEvent(
index 5ff750f..9b04c3f 100644 (file)
       </fix>
       <add>
         <bug>51418</bug>: Provide more control over Context creation when
-        embedding Tomcat. Based on a patch by Benson Margulies. (markt)
+        embedding Tomcat. Based on a patch by Benson Margulies. (markt/kkolinko)
       </add>
     </changelog>
   </subsection>