From 52a16f8e9e8ef7873eca60d4168acc8e4ad040b9 Mon Sep 17 00:00:00 2001
From: markt The Application Base directory for this virtual host.
This is the pathname of a directory that may contain web applications
to be deployed on this virtual host. You may specify an
- absolute pathname for this directory, or a pathname that is relative
- to the appBase directory?
*/
@@ -233,6 +241,28 @@ public class HostConfig
/**
+ * Return the copy XML config file flag for this component.
+ */
+ public boolean isCopyXML() {
+
+ return (this.copyXML);
+
+ }
+
+
+ /**
+ * Set the copy XML config file flag for this component.
+ *
+ * @param copyXML The new copy XML flag
+ */
+ public void setCopyXML(boolean copyXML) {
+
+ this.copyXML= copyXML;
+
+ }
+
+
+ /**
* Return the unpack WARs flag.
*/
public boolean isUnpackWARs() {
@@ -309,6 +339,7 @@ public class HostConfig
try {
host = (Host) event.getLifecycle();
if (host instanceof StandardHost) {
+ setCopyXML(((StandardHost) host).isCopyXML());
setDeployXML(((StandardHost) host).isDeployXML());
setUnpackWARs(((StandardHost) host).isUnpackWARs());
setXmlNamespaceAware(((StandardHost) host).getXmlNamespaceAware());
@@ -612,7 +643,7 @@ public class HostConfig
(LifecycleListener) clazz.newInstance();
context.addLifecycleListener(listener);
- context.setConfigFile(contextXml.getAbsolutePath());
+ context.setConfigFile(contextXml.toURI().toURL());
context.setPath(contextPath);
// Add the associated docBase to the redeployed list if it's a WAR
boolean isExternalWar = false;
@@ -806,11 +837,16 @@ public class HostConfig
BufferedOutputStream ostream = null;
File xml = new File
(configBase(), file.substring(0, file.lastIndexOf(".")) + ".xml");
+ boolean xmlInWar = false;
+
if (deployXML && !xml.exists()) {
try {
jar = new JarFile(war);
entry = jar.getJarEntry(Constants.ApplicationContextXml);
if (entry != null) {
+ xmlInWar = true;
+ }
+ if (copyXML) {
istream = jar.getInputStream(entry);
ostream =
@@ -882,7 +918,52 @@ public class HostConfig
digester.reset();
}
}
- context.setConfigFile(xml.getAbsolutePath());
+ context.setConfigFile(xml.toURI().toURL());
+ } else if (deployXML && xmlInWar) {
+ synchronized (digester) {
+ try {
+ jar = new JarFile(war);
+ entry =
+ jar.getJarEntry(Constants.ApplicationContextXml);
+ istream = jar.getInputStream(entry);
+ context = (Context) digester.parse(istream);
+
+ if (context == null) {
+ log.error(sm.getString(
+ "hostConfig.deployDescriptor.error",
+ file));
+ return;
+ }
+ context.setConfigFile(new URL("jar:" +
+ war.toURI().toString() + "!/" +
+ Constants.ApplicationContextXml));
+ } catch (Exception e) {
+ if (istream != null) {
+ try {
+ istream.close();
+ } catch (Throwable t) {
+ // Ignore
+ }
+ istream = null;
+ }
+ } finally {
+ entry = null;
+ if (jar != null) {
+ try {
+ jar.close();
+ } catch (Throwable t) {
+ // Ignore
+ }
+ jar = null;
+ }
+ digester.reset();
+ }
+ }
+ if (context == null) {
+ log.error(sm.getString("hostConfig.deployDescriptor.error",
+ file));
+ return;
+ }
} else {
context = (Context) Class.forName(contextClass).newInstance();
}
@@ -991,9 +1072,6 @@ public class HostConfig
File xml = new File(dir, Constants.ApplicationContextXml);
File xmlCopy = null;
if (deployXML && xml.exists()) {
- // Will only do this on initial deployment. On subsequent
- // deployments the copied xml file means we'll use
- // deployDescriptor() instead
synchronized (digester) {
try {
context = (Context) digester.parse(xml);
@@ -1007,27 +1085,31 @@ public class HostConfig
digester.reset();
}
}
- xmlCopy = new File(configBase(), file + ".xml");
- InputStream is = null;
- OutputStream os = null;
- try {
- is = new FileInputStream(xml);
- os = new FileOutputStream(xmlCopy);
- IOTools.flow(is, os);
- // Don't catch IOE - let the outer try/catch handle it
- } finally {
+ if (copyXML) {
+ xmlCopy = new File(configBase(), file + ".xml");
+ InputStream is = null;
+ OutputStream os = null;
try {
- if (is != null) is.close();
- } catch (IOException e){
- // Ignore
- }
- try {
- if (os != null) os.close();
- } catch (IOException e){
- // Ignore
+ is = new FileInputStream(xml);
+ os = new FileOutputStream(xmlCopy);
+ IOTools.flow(is, os);
+ // Don't catch IOE - let the outer try/catch handle it
+ } finally {
+ try {
+ if (is != null) is.close();
+ } catch (IOException e){
+ // Ignore
+ }
+ try {
+ if (os != null) os.close();
+ } catch (IOException e){
+ // Ignore
+ }
}
+ context.setConfigFile(xmlCopy.toURI().toURL());
+ } else {
+ context.setConfigFile(xml.toURI().toURL());
}
- context.setConfigFile(xmlCopy.getAbsolutePath());
} else {
context = (Context) Class.forName(contextClass).newInstance();
}
diff --git a/java/org/apache/catalina/startup/LocalStrings.properties b/java/org/apache/catalina/startup/LocalStrings.properties
index 71a6616f1..6f3fe5d47 100644
--- a/java/org/apache/catalina/startup/LocalStrings.properties
+++ b/java/org/apache/catalina/startup/LocalStrings.properties
@@ -25,6 +25,7 @@ contextConfig.authenticatorConfigured=Configured an authenticator for method {0}
contextConfig.authenticatorInstantiate=Cannot instantiate an authenticator of class {0}
contextConfig.authenticatorMissing=Cannot configure an authenticator for method {0}
contextConfig.authenticatorResources=Cannot load authenticators mapping list
+contextConfig.badUrl=Unable to process context descriptor [{0}]
contectConfig.baseError=Unable to determine $CATALINA_BASE
contextConfig.cce=Lifecycle event data object {0} is not a Context
contextConfig.contextClose=Error closing context.xml
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 2f319dd46..efc56e114 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -92,6 +92,11 @@
and stop, and align components that implement Lifecycle with this
definition. (markt)
+ $CATALINA_BASE directory. See
+ absolute pathname, or a pathname that is relative to the
+ $CATALINA_BASE directory. See
Automatic Application
Deployment for more information on automatic recognition and
- deployment of web applications to be deployed automatically. If not
- specified, the default of webapps will be used.webapps will be used.
The XML Base directory for this virtual host.
- This is the pathname of a directory that may contain context XML descriptors
- to be deployed on this virtual host. You may specify an
+ This is the pathname of a directory that may contain context XML
+ descriptors to be deployed on this virtual host. You may specify an
absolute pathname for this directory, or a pathname that is relative
to the $CATALINA_BASE directory. See
Automatic Application
Deployment for more information on automatic recognition and
- deployment of web applications to be deployed automatically.
[engine_name]/[host_name] will be used.
If set to true, Tomcat will attempt to create the directories defined by the
- attributes appBase and xmlBase during the startup phase.
- The default value is true.
- If set to true, and directory creation fails, an error message will be printed out but will not halt
- the startup sequence.
If set to true, Tomcat will attempt to create the directories defined
+ by the attributes appBase and xmlBase during
+ the startup phase. The default value is true. If set to
+ true, and directory creation fails, an error message will be printed out
+ but will not halt the startup sequence.
This flag value indicates if new web applications, dropped in to
- the appBase directory while Tomcat is running, should
- be automatically deployed. The flag's value defaults to true. See
+
This flag value indicates if Tomcat should check periodically for new
+ or updated web applications while Tomcat is running. If true, Tomcat
+ periodically checks the appBase and xmlBase
+ directories and deploys any new web applications or context XML
+ descriptors found. Updated web applications or context XML descriptors
+ will trigger a reload of the web application. The flag's value defaults
+ to true. See
Automatic Application
Deployment for more information.
This flag value indicates if web applications from this host should - be automatically deployed by the host configurator. - The flag's value defaults to true. See + be automatically deployed when Tomcat starts. The flag's value defaults + to true. See Automatic Application Deployment for more information.
Set to true if you want a context XML descriptor
+ embedded inside the application (located at
+ /META-INF/context.xml) to be copied to xmlBase
+ when the application is deployed. On subsequent starts, the copied
+ context XML descriptor will be used in preference to any context XML
+ descriptor embedded inside the application even if the descriptor
+ embedded inside the application is more recent. The flag's value
+ defaults to false. Note if deployXML
+ is false, this attribute will have no effect.
Set to false if you want to disable parsing the context.xml
- file embedded inside the application (located at /META-INF/context.xml).
- Security conscious environments should set this to false to prevent
- applications from interacting with the container's configuration. The
- administrator will then be responsible for providing an external context
- configuration file, and put it in
- $CATALINA_BASE/conf/[enginename]/[hostname]/ unless the attribute xmlBase is specified.
- The flag's value defaults to true.
Set to false if you want to disable parsing the context
+ XML descriptor embedded inside the application (located at
+ /META-INF/context.xml). Security conscious environments
+ should set this to false to prevent applications from
+ interacting with the container's configuration. The administrator will
+ then be responsible for providing an external context configuration
+ file, and putting it in the location defined by the
+ xmlBase attribute. The flag's value defaults to
+ true.
appBase directory as web application
archive (WAR) files to be unpacked into a corresponding disk directory
structure, false to run such web applications directly
- from a WAR file. See
+ from a WAR file. WAR files located outside of the Host's
+ appBase will not be expanded. See
Automatic Application
Deployment for more information.
A host is associated with the
- org.apache.catalina.core.ContainerBase.[enginename].[hostname]
+ org.apache.catalina.core.ContainerBase.[engine_name].[host_name]
log category. Note that the brackets are part of the name,
don't omit them.
deployOnStartup property is set to
true (which is the default value):
$CATALINA_BASE/conf/[engine_name]/[host_name] directory is
- assumed to contain a
+ xmlBase directory (by
+ default $CATALINA_BASE/conf/[engine_name]/[host_name]) is
+ assumed to be a context XML descriptor containing a
Context element (and its associated
- subelements) for a single web application. The docBase
- attribute of this <Context> element will typically
- be the absolute pathname to a web application directory, or the
- absolute pathname of a web application archive (WAR) file (which
- will not be expanded). The path attribute will be automatically set
- as defined in the Context documentation.unpackWARs property
- is set to false. If you redeploy an updated WAR file,
- be sure to delete the expanded directory when restarting Tomcat, so
- that the updated WAR file will be re-expanded (note that the auto
- deployer, if enabled, will automatically expand the updated WAR file
- once the previously expanded directory is removed). Multi-level contexts
- may be defined by using #, e.g. use a WAR named foo#bar.war
- for a context path of /foo/bar.conf/server.xml file. The context path for this
- deployed Context will be a slash character ("/") followed by the
- directory name, unless the directory name is ROOT, in which case
- the context path will be an empty string (""). Multi-level contexts
- may be defined by using #, e.g. use a directory named foo#bar
- for a context path of /foo/bar.docBase attribute of this <Context>
+ element must only be set if the docBase is outside the Host's
+ appBase. For web applications located inside the Host's
+ appBase, the docBase will be the name of the
+ XML file with ".xml" replaced with ".war" for a web application archive
+ or the name of the XML file with ".xml" removed for a directory.path attribute must not be set. The context path used
+ will be a slash character ("/") followed by the name of the XML file
+ (less the .xml extension). Multi-level context paths may be defined
+ using #, e.g. foo#bar.xml for a context path of
+ /foo/bar. The default web application that has a context
+ path of / may be defined by using a file called
+ ROOT.xml.
+ appBase
+ directory that has not already been deployed as a result of a context
+ XML descriptor and does not have a corresponding directory of the same
+ name (without the ".war" extension) will be deployed next. The context
+ path used will be a slash character ("/") followed by the web
+ application archive name less the ".war" extension. The one exception to
+ this rule is that a web application archive named "ROOT.war" will be
+ deployed with a context path of /. Multi-level contexts may
+ be defined by using #, e.g. use a WAR named foo#bar.war for
+ a context path of /foo/bar.unpackWARs attribute is true, the web
+ application archive file will be expanded to a directory of the same
+ name (without the ".war" extension".copyXml is true (it is false
+ by default), any web application archive file within the Hosts's
+ appBase directory that does not have a corresponding
+ context XML descriptor (with a ".xml" extension rather than a ".war"
+ extension) in the Host's xmlBase will be scanned to see
+ if it contains a context XML descriptor (located at
+ /META-INF/context.xml) and if one is found the descriptor
+ will be copied to the xmlBase directory and renamed.
+ appBase that
+ has not already been deployed as a result of a context XML descriptor
+ will be deployed next. The context path used will be a slash character
+ ("/") followed by the directory name, unless the directory name is ROOT,
+ in which case the context path will /. Multi-level contexts
+ may be defined by using #, e.g. use a directory named
+ foo#bar for a context path of /foo/bar.copyXml is true (it is false
+ by default), any directory within the Hosts's appBase
+ directory that does not have a corresponding context XML descriptor in
+ the Host's xmlBase will be scanned to see if it contains
+ a context XML descriptor (located at /META-INF/context.xml)
+ and if one is found the descriptor will be copied to the
+ xmlBase directory and renamed.
+ In addition to the automatic deployment that occurs at startup time,
you can also request that new XML configuration files, WAR files, or
- subdirectories that are dropped in to the appBase (or
- $CATALINA_BASE/conf/[engine_name]/[host_name] in the case of
- an XML configuration file) directory while Tomcat is running will be
- automatically deployed, according to the rules described above. The
- auto deployer will also track web applications for the following changes:
+ sub-directories that are dropped in to the appBase (or
+ xmlBase in the case of an XML configuration file) directory
+ while Tomcat is running will be automatically deployed, according to the
+ rules described above. The auto deployer will also track web applications
+ for the following changes:
Finally, note that if you are defining contexts explicitly, you should - probably turn off automatic application deployment. Otherwise, your context - will be deployed twice each, and that may cause problems for your app. +
Finally, note that if you are defining contexts explicitly in server.xml, + you should probably turn off automatic application deployment. Otherwise, + the web applications will each be deployed twice each, and that may cause + problems for the applications.