You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by cr...@locus.apache.org on 2000/10/05 04:30:24 UTC

cvs commit: jakarta-tomcat-4.0/webapps/manager/WEB-INF web.xml

craigmcc    00/10/04 19:30:24

  Modified:    catalina/src/share/org/apache/catalina/servlets
                        LocalStrings.properties ManagerServlet.java
               webapps  build.xml
  Added:       webapps/manager build.bat build.sh build.xml
               webapps/manager/WEB-INF web.xml
  Log:
  Add a new web application (/manager) that uses the new hot-deploy
  facilities of StandardHost to support deployment, undeployment, and
  on-command reloading of other web applications that are deployed on the
  same virtual host.
  
  NOTE:  The problem alluded to in the previous commit message prevents you
  from deploying, undeploying, and then redeploying a web application from a
  WAR file at exactly the same URL.  However, you can deploy and undeploy a
  directory-based application any number of times without problems.
  
  A document will shortly be added that describes the usage of the manager
  application.
  
  Revision  Changes    Path
  1.2       +3 -0      jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/LocalStrings.properties
  
  Index: LocalStrings.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/LocalStrings.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LocalStrings.properties	2000/08/11 23:39:52	1.1
  +++ LocalStrings.properties	2000/10/05 02:30:22	1.2
  @@ -3,8 +3,11 @@
   defaultservlet.subdirectories=Subdirectories:
   defaultservlet.files=Files:
   managerServlet.alreadyContext=FAIL - Application already exists at path {0}
  +managerServlet.cannotInvoke=Cannot invoke manager servlet through invoker
   managerServlet.deployed=OK - Deployed application at context path {0}
   managerServlet.exception=FAIL - Encountered exception {0}
  +managerServlet.invalidPath=FAIL - Invalid context path {0} was specified
  +managerServlet.invalidWar=FAIL - Invalid application URL {0} was specified
   managerServlet.listed=OK - Listed applications for virtual host {0}
   managerServlet.noCommand=FAIL - No command was specified
   managerServlet.noContext=FAIL - No context exists for path {0}
  
  
  
  1.2       +54 -19    jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/ManagerServlet.java
  
  Index: ManagerServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/ManagerServlet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ManagerServlet.java	2000/08/11 23:39:52	1.1
  +++ ManagerServlet.java	2000/10/05 02:30:22	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/ManagerServlet.java,v 1.1 2000/08/11 23:39:52 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/08/11 23:39:52 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/ManagerServlet.java,v 1.2 2000/10/05 02:30:22 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/10/05 02:30:22 $
    *
    * ====================================================================
    *
  @@ -67,13 +67,15 @@
   
   import java.io.IOException;
   import java.io.PrintWriter;
  +import java.net.URL;
   import javax.servlet.ServletException;
  +import javax.servlet.UnavailableException;
   import javax.servlet.http.HttpServlet;
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
   import org.apache.catalina.Container;
   import org.apache.catalina.Context;
  -import org.apache.catalina.Host;
  +import org.apache.catalina.Deployer;
   import org.apache.catalina.HttpRequest;
   import org.apache.catalina.HttpResponse;
   import org.apache.catalina.Wrapper;
  @@ -109,6 +111,11 @@
    * generally be deployed as a separate web application within the virtual host
    * to be managed.
    * <p>
  + * <b>NOTE</b> - For security reasons, this application will not operate
  + * when accessed via the invoker servlet.  You must explicitly map this servlet
  + * with a servlet mapping, and you will always want to protect it with
  + * appropriate security constraints as well.
  + * <p>
    * The following servlet initialization parameters are recognized:
    * <ul>
    * <li><b>debug</b> - The debugging detail level that controls the amount
  @@ -116,7 +123,7 @@
    * </ul>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/08/11 23:39:52 $
  + * @version $Revision: 1.2 $ $Date: 2000/10/05 02:30:22 $
    */
   
   public final class ManagerServlet
  @@ -139,11 +146,11 @@
   
   
       /**
  -     * The Host container that contains our own web application's Context,
  +     * The Deployer container that contains our own web application's Context,
        * along with the associated Contexts for web applications that we
        * are managing.
        */
  -    private Host host = null;
  +    private Deployer deployer = null;
   
   
       /**
  @@ -218,6 +225,14 @@
        */
       public void init() throws ServletException {
   
  +        // Verify that we were not accessed using the invoker servlet
  +        String servletName = getServletConfig().getServletName();
  +        if (servletName == null)
  +            servletName = "";
  +        if (servletName.startsWith("org.apache.catalina.INVOKER."))
  +            throw new UnavailableException
  +                (sm.getString("managerServlet.cannotInvoke"));
  +
   	// Set our properties from the initialization parameters
   	String value = null;
   	try {
  @@ -230,11 +245,11 @@
   	// Identify the internal container resources we need
   	Wrapper wrapper = (Wrapper) getServletConfig();
   	context = (Context) wrapper.getParent();
  -	host = (Host) context.getParent();
  +	deployer = (Deployer) context.getParent();
   
   	// Log debugging messages as necessary
   	if (debug >= 1) {
  -	    log("init: Associated with Host '" + host.getName() + "'");
  +	    log("init: Associated with Deployer '" + deployer.getName() + "'");
   	}
   
       }
  @@ -258,14 +273,24 @@
   	    log("deploy: Deploying web application at '" + path +
   		"' from '" + war + "'");
   
  +        if ((path == null) || !path.startsWith("/")) {
  +            writer.println(sm.getString("managerServlet.invalidPath", path));
  +            return;
  +        }
  +        if ((war == null) ||
  +            (!war.startsWith("file:") && !war.startsWith("jar:"))) {
  +            writer.println(sm.getString("managerServlet.invalidWar", war));
  +            return;
  +        }
  +
   	try {
  -	  Context context = (Context) host.findChild(path);
  +	  Context context =  deployer.findDeployedApp(path);
   	  if (context != null) {
   	      writer.println(sm.getString("managerServlet.alreadyContext",
   					  path));
   	      return;
   	  }
  -	  ; // FIXME - deploy()
  +          deployer.deploy(path, new URL(war));
   	  writer.println(sm.getString("managerServlet.deployed", path));
   	} catch (Throwable t) {
   	    getServletContext().log("ManagerServlet.deploy[" + path + "]", t);
  @@ -285,14 +310,14 @@
   
           if (debug >= 1)
   	    log("list: Listing contexts for virtual host '" +
  -		host.getName() + "'");
  +		deployer.getName() + "'");
   
  -        writer.println(sm.getString("managerServlet.listed", host.getName()));
  -	Container children[] = host.findChildren();
  -	for (int i = 0; i < children.length; i++)
  -	    writer.println(children[i].getName());
  +        writer.println(sm.getString("managerServlet.listed",
  +                                    deployer.getName()));
  +        String contextPaths[] = deployer.findDeployedApps();
  +        for (int i = 0; i < contextPaths.length; i++)
  +            writer.println(contextPaths[i]);
   
  -
       }
   
   
  @@ -307,8 +332,13 @@
           if (debug >= 1)
   	    log("restart: Reloading web application at '" + path + "'");
   
  +        if ((path == null) || !path.startsWith("/")) {
  +            writer.println(sm.getString("managerServlet.invalidPath", path));
  +            return;
  +        }
  +
           try {
  -	    Context context = (Context) host.findChild(path);
  +	    Context context = deployer.findDeployedApp(path);
   	    if (context == null) {
   	        writer.println(sm.getString("managerServlet.noContext", path));
   		return;
  @@ -335,13 +365,18 @@
           if (debug >= 1)
   	    log("undeploy: Undeploying web application at '" + path + "'");
   
  +        if ((path == null) || !path.startsWith("/")) {
  +            writer.println(sm.getString("managerServlet.invalidPath", path));
  +            return;
  +        }
  +
           try {
  -	    Context context = (Context) host.findChild(path);
  +	    Context context = deployer.findDeployedApp(path);
   	    if (context == null) {
   	        writer.println(sm.getString("managerServlet.noContext", path));
   		return;
   	    }
  -	    host.removeChild(context);
  +            deployer.undeploy(path);
   	    writer.println(sm.getString("managerServlet.undeployed", path));
   	} catch (Throwable t) {
   	    getServletContext().log("ManagerServlet.undeploy[" + path + "]",
  
  
  
  1.7       +5 -1      jakarta-tomcat-4.0/webapps/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/build.xml,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- build.xml	2000/09/27 17:56:51	1.6
  +++ build.xml	2000/10/05 02:30:23	1.7
  @@ -32,6 +32,10 @@
       <ant dir="${basedir}/examples" target="dist"/>
     </target>
   
  +  <target name="manager">
  +    <ant dir="${basedir}/manager" target="dist"/>
  +  </target>
  +
     <target name="webdav">
       <ant dir="${basedir}/webdav" target="dist"/>
     </target>
  @@ -39,7 +43,7 @@
   
     <!-- ================= BUILD: Compile Server Components ================= -->
     <!-- Update the depends list for each subproject -->
  -  <target name="build" depends="build-prepare,ROOT,examples,webdav"/>
  +  <target name="build" depends="build-prepare,ROOT,examples,manager,webdav"/>
   
   
     <!-- ======================= BUILD: Clean Directory ===================== -->
  
  
  
  1.1                  jakarta-tomcat-4.0/webapps/manager/build.bat
  
  Index: build.bat
  ===================================================================
  @echo off
  rem ---------------------------------------------------------------------------
  rem build.bat - Build Script for webapps
  rem
  rem Environment Variable Prerequisites:
  rem
  rem   ANT_HOME         Must point at your Ant installation [../../jakarta-ant]
  rem
  rem   ANT_OPTS         Command line options to the Java runtime
  rem                    that executes Ant [NONE]
  rem
  rem   JAVA_HOME        Must point at your Java Development Kit [REQUIRED]
  rem
  rem   JAXP_HOME        Must point at your JAXP installation 
  rem
  rem   SERVLETAPI_HOME  Must point at your "jakarta-servletapi" installation.
  rem                    [../../jakarta-servletapi]
  rem
  rem $Id: build.bat,v 1.1 2000/10/05 02:30:23 craigmcc Exp $
  rem ---------------------------------------------------------------------------
  
  
  rem ----- Save Environment Variables ------------------------------------------
  
  set _ANT_HOME=%ANT_HOME%
  set _CLASSPATH=%CLASSPATH%
  set _SERVLETAPI_HOME=%SERVLETAPI_HOME%
  
  
  rem ----- Verify and Set Required Environment Variables -----------------------
  
  if not "%JAVA_HOME%" == "" goto gotJavaHome
  echo You must set JAVA_HOME to point at your Java Development Kit installation
  goto cleanup
  :gotJavaHome
  
  if not "%ANT_HOME%" == "" goto gotAntHome
  set ANT_HOME=../../jakarta-ant
  :gotAntHome
  
  if not "%SERVLETAPI_HOME%" == "" goto gotServletapiHome
  set SERVLETAPI_HOME=../../jakarta-servletapi
  :gotServletapiHome
  
  
  rem ----- Set Up The Runtime Classpath ----------------------------------------
  
  if not "%CLASSPATH%" == "" set CLASSPATH=%CLASSPATH%;
  set CLASSPATH=%CLASSPATH%;%ANT_HOME%\lib\ant.jar;%JAVA_HOME%\lib\tools.jar
  
  
  rem ----- Execute The Requested Build -----------------------------------------
  
  java %ANT_OPTS% org.apache.tools.ant.Main -Dant.home=%ANT_HOME% -Djaxp.home="%JAXP_HOME%" -Dservletapi.home=%SERVLETAPI_HOME% %1 %2 %3 %4 %5 %6 %7 %8 %9
  
  
  rem ----- Restore Environment Variables ---------------------------------------
  
  :cleanup
  set SERVLETAPI_HOME=%_SERVLETAPIHOME%
  set _SERVLETAPIHOME=
  set CLASSPATH=%_CLASSPATH%
  set _CLASSPATH=
  set ANT_HOME=%_ANT_HOME%
  set _ANT_HOME=
  :finish
  
  
  
  1.1                  jakarta-tomcat-4.0/webapps/manager/build.sh
  
  Index: build.sh
  ===================================================================
  #!/bin/sh
  # -----------------------------------------------------------------------------
  # build.sh - Build Script for webapps
  #
  # Environment Variable Prerequisites:
  #
  #   ANT_HOME         Must point at your Ant installation [../../jakarta-ant]
  #
  #   ANT_OPTS         Command line options to the Java runtime
  #                    that executes Ant [NONE]
  #
  #   JAVA_HOME        Must point at your Java Development Kit [REQUIRED]
  #
  #   JAXP_HOME        Must point at your JAXP installation
  #
  #   SERVLETAPI_HOME  Must point at your "jakarta-servletapi" installation.
  #                    [../../jakarta-servletapi]
  #
  # $Id: build.sh,v 1.1 2000/10/05 02:30:23 craigmcc Exp $
  # -----------------------------------------------------------------------------
  
  
  # ----- Verify and Set Required Environment Variables -------------------------
  
  if [ "$ANT_HOME" = "" ] ; then
    ANT_HOME=../../jakarta-ant
  fi
  
  if [ "$ANT_OPTS" = "" ] ; then
    ANT_OPTS=""
  fi
  
  if [ "$JAVA_HOME" = "" ] ; then
    echo You must set JAVA_HOME to point at your Java Development Kit install
    exit 1
  fi
  
  if [ "$SERVLETAPI_HOME" = "" ] ; then
    SERVLETAPI_HOME=../../jakarta-servletapi
  fi
  
  
  # ----- Set Up The Runtime Classpath ------------------------------------------
  
  CP=$ANT_HOME/lib/ant.jar:$JAVA_HOME/lib/tools.jar
  if [ "$CLASSPATH" != "" ] ; then
    CP=$CLASSPATH:$CP
  fi
  
  
  # ----- Execute The Requested Build -------------------------------------------
  
  java $ANT_OPTS -classpath $CP org.apache.tools.ant.Main -Dant.home=$ANT_HOME -Djaxp.home=$JAXP_HOME -Dservletapi.home=$SERVLETAPI_HOME "$@"
  
  
  
  
  1.1                  jakarta-tomcat-4.0/webapps/manager/build.xml
  
  Index: build.xml
  ===================================================================
  <project name="manager" default="build-main" basedir=".">
  
  
    <!-- ===================== Initialize Property Values =================== -->
    <property name="ant.home"        value="../../../jakarta-ant"/>
    <property name="build.compiler"  value="classic"/>
    <property name="build.dir"       value="../../../build/webapps"/>
    <property name="dist.dir"        value="../../../dist/webapps"/>
    <property name="servletapi.home" value="../../../jakarta-servletapi"/>
    <property name="webapp.name"    value="manager"/>
  
  
    <!-- ================== Derived Property Values ========================= -->
    <property name="servlet.jar"     value="${servletapi.home}/lib/servlet.jar"/>
  
  
    <!-- =================== BUILD: Create Directories ====================== -->
    <target name="build-prepare">
      <mkdir dir="${build.dir}"/>
      <mkdir dir="${build.dir}/${webapp.name}"/>
    </target>
  
  
    <!-- ================ BUILD: Copy Static Files ========================== -->
    <target name="build-static" depends="build-prepare">
      <copydir src="." dest="${build.dir}/${webapp.name}"
               excludes="build.*"/>
    </target>
  
  
    <!-- ================= BUILD: Compile Server Components ================= -->
    <target name="build-main" depends="build-static">
  
  <!--
      <javac   srcdir="WEB-INF/classes" 
               destdir="${build.dir}/${webapp.name}/WEB-INF/classes"
               classpath="${servlet.jar}"
               deprecation="off" debug="on" optimize="off"
               excludes="**/CVS/**"/>
  -->
  
    </target>
  
  
    <!-- ==================== BUILD: Rebuild Everything ===================== -->
    <target name="all" depends="build-clean,build-main"/>
  
  
    <!-- ======================= BUILD: Clean Directory ===================== -->
    <target name="build-clean">
      <deltree dir="${build.dir}/${webapp.name}"/>
    </target>
  
  
    <!-- ======================= DIST: Create Directories =================== -->
    <target name="dist-prepare">
      <mkdir dir="${dist.dir}"/>
    </target>
  
  
    <!-- ======================= DIST: Create Distribution Files ============ -->
    <target name="dist" depends="build-main,dist-prepare">
        <jar   jarfile="${dist.dir}/${webapp.name}.war"
               basedir="${build.dir}/${webapp.name}" includes="**"/>
    </target>
  
  
    <!-- ======================= DIST: Clean Directory ====================== -->
    <target name="dist-clean">
      <deltree dir="${dist.dir}/${webapp.name}"/>
    </target>
  
  
    <!-- ====================== Convenient Synonyms ========================= -->
    <target name="clean" depends="build-clean,dist-clean"/>
  
  
  </project>
  
  
  
  1.1                  jakarta-tomcat-4.0/webapps/manager/WEB-INF/web.xml
  
  Index: web.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  
  <!DOCTYPE web-app
      PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
      "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
  
  <web-app>
  
    <!-- Define the Manager Servlet -->
    <servlet>
      <servlet-name>Manager</servlet-name>
      <servlet-class>org.apache.catalina.servlets.ManagerServlet</servlet-class>
      <init-param>
        <param-name>debug</param-name>
        <param-value>2</param-value>
      </init-param>
    </servlet>
  
    <!-- Define the Manager Servlet Mapping -->
    <servlet-mapping>
      <servlet-name>Manager</servlet-name>
      <url-pattern>/*</url-pattern>
    </servlet-mapping>
  
    <!-- Define a Security Constraint on this Application -->
    <security-constraint>
      <web-resource-collection>
        <web-resource-name>Entire Application</web-resource-name>
        <url-pattern>/*</url-pattern>
      </web-resource-collection>
      <auth-constraint>
         <!-- NOTE:  This role is not present in the default users file -->
         <role-name>manager</role-name>
      </auth-constraint>
    </security-constraint>
  
    <!-- Define the Login Configuration for this Application -->
    <login-config>
      <auth-method>BASIC</auth-method>
      <realm-name>Tomcat Manager Application</realm-name>
    </login-config>
  
  </web-app>