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
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";
// 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());
}
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 {
* {@link #getDefaultWebXmlListener()}.
*/
public String noDefaultWebXmlPath() {
- return "org/apache/catalin/startup/NO_DEFAULT_XML";
+ return Constants.NoDefaultWebXml;
}
/**
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;
}
};
// 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");
}
};
// 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(
</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>