craigmcc 01/04/09 18:37:08
Modified: catalina/src/share/org/apache/catalina/core
ContainerBase.java LocalStrings.properties
StandardHost.java
catalina/src/share/org/apache/catalina/startup
HostConfig.java
Log:
Fix a "container not started" exception at shutdown time, which was caused
by an attempt to stop the Contexts associated with a particular Host twice
-- once because of the undeploy processing in HostConfig.stop(), and once
because of the normal child shutdown processing in ContainerBase.stop().
Changes to org.apache.catalina.startup.HostConfig:
- In undeployApps(), call host.remove() instead of host.stop() so that the
child will be stopped and then removed from the list of children.
- In undeployApps(), correct message resource lookup keys.
Changes to org.apache.catalina.core.StandardHost:
- In remove(), no longer delete the webapp directory, the corresponding
WAR file, or the associated work directory. This was causing webapp
directories originally auto-deployed to be deleted.
Changes to org.apache.catalina.core.ContainerBase:
- In stop(), stop child containers in the order returned by
findChildren().
Revision Changes Path
1.10 +21 -15
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ContainerBase.java
Index: ContainerBase.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ContainerBase.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ContainerBase.java 2001/04/06 19:31:18 1.9
+++ ContainerBase.java 2001/04/10 01:37:08 1.10
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ContainerBase.java,v
1.9 2001/04/06 19:31:18 remm Exp $
- * $Revision: 1.9 $
- * $Date: 2001/04/06 19:31:18 $
+ * $Header:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ContainerBase.java,v
1.10 2001/04/10 01:37:08 craigmcc Exp $
+ * $Revision: 1.10 $
+ * $Date: 2001/04/10 01:37:08 $
*
* ====================================================================
*
@@ -153,7 +153,7 @@
* class comments of the implementation class.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.9 $ $Date: 2001/04/06 19:31:18 $
+ * @version $Revision: 1.10 $ $Date: 2001/04/10 01:37:08 $
*/
public abstract class ContainerBase
@@ -1030,7 +1030,7 @@
// Validate and update our current component state
if (started)
throw new LifecycleException
- (sm.getString("containerBase.alreadyStarted"));
+ (sm.getString("containerBase.alreadyStarted", logName()));
started = true;
// Start our subordinate components, if any
@@ -1084,21 +1084,22 @@
// Validate and update our current component state
if (!started)
throw new LifecycleException
- (sm.getString("containerBase.notStarted"));
+ (sm.getString("containerBase.notStarted", logName()));
// Notify our interested LifecycleListeners
- lifecycle.fireLifecycleEvent(STOP_EVENT, null);
+ lifecycle.fireLifecycleEvent(STOP_EVENT, null);
started = false;
// Stop the Valves in our pipeline (including the basic), if any
- if (pipeline instanceof Lifecycle)
+ if (pipeline instanceof Lifecycle) {
((Lifecycle) pipeline).stop();
+ }
// Stop our child containers, if any
Container children[] = findChildren();
for (int i = 0; i < children.length; i++) {
- if (children[(children.length-1)-i] instanceof Lifecycle)
- ((Lifecycle) children[(children.length-1)-i]).stop();
+ if (children[i] instanceof Lifecycle)
+ ((Lifecycle) children[i]).stop();
}
// Stop our Mappers, if any
@@ -1109,16 +1110,21 @@
}
// Stop our subordinate components, if any
- if ((resources != null) && (resources instanceof Lifecycle))
+ if ((resources != null) && (resources instanceof Lifecycle)) {
((Lifecycle) resources).stop();
- if ((realm != null) && (realm instanceof Lifecycle))
+ }
+ if ((realm != null) && (realm instanceof Lifecycle)) {
((Lifecycle) realm).stop();
- if ((manager != null) && (manager instanceof Lifecycle))
+ }
+ if ((manager != null) && (manager instanceof Lifecycle)) {
((Lifecycle) manager).stop();
- if ((logger != null) && (logger instanceof Lifecycle))
+ }
+ if ((logger != null) && (logger instanceof Lifecycle)) {
((Lifecycle) logger).stop();
- if ((loader != null) && (loader instanceof Lifecycle))
+ }
+ if ((loader != null) && (loader instanceof Lifecycle)) {
((Lifecycle) loader).stop();
+ }
}
1.29 +2 -2
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/LocalStrings.properties
Index: LocalStrings.properties
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/LocalStrings.properties,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- LocalStrings.properties 2001/03/30 23:24:04 1.28
+++ LocalStrings.properties 2001/04/10 01:37:08 1.29
@@ -12,9 +12,9 @@
applicationResponse.badParent=Cannot locate parent Response implementation
applicationResponse.badResponse=Response is not a
javax.servlet.ServletResponseWrapper
containerBase.addDefaultMapper=Exception configuring default mapper of class {0}
-containerBase.alreadyStarted=Container has already been started
+containerBase.alreadyStarted=Container {0} has already been started
containerBase.notConfigured=No basic Valve has been configured
-containerBase.notStarted=Container has not been started
+containerBase.notStarted=Container {0} has not been started
filterChain.filter=Filter execution threw an exception
filterChain.servlet=Servlet execution threw an exception
httpContextMapper.container=This container is not a StandardContext
1.12 +4 -26
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardHost.java
Index: StandardHost.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardHost.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- StandardHost.java 2001/03/31 16:32:10 1.11
+++ StandardHost.java 2001/04/10 01:37:08 1.12
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardHost.java,v
1.11 2001/03/31 16:32:10 glenn Exp $
- * $Revision: 1.11 $
- * $Date: 2001/03/31 16:32:10 $
+ * $Header:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardHost.java,v
1.12 2001/04/10 01:37:08 craigmcc Exp $
+ * $Revision: 1.12 $
+ * $Date: 2001/04/10 01:37:08 $
*
* ====================================================================
*
@@ -100,7 +100,7 @@
* requests directed to a particular web application.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.11 $ $Date: 2001/03/31 16:32:10 $
+ * @version $Revision: 1.12 $ $Date: 2001/04/10 01:37:08 $
*/
public class StandardHost
@@ -696,28 +696,6 @@
throw new IOException(e.toString());
}
- // Remove the context directory
- String docBase = context.getDocBase();
- if (docBase != null) {
- if (debug >= 1)
- log("Removing expanded directory " + docBase);
- remove(new File(docBase));
- }
- // Remove the war file if it exists
- File warFile = new File(docBase + ".war");
- if (warFile.exists()) {
- if (!warFile.delete())
- throw new IOException("Cannot delete war file " +
- warFile.toString());
- }
-
- // Remove the work directory if it exists
- File dir = (File)context.getServletContext().getAttribute(
- Globals.WORK_DIR_ATTR);
- if (debug >= 1)
- log("Removing work directory" + dir.toString());
- if (dir.exists())
- remove(dir);
}
1.6 +426 -426
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/HostConfig.java
Index: HostConfig.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/HostConfig.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- HostConfig.java 2001/03/26 03:23:52 1.5
+++ HostConfig.java 2001/04/10 01:37:08 1.6
@@ -1,426 +1,426 @@
-/*
- * $Header:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/HostConfig.java,v
1.5 2001/03/26 03:23:52 glenn Exp $
- * $Revision: 1.5 $
- * $Date: 2001/03/26 03:23:52 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact [EMAIL PROTECTED]
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- * [Additional notices, if required by prior licensing conditions]
- *
- */
-
-
-package org.apache.catalina.startup;
-
-
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-import org.apache.catalina.Context;
-import org.apache.catalina.Deployer;
-import org.apache.catalina.Host;
-import org.apache.catalina.Lifecycle;
-import org.apache.catalina.LifecycleEvent;
-import org.apache.catalina.LifecycleListener;
-import org.apache.catalina.Logger;
-import org.apache.catalina.util.StringManager;
-
-
-/**
- * Startup event listener for a <b>Host</b> that configures the properties
- * of that Host, and the associated defined contexts.
- *
- * @author Craig R. McClanahan
- * @version $Revision: 1.5 $ $Date: 2001/03/26 03:23:52 $
- */
-
-public final class HostConfig
- implements LifecycleListener {
-
-
- // ----------------------------------------------------- Instance Variables
-
-
- /**
- * The Java class name of the Context configuration class we should use.
- */
- private String configClass = "org.apache.catalina.startup.ContextConfig";
-
-
- /**
- * The Java class name of the Context implementation we should use.
- */
- private String contextClass = "org.apache.catalina.core.StandardContext";
-
-
- /**
- * The debugging detail level for this component.
- */
- private int debug = 0;
-
-
- /**
- * The Host we are associated with.
- */
- private Host host = null;
-
-
- /**
- * The string resources for this package.
- */
- private static final StringManager sm =
- StringManager.getManager(Constants.Package);
-
-
- // ------------------------------------------------------------- Properties
-
-
- /**
- * Return the Context configuration class name.
- */
- public String getConfigClass() {
-
- return (this.configClass);
-
- }
-
-
- /**
- * Set the Context configuration class name.
- *
- * @param configClass The new Context configuration class name.
- */
- public void setConfigClass(String configClass) {
-
- this.configClass = configClass;
-
- }
-
-
- /**
- * Return the Context implementation class name.
- */
- public String getContextClass() {
-
- return (this.contextClass);
-
- }
-
-
- /**
- * Set the Context implementation class name.
- *
- * @param contextClass The new Context implementation class name.
- */
- public void setContextClass(String contextClass) {
-
- this.contextClass = contextClass;
-
- }
-
-
- /**
- * Return the debugging detail level for this component.
- */
- public int getDebug() {
-
- return (this.debug);
-
- }
-
-
- /**
- * Set the debugging detail level for this component.
- *
- * @param debug The new debugging detail level
- */
- public void setDebug(int debug) {
-
- this.debug = debug;
-
- }
-
-
- // --------------------------------------------------------- Public Methods
-
-
- /**
- * Process the START event for an associated Host.
- *
- * @param event The lifecycle event that has occurred
- */
- public void lifecycleEvent(LifecycleEvent event) {
-
- // Identify the host we are associated with
- try {
- host = (Host) event.getLifecycle();
- } catch (ClassCastException e) {
- log(sm.getString("hostConfig.cce", event.getLifecycle()), e);
- return;
- }
-
- // Process the event that has occurred
- if (event.getType().equals(Lifecycle.START_EVENT))
- start();
- else if (event.getType().equals(Lifecycle.STOP_EVENT))
- stop();
-
- }
-
-
- // -------------------------------------------------------- Private Methods
-
-
- /**
- * Return a File object representing the "application root" directory
- * for our associated Host.
- */
- private File appBase() {
-
- File file = new File(host.getAppBase());
- if (!file.isAbsolute())
- file = new File(System.getProperty("catalina.home"),
- host.getAppBase());
- return (file);
-
- }
-
-
- /**
- * Deploy applications for any directories or WAR files that are found
- * in our "application root" directory.
- */
- private void deployApps() {
-
- if (!(host instanceof Deployer))
- return;
- if (debug >= 1)
- log(sm.getString("hostConfig.deploying"));
-
- File appBase = appBase();
- if (!appBase.exists() || !appBase.isDirectory())
- return;
- String files[] = appBase.list();
-
- for (int i = 0; i < files.length; i++) {
-
- if (files[i].equalsIgnoreCase("META-INF"))
- continue;
- if (files[i].equalsIgnoreCase("WEB-INF"))
- continue;
- File dir = new File(appBase, files[i]);
- if (dir.isDirectory()) {
-
- // Make sure there is an application configuration directory
- File webInf = new File(dir, "/WEB-INF");
- if (!webInf.exists() || !webInf.isDirectory() ||
- !webInf.canRead())
- continue;
-
- // Calculate the context path and make sure it is unique
- String contextPath = "/" + files[i];
- if (files[i].equals("ROOT"))
- contextPath = "";
- if (host.findChild(contextPath) != null)
- continue;
-
- // Deploy the application in this directory
- if (debug >= 1)
- log(sm.getString("hostConfig.deployDir", files[i]));
- try {
- URL url = new URL("file", null, dir.getCanonicalPath());
- ((Deployer) host).install(contextPath, url);
- } catch (Throwable t) {
- log(sm.getString("hostConfig.deployDir.error", files[i]),
- t);
- }
-
- } else if (files[i].toLowerCase().endsWith(".war")) {
-
- // Calculate the context path and make sure it is unique
- String contextPath = "/" + files[i];
- int period = contextPath.lastIndexOf(".");
- if (period >= 0)
- contextPath = contextPath.substring(0, period);
- if (contextPath.equals("/ROOT"))
- contextPath = "";
- if (host.findChild(contextPath) != null)
- continue;
-
- // Deploy the application in this WAR file
- if (debug >= 1)
- log(sm.getString("hostConfig.deployJar", files[i]));
- try {
- URL url = new URL("file", null, dir.getCanonicalPath());
- url = new URL("jar:" + url.toString() + "!/");
- ((Deployer) host).install(contextPath, url);
- } catch (Throwable t) {
- log(sm.getString("hostConfig.deployJar.error", files[i]),
- t);
- }
-
- }
-
- }
-
- }
-
-
-
- /**
- * Log a message on the Logger associated with our Host (if any)
- *
- * @param message Message to be logged
- */
- private void log(String message) {
-
- Logger logger = null;
- if (host != null)
- logger = host.getLogger();
- if (logger != null)
- logger.log("HostConfig[" + host.getName() + "]: " + message);
- else
- System.out.println("HostConfig[" + host.getName() + "]: "
- + message);
-
- }
-
-
- /**
- * Log a message on the Logger associated with our Host (if any)
- *
- * @param message Message to be logged
- * @param throwable Associated exception
- */
- private void log(String message, Throwable throwable) {
-
- Logger logger = null;
- if (host != null)
- logger = host.getLogger();
- if (logger != null)
- logger.log("HostConfig[" + host.getName() + "] "
- + message, throwable);
- else {
- System.out.println("HostConfig[" + host.getName() + "]: "
- + message);
- System.out.println("" + throwable);
- throwable.printStackTrace(System.out);
- }
-
- }
-
-
- /**
- * Process a "start" event for this Host.
- */
- private void start() {
-
- if (debug >= 1)
- log(sm.getString("hostConfig.start"));
-
- deployApps();
-
- }
-
-
- /**
- * Process a "stop" event for this Host.
- */
- private void stop() {
-
- if (debug >= 1)
- log(sm.getString("hostConfig.stop"));
-
- undeployApps();
-
- }
-
-
- /**
- * Undeploy all deployed applications.
- */
- private void undeployApps() {
-
- if (!(host instanceof Deployer))
- return;
- if (debug >= 1)
- log(sm.getString("hostConfig.stopping"));
-
- String contextPaths[] = ((Deployer) host).findDeployedApps();
- for (int i = 0; i < contextPaths.length; i++) {
- if (debug >= 1)
- log(sm.getString("hostConfig.stop", contextPaths[i]));
- try {
- ((Deployer) host).stop(contextPaths[i]);
- } catch (Throwable t) {
- log(sm.getString("hostConfig.stop.error",
- contextPaths[i]), t);
- }
- }
-
- }
-
-
-}
+/*
+ * $Header:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/HostConfig.java,v
1.6 2001/04/10 01:37:08 craigmcc Exp $
+ * $Revision: 1.6 $
+ * $Date: 2001/04/10 01:37:08 $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact [EMAIL PROTECTED]
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * [Additional notices, if required by prior licensing conditions]
+ *
+ */
+
+
+package org.apache.catalina.startup;
+
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import org.apache.catalina.Context;
+import org.apache.catalina.Deployer;
+import org.apache.catalina.Host;
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.LifecycleEvent;
+import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.Logger;
+import org.apache.catalina.util.StringManager;
+
+
+/**
+ * Startup event listener for a <b>Host</b> that configures the properties
+ * of that Host, and the associated defined contexts.
+ *
+ * @author Craig R. McClanahan
+ * @version $Revision: 1.6 $ $Date: 2001/04/10 01:37:08 $
+ */
+
+public final class HostConfig
+ implements LifecycleListener {
+
+
+ // ----------------------------------------------------- Instance Variables
+
+
+ /**
+ * The Java class name of the Context configuration class we should use.
+ */
+ private String configClass = "org.apache.catalina.startup.ContextConfig";
+
+
+ /**
+ * The Java class name of the Context implementation we should use.
+ */
+ private String contextClass = "org.apache.catalina.core.StandardContext";
+
+
+ /**
+ * The debugging detail level for this component.
+ */
+ private int debug = 0;
+
+
+ /**
+ * The Host we are associated with.
+ */
+ private Host host = null;
+
+
+ /**
+ * The string resources for this package.
+ */
+ private static final StringManager sm =
+ StringManager.getManager(Constants.Package);
+
+
+ // ------------------------------------------------------------- Properties
+
+
+ /**
+ * Return the Context configuration class name.
+ */
+ public String getConfigClass() {
+
+ return (this.configClass);
+
+ }
+
+
+ /**
+ * Set the Context configuration class name.
+ *
+ * @param configClass The new Context configuration class name.
+ */
+ public void setConfigClass(String configClass) {
+
+ this.configClass = configClass;
+
+ }
+
+
+ /**
+ * Return the Context implementation class name.
+ */
+ public String getContextClass() {
+
+ return (this.contextClass);
+
+ }
+
+
+ /**
+ * Set the Context implementation class name.
+ *
+ * @param contextClass The new Context implementation class name.
+ */
+ public void setContextClass(String contextClass) {
+
+ this.contextClass = contextClass;
+
+ }
+
+
+ /**
+ * Return the debugging detail level for this component.
+ */
+ public int getDebug() {
+
+ return (this.debug);
+
+ }
+
+
+ /**
+ * Set the debugging detail level for this component.
+ *
+ * @param debug The new debugging detail level
+ */
+ public void setDebug(int debug) {
+
+ this.debug = debug;
+
+ }
+
+
+ // --------------------------------------------------------- Public Methods
+
+
+ /**
+ * Process the START event for an associated Host.
+ *
+ * @param event The lifecycle event that has occurred
+ */
+ public void lifecycleEvent(LifecycleEvent event) {
+
+ // Identify the host we are associated with
+ try {
+ host = (Host) event.getLifecycle();
+ } catch (ClassCastException e) {
+ log(sm.getString("hostConfig.cce", event.getLifecycle()), e);
+ return;
+ }
+
+ // Process the event that has occurred
+ if (event.getType().equals(Lifecycle.START_EVENT))
+ start();
+ else if (event.getType().equals(Lifecycle.STOP_EVENT))
+ stop();
+
+ }
+
+
+ // -------------------------------------------------------- Private Methods
+
+
+ /**
+ * Return a File object representing the "application root" directory
+ * for our associated Host.
+ */
+ private File appBase() {
+
+ File file = new File(host.getAppBase());
+ if (!file.isAbsolute())
+ file = new File(System.getProperty("catalina.home"),
+ host.getAppBase());
+ return (file);
+
+ }
+
+
+ /**
+ * Deploy applications for any directories or WAR files that are found
+ * in our "application root" directory.
+ */
+ private void deployApps() {
+
+ if (!(host instanceof Deployer))
+ return;
+ if (debug >= 1)
+ log(sm.getString("hostConfig.deploying"));
+
+ File appBase = appBase();
+ if (!appBase.exists() || !appBase.isDirectory())
+ return;
+ String files[] = appBase.list();
+
+ for (int i = 0; i < files.length; i++) {
+
+ if (files[i].equalsIgnoreCase("META-INF"))
+ continue;
+ if (files[i].equalsIgnoreCase("WEB-INF"))
+ continue;
+ File dir = new File(appBase, files[i]);
+ if (dir.isDirectory()) {
+
+ // Make sure there is an application configuration directory
+ File webInf = new File(dir, "/WEB-INF");
+ if (!webInf.exists() || !webInf.isDirectory() ||
+ !webInf.canRead())
+ continue;
+
+ // Calculate the context path and make sure it is unique
+ String contextPath = "/" + files[i];
+ if (files[i].equals("ROOT"))
+ contextPath = "";
+ if (host.findChild(contextPath) != null)
+ continue;
+
+ // Deploy the application in this directory
+ if (debug >= 1)
+ log(sm.getString("hostConfig.deployDir", files[i]));
+ try {
+ URL url = new URL("file", null, dir.getCanonicalPath());
+ ((Deployer) host).install(contextPath, url);
+ } catch (Throwable t) {
+ log(sm.getString("hostConfig.deployDir.error", files[i]),
+ t);
+ }
+
+ } else if (files[i].toLowerCase().endsWith(".war")) {
+
+ // Calculate the context path and make sure it is unique
+ String contextPath = "/" + files[i];
+ int period = contextPath.lastIndexOf(".");
+ if (period >= 0)
+ contextPath = contextPath.substring(0, period);
+ if (contextPath.equals("/ROOT"))
+ contextPath = "";
+ if (host.findChild(contextPath) != null)
+ continue;
+
+ // Deploy the application in this WAR file
+ if (debug >= 1)
+ log(sm.getString("hostConfig.deployJar", files[i]));
+ try {
+ URL url = new URL("file", null, dir.getCanonicalPath());
+ url = new URL("jar:" + url.toString() + "!/");
+ ((Deployer) host).install(contextPath, url);
+ } catch (Throwable t) {
+ log(sm.getString("hostConfig.deployJar.error", files[i]),
+ t);
+ }
+
+ }
+
+ }
+
+ }
+
+
+
+ /**
+ * Log a message on the Logger associated with our Host (if any)
+ *
+ * @param message Message to be logged
+ */
+ private void log(String message) {
+
+ Logger logger = null;
+ if (host != null)
+ logger = host.getLogger();
+ if (logger != null)
+ logger.log("HostConfig[" + host.getName() + "]: " + message);
+ else
+ System.out.println("HostConfig[" + host.getName() + "]: "
+ + message);
+
+ }
+
+
+ /**
+ * Log a message on the Logger associated with our Host (if any)
+ *
+ * @param message Message to be logged
+ * @param throwable Associated exception
+ */
+ private void log(String message, Throwable throwable) {
+
+ Logger logger = null;
+ if (host != null)
+ logger = host.getLogger();
+ if (logger != null)
+ logger.log("HostConfig[" + host.getName() + "] "
+ + message, throwable);
+ else {
+ System.out.println("HostConfig[" + host.getName() + "]: "
+ + message);
+ System.out.println("" + throwable);
+ throwable.printStackTrace(System.out);
+ }
+
+ }
+
+
+ /**
+ * Process a "start" event for this Host.
+ */
+ private void start() {
+
+ if (debug >= 1)
+ log(sm.getString("hostConfig.start"));
+
+ deployApps();
+
+ }
+
+
+ /**
+ * Process a "stop" event for this Host.
+ */
+ private void stop() {
+
+ if (debug >= 1)
+ log(sm.getString("hostConfig.stop"));
+
+ undeployApps();
+
+ }
+
+
+ /**
+ * Undeploy all deployed applications.
+ */
+ private void undeployApps() {
+
+ if (!(host instanceof Deployer))
+ return;
+ if (debug >= 1)
+ log(sm.getString("hostConfig.undeploying"));
+
+ String contextPaths[] = ((Deployer) host).findDeployedApps();
+ for (int i = 0; i < contextPaths.length; i++) {
+ if (debug >= 1)
+ log(sm.getString("hostConfig.undeploy", contextPaths[i]));
+ try {
+ ((Deployer) host).remove(contextPaths[i]);
+ } catch (Throwable t) {
+ log(sm.getString("hostConfig.undeploy.error",
+ contextPaths[i]), t);
+ }
+ }
+
+ }
+
+
+}