tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gl...@apache.org
Subject cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets ManagerServlet.java
Date Mon, 26 Mar 2001 03:23:35 GMT
glenn       01/03/25 19:23:35

  Modified:    catalina/src/share/org/apache/catalina/servlets
                        ManagerServlet.java
  Log:
  Improve webapp unpack WAR file behaviour and enhance manager servlet
  
  Revision  Changes    Path
  1.4       +242 -46   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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ManagerServlet.java	2001/01/03 02:20:46	1.3
  +++ ManagerServlet.java	2001/03/26 03:23:35	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/ManagerServlet.java,v
1.3 2001/01/03 02:20:46 craigmcc Exp $
  - * $Revision: 1.3 $
  - * $Date: 2001/01/03 02:20:46 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/ManagerServlet.java,v
1.4 2001/03/26 03:23:35 glenn Exp $
  + * $Revision: 1.4 $
  + * $Date: 2001/03/26 03:23:35 $
    *
    * ====================================================================
    *
  @@ -78,6 +78,7 @@
   import org.apache.catalina.Deployer;
   import org.apache.catalina.HttpRequest;
   import org.apache.catalina.HttpResponse;
  +import org.apache.catalina.Session;
   import org.apache.catalina.Wrapper;
   import org.apache.catalina.util.StringManager;
   
  @@ -94,19 +95,48 @@
    * The following actions and parameters (starting after the servlet path)
    * are supported:
    * <ul>
  - * <li><b>/list</b> - Return a list of the context paths of all currently
  - *     running web applications in this virtual host.
  - * <li><b>/deploy?path=/xxx&war={war-url}</b> - Deploy a new web
application
  - *     attached to context path <code>/xxx</code>, based on the contents of
  - *     the web application archive found at the specified URL.
  + * <li><b>/install?path=/xxx&war={war-url}</b> - Install and start
a new
  + *     web application attached to context path <code>/xxx</code>, based
  + *     on the contents of the web application archive found at the
  + *     specified URL.</li>
  + * <li><b>/list</b> - List the context paths of all currently installed
web
  + *     applications for this virtual host.  Each context will be listed with
  + *     the following format <code>path:status:sessions</code>.
  + *     Where path is the context path.  Status is either running or stopped.
  + *     Sessions is the number of active Sessions.</li>
    * <li><b>/reload?path=/xxx</b> - Reload the Java classes and resources
for
    *     the application at the specified path, but do not reread the web.xml
  - *     configuration files.
  - * <li><b>/undeploy?path=/xxx</b> - Remove any web application attached
to
  - *     context path <code>/xxx</code> from this virtual host.
  + *     configuration files.</li>
  + * <li><b>/remove?path=/xxx</b> - Shutdown and remove the web application
  + *     attached to context path <code>/xxx</code> for this virtual host.</li>
  + * <li><b>/sessions?path=/xxx</b> - List session information about the
web
  + *     application attached to context path <code>/xxx</code> for this
  + *     virtual host.</li>
  + * <li><b>/start?path=/xxx</b> - Start the web application attached to
  + *     context path <code>/xxx</code> for this virtual host.</li>
  + * <li><b>/stop?path=/xxx</b> - Stop the web application attached to
  + *     context path <code>/xxx</code> for this virtual host.</li>
    * </ul>
  + * <p>Use <code>path=/</code> for the ROOT context.</p>
  + * <p>The syntax of the URL for a web application archive must conform to one
  + * of the following patterns to be successfully deployed:</p>
  + * <ul>
  + * <li><b>file:/absolute/path/to/a/directory</b> - You can specify the
absolute
  + *     path of a directory that contains the unpacked version of a web
  + *     application.  This directory will be attached to the context path you
  + *     specify without any changes.</li>
  + * <li><b>jar:file:/absolute/path/to/a/warfile.war!/</b> - You can specify
a
  + *     URL to a local web application archive file.  The syntax must conform to
  + *     the rules specified by the <code>JarURLConnection</code> class for a
  + *     reference to an entire JAR file.</li>
  + * <li><b>jar:http://hostname:port/path/to/a/warfile.war!/</b> - You
can specify
  + *     a URL to a remote (HTTP-accessible) web application archive file.  The
  + *     syntax must conform to the rules specified by the
  + *     <code>JarURLConnection</code> class for a reference to an entire
  + *     JAR file.</li>
  + * </ul>
    * <p>
  - * <b>NOTE</b> - Attempting to reload or undeploy the application containing
  + * <b>NOTE</b> - Attempting to reload or remove the application containing
    * this servlet itself will not succeed.  Therefore, this servlet should
    * generally be deployed as a separate web application within the virtual host
    * to be managed.
  @@ -123,7 +153,7 @@
    * </ul>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.3 $ $Date: 2001/01/03 02:20:46 $
  + * @version $Revision: 1.4 $ $Date: 2001/03/26 03:23:35 $
    */
   
   public final class ManagerServlet
  @@ -200,14 +230,20 @@
   	// Process the requested command
   	if (command == null) {
   	    writer.println(sm.getString("managerServlet.noCommand"));
  -	} else if (command.equals("/deploy")) {
  -	    deploy(writer, path, war);
  +	} else if (command.equals("/install")) {
  +	    install(writer, path, war);
   	} else if (command.equals("/list")) {
   	    list(writer);
   	} else if (command.equals("/reload")) {
   	    reload(writer, path);
  -	} else if (command.equals("/undeploy")) {
  -	    undeploy(writer, path);
  +	} else if (command.equals("/remove")) {
  +	    remove(writer, path);
  +        } else if (command.equals("/sessions")) {
  +            sessions(writer, path);
  +        } else if (command.equals("/start")) {
  +            start(writer, path);
  +        } else if (command.equals("/stop")) {
  +            stop(writer, path);
   	} else {
   	    writer.println(sm.getString("managerServlet.unknownCommand",
   					command));
  @@ -260,24 +296,26 @@
   
   
       /**
  -     * Deploy an application for the specified path from the specified
  +     * Install an application for the specified path from the specified
        * web application archive.
        *
        * @param writer Writer to render results to
  -     * @param path Context path of the application to be deployed
  -     * @param war URL of the web application archive to be deployed
  +     * @param path Context path of the application to be installed
  +     * @param war URL of the web application archive to be installed
        */
  -    private void deploy(PrintWriter writer, String path, String war) {
  +    private void install(PrintWriter writer, String path, String war) {
   
           if (debug >= 1)
  -	    log("deploy: Deploying web application at '" + path +
  +	    log("install: Installing web application at '" + path +
   		"' from '" + war + "'");
   
  -        if ((path == null) ||
  -            (!path.startsWith("/") && !path.equals(""))) {
  +        if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
               writer.println(sm.getString("managerServlet.invalidPath", path));
               return;
           }
  +        String displayPath = path;
  +        if( path.equals("/") )
  +            path = "";
           if ((war == null) ||
               (!war.startsWith("file:") && !war.startsWith("jar:"))) {
               writer.println(sm.getString("managerServlet.invalidWar", war));
  @@ -288,13 +326,13 @@
   	  Context context =  deployer.findDeployedApp(path);
   	  if (context != null) {
   	      writer.println(sm.getString("managerServlet.alreadyContext",
  -					  path));
  +					  displayPath));
   	      return;
   	  }
  -          deployer.deploy(path, new URL(war));
  -	  writer.println(sm.getString("managerServlet.deployed", path));
  +          deployer.install(path, new URL(war));
  +	  writer.println(sm.getString("managerServlet.installed", displayPath));
   	} catch (Throwable t) {
  -	    getServletContext().log("ManagerServlet.deploy[" + path + "]", t);
  +	    getServletContext().log("ManagerServlet.install[" + displayPath + "]", t);
   	    writer.println(sm.getString("managerServlet.exception",
   					t.toString()));
   	}
  @@ -316,9 +354,25 @@
           writer.println(sm.getString("managerServlet.listed",
                                       deployer.getName()));
           String contextPaths[] = deployer.findDeployedApps();
  -        for (int i = 0; i < contextPaths.length; i++)
  -            writer.println(contextPaths[i]);
  -
  +        for (int i = 0; i < contextPaths.length; i++) {
  +	    Context context = deployer.findDeployedApp(contextPaths[i]);
  +            String displayPath = contextPaths[i];
  +            if( displayPath.equals("") )
  +                displayPath = "/";
  +	    if (context != null ) {
  +                if (context.getAvailable()) {
  +                    writer.println(sm.getString("managerServlet.listitem",
  +                        displayPath,
  +                        "running",
  +                        "" + context.getManager().findSessions().length));
  +                } else {
  +                    writer.println(sm.getString("managerServlet.listitem",
  +                        displayPath,   
  +                        "stopped",      
  +                        "0"));
  +                }
  +            }
  +        }
       }
   
   
  @@ -333,22 +387,24 @@
           if (debug >= 1)
   	    log("restart: Reloading web application at '" + path + "'");
   
  -        if ((path == null) ||
  -            (!path.startsWith("/") && !path.equals(""))) {
  +        if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
               writer.println(sm.getString("managerServlet.invalidPath", path));
               return;
           }
  +        String displayPath = path;
  +        if( path.equals("/") )
  +            path = "";
   
           try {
   	    Context context = deployer.findDeployedApp(path);
   	    if (context == null) {
  -	        writer.println(sm.getString("managerServlet.noContext", path));
  +	        writer.println(sm.getString("managerServlet.noContext", displayPath));
   		return;
   	    }
   	    context.reload();
  -	    writer.println(sm.getString("managerServlet.reloaded", path));
  +	    writer.println(sm.getString("managerServlet.reloaded", displayPath));
   	} catch (Throwable t) {
  -	    getServletContext().log("ManagerServlet.reload[" + path + "]", t);
  +	    getServletContext().log("ManagerServlet.reload[" + displayPath + "]", t);
   	    writer.println(sm.getString("managerServlet.exception",
   					t.toString()));
   	}
  @@ -357,36 +413,176 @@
   
   
       /**
  -     * Undeploy the web application at the specified context path.
  +     * Remove the web application at the specified context path.
        *
        * @param writer Writer to render to
  -     * @param path Context path of the application to be undeployed
  +     * @param path Context path of the application to be removed
        */
  -    private void undeploy(PrintWriter writer, String path) {
  +    private void remove(PrintWriter writer, String path) {
   
           if (debug >= 1)
  -	    log("undeploy: Undeploying web application at '" + path + "'");
  +	    log("remove: Removing web application at '" + path + "'");
   
  -        if ((path == null) ||
  -            (!path.startsWith("/") && !path.equals(""))) {
  +        if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
               writer.println(sm.getString("managerServlet.invalidPath", path));
               return;
           }
  +        String displayPath = path;
  +        if( path.equals("/") )
  +            path = "";
   
           try {
   	    Context context = deployer.findDeployedApp(path);
   	    if (context == null) {
  -	        writer.println(sm.getString("managerServlet.noContext", path));
  +	        writer.println(sm.getString("managerServlet.noContext", displayPath));
   		return;
   	    }
  -            deployer.undeploy(path);
  -	    writer.println(sm.getString("managerServlet.undeployed", path));
  +            deployer.remove(path);
  +	    writer.println(sm.getString("managerServlet.removed", displayPath));
   	} catch (Throwable t) {
  -	    getServletContext().log("ManagerServlet.undeploy[" + path + "]",
  +	    getServletContext().log("ManagerServlet.remove[" + displayPath + "]",
   				    t);
   	    writer.println(sm.getString("managerServlet.exception",
   					t.toString()));
   	}
  +
  +    }
  +
  +
  +    /**
  +     * Session information for the web application at the specified context path.
  +     * Displays a profile of session MaxInactiveInterval timeouts listing number
  +     * of sessions for each 10 minute timeout interval up to 10 hours.
  +     *
  +     * @param writer Writer to render to
  +     * @param path Context path of the application to list session information for
  +     */
  +    private void sessions(PrintWriter writer, String path) {
  + 
  +        if (debug >= 1)
  +            log("sessions: Session information for web application at '" + path + "'");
  +       
  +        if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
  +            writer.println(sm.getString("managerServlet.invalidPath", path));
  +            return;
  +        }
  +        String displayPath = path;
  +        if( path.equals("/") )
  +            path = ""; 
  +        try {
  +            Context context = deployer.findDeployedApp(path);
  +            if (context == null) {
  +                writer.println(sm.getString("managerServlet.noContext", displayPath));
  +                return;
  +            }
  +            writer.println(sm.getString("managerServlet.sessions", displayPath));
  +	    writer.println(sm.getString("managerServlet.sessiondefaultmax",
  +                "" + context.getManager().getMaxInactiveInterval()/60));
  +	    Session [] sessions = context.getManager().findSessions();
  +            int [] timeout = new int[60];
  +	    int notimeout = 0;
  +            for (int i = 0; i < sessions.length; i++) {
  +                int time = sessions[i].getMaxInactiveInterval()/(10*60);
  +                if (time < 0)
  +                    notimeout++;
  +                else if (time >= timeout.length)
  +                    timeout[timeout.length-1]++;
  +                else
  +                    timeout[time]++;
  +            }
  +            if (timeout[0] > 0)
  +                writer.println(sm.getString("managerServlet.sessiontimeout",
  +                    "<10" + timeout[0]));
  +            for (int i = 1; i < timeout.length-1; i++) {
  +                if (timeout[i] > 0)
  +                    writer.println(sm.getString("managerServlet.sessiontimeout",
  +                        "" + (i)*10 + " - <" + (i+1)*10,"" + timeout[i]));
  +            }
  +            if (timeout[timeout.length-1] > 0)            
  +                writer.println(sm.getString("managerServlet.sessiontimeout",
  +                    ">=" + timeout.length*10,"" + timeout[timeout.length-1]));
  +            if (notimeout > 0)
  +               writer.println(sm.getString("managerServlet.sessiontimeout",
  +                   "unlimited","" + notimeout));
  +        } catch (Throwable t) {
  +            getServletContext().log("ManagerServlet.sessions[" + displayPath + "]",
  +                                    t);
  +            writer.println(sm.getString("managerServlet.exception",
  +                                        t.toString()));
  +        }
  +       
  +    }
  +
  +    /**
  +     * Start the web application at the specified context path.
  +     *
  +     * @param writer Writer to render to
  +     * @param path Context path of the application to be started
  +     */
  +    private void start(PrintWriter writer, String path) {
  + 
  +        if (debug >= 1)
  +            log("start: Starting web application at '" + path + "'");
  +       
  +        if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
  +            writer.println(sm.getString("managerServlet.invalidPath", path));
  +            return;
  +        }
  +        String displayPath = path;
  +        if( path.equals("/") )
  +            path = "";
  + 
  +        try {
  +            Context context = deployer.findDeployedApp(path);
  +            if (context == null) {
  +                writer.println(sm.getString("managerServlet.noContext", displayPath));
  +                return;
  +            }
  +            deployer.start(path);
  +            writer.println(sm.getString("managerServlet.started", displayPath));
  +        } catch (Throwable t) {
  +            getServletContext().log("ManagerServlet.start[" + displayPath + "]",
  +                                    t);
  +            writer.println(sm.getString("managerServlet.exception",
  +                                        t.toString()));
  +        }
  +       
  +    }
  +
  +
  +    /**
  +     * Stop the web application at the specified context path.
  +     *
  +     * @param writer Writer to render to
  +     * @param path Context path of the application to be stopped
  +     */
  +    private void stop(PrintWriter writer, String path) {
  +
  +        if (debug >= 1)
  +            log("stop: Stopping web application at '" + path + "'");
  +
  +        if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
  +            writer.println(sm.getString("managerServlet.invalidPath", path));
  +            return;
  +        }
  +        String displayPath = path;
  +        if( path.equals("/") )
  +            path = "";
  +
  +        try {
  +            Context context = deployer.findDeployedApp(path);
  +            if (context == null) {
  +                writer.println(sm.getString("managerServlet.noContext", displayPath));
  +                return;
  +            }          
  +            deployer.stop(path);
  +            writer.println(sm.getString("managerServlet.stopped", displayPath));
  +        } catch (Throwable t) {
  +            getServletContext().log("ManagerServlet.stop[" + displayPath + "]",
  +                                    t);                                  
  +            writer.println(sm.getString("managerServlet.exception",
  +                                        t.toString()));            
  +        }
   
       }
   
  
  
  

Mime
View raw message