bip         01/05/27 14:09:11

  Modified:    catalina/src/share/org/apache/catalina/servlets
                        ManagerServlet.java
  Added:       catalina/src/share/org/apache/catalina/servlets
                        HTMLManagerServlet.java
  Log:
  Changed ManagerServlet to allow for subclassing.
  
  Added HTMLManagerServlet which is a ManagerServlet with
  a extended HTML interface to allow for easier administration.
  
  Revision  Changes    Path
  1.6       +130 -128  
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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ManagerServlet.java       2001/05/14 00:02:32     1.5
  +++ ManagerServlet.java       2001/05/27 21:09:11     1.6
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/ManagerServlet.java,v
 1.5 2001/05/14 00:02:32 craigmcc Exp $
  - * $Revision: 1.5 $
  - * $Date: 2001/05/14 00:02:32 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/ManagerServlet.java,v
 1.6 2001/05/27 21:09:11 bip Exp $
  + * $Revision: 1.6 $
  + * $Date: 2001/05/27 21:09:11 $
    *
    * ====================================================================
    *
  @@ -152,10 +152,10 @@
    * </ul>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.5 $ $Date: 2001/05/14 00:02:32 $
  + * @version $Revision: 1.6 $ $Date: 2001/05/27 21:09:11 $
    */
   
  -public final class ManagerServlet
  +public class ManagerServlet
       extends HttpServlet implements ContainerServlet {
   
   
  @@ -165,13 +165,13 @@
       /**
        * The Context container associated with our web application.
        */
  -    private Context context = null;
  +    protected Context context = null;
   
   
       /**
        * The debugging detail level for this servlet.
        */
  -    private int debug = 1;
  +    protected int debug = 1;
   
   
       /**
  @@ -179,20 +179,20 @@
        * along with the associated Contexts for web applications that we
        * are managing.
        */
  -    private Deployer deployer = null;
  +    protected Deployer deployer = null;
   
   
       /**
        * The string manager for this package.
        */
  -    private static StringManager sm =
  -      StringManager.getManager(Constants.Package);
  +    protected static StringManager sm =
  +     StringManager.getManager(Constants.Package);
   
   
       /**
        * The Wrapper container associated with this servlet.
        */
  -    private Wrapper wrapper = null;
  +    protected Wrapper wrapper = null;
   
   
       // ----------------------------------------------- ContainerServlet Methods
  @@ -250,46 +250,46 @@
        * @exception ServletException if a servlet-specified error occurs
        */
       public void doGet(HttpServletRequest request,
  -                   HttpServletResponse response)
  -     throws IOException, ServletException {
  +                      HttpServletResponse response)
  +        throws IOException, ServletException {
   
  -     // Identify the request parameters that we need
  -     String command = request.getPathInfo();
  -     if (command == null)
  -         command = request.getServletPath();
  -     String path = request.getParameter("path");
  -     String war = request.getParameter("war");
  -
  -     // Prepare our output writer to generate the response message
  -     response.setContentType("text/plain");
  -     PrintWriter writer = response.getWriter();
  -
  -     // Process the requested command
  -     if (command == null) {
  -         writer.println(sm.getString("managerServlet.noCommand"));
  -     } 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("/remove")) {
  -         remove(writer, path);
  +        // Identify the request parameters that we need
  +        String command = request.getPathInfo();
  +        if (command == null)
  +            command = request.getServletPath();
  +        String path = request.getParameter("path");
  +        String war = request.getParameter("war");
  +        
  +        // Prepare our output writer to generate the response message
  +        response.setContentType("text/plain");
  +        PrintWriter writer = response.getWriter();
  +        
  +        // Process the requested command
  +        if (command == null) {
  +            writer.println(sm.getString("managerServlet.noCommand"));
  +        } 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("/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));
  -     }
  -
  -     // Finish up the response
  -     writer.flush();
  -     writer.close();
  -
  +        } else {
  +            writer.println(sm.getString("managerServlet.unknownCommand",
  +                                        command));
  +        }
  +        
  +        // Finish up the response
  +        writer.flush();
  +        writer.close();
  +        
       }
   
   
  @@ -311,23 +311,23 @@
               throw new UnavailableException
                   (sm.getString("managerServlet.cannotInvoke"));
   
  -     // Set our properties from the initialization parameters
  -     String value = null;
  -     try {
  -         value = getServletConfig().getInitParameter("debug");
  -         debug = Integer.parseInt(value);
  -     } catch (Throwable t) {
  -         ;
  -     }
  +        // Set our properties from the initialization parameters
  +        String value = null;
  +        try {
  +            value = getServletConfig().getInitParameter("debug");
  +            debug = Integer.parseInt(value);
  +        } catch (Throwable t) {
  +            ;
  +        }
   
   
        // Log debugging messages as necessary
  -     if (debug >= 1) {
  -         log("init: Associated with Deployer '" + deployer.getName() + "'");
  -     }
  -
  +        if (debug >= 1) {
  +            log("init: Associated with Deployer '" + deployer.getName() + "'");
  +        }
  +        
       }
  -
  +    
   
   
       // -------------------------------------------------------- Private Methods
  @@ -341,12 +341,12 @@
        * @param path Context path of the application to be installed
        * @param war URL of the web application archive to be installed
        */
  -    private void install(PrintWriter writer, String path, String war) {
  +    protected void install(PrintWriter writer, String path, String war) {
   
           if (debug >= 1)
  -         log("install: Installing web application at '" + path +
  -             "' from '" + war + "'");
  -
  +            log("install: Installing web application at '" + path +
  +                "' from '" + war + "'");
  +        
           if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
               writer.println(sm.getString("managerServlet.invalidPath", path));
               return;
  @@ -359,22 +359,22 @@
               writer.println(sm.getString("managerServlet.invalidWar", war));
               return;
           }
  -
  -     try {
  -       Context context =  deployer.findDeployedApp(path);
  -       if (context != null) {
  -           writer.println(sm.getString("managerServlet.alreadyContext",
  -                                       displayPath));
  -           return;
  -       }
  -          deployer.install(path, new URL(war));
  -       writer.println(sm.getString("managerServlet.installed", displayPath));
  -     } catch (Throwable t) {
  -         getServletContext().log("ManagerServlet.install[" + displayPath + "]", t);
  -         writer.println(sm.getString("managerServlet.exception",
  -                                     t.toString()));
  -     }
  -
  +        
  +        try {
  +            Context context =  deployer.findDeployedApp(path);
  +            if (context != null) {
  +                writer.println(sm.getString("managerServlet.alreadyContext",
  +                                            displayPath));
  +                return;
  +            }
  +            deployer.install(path, new URL(war));
  +            writer.println(sm.getString("managerServlet.installed", displayPath));
  +        } catch (Throwable t) {
  +            getServletContext().log("ManagerServlet.install[" + displayPath + "]", 
t);
  +            writer.println(sm.getString("managerServlet.exception",
  +                                        t.toString()));
  +        }
  +        
       }
   
   
  @@ -383,7 +383,7 @@
        *
        * @param writer Writer to render to
        */
  -    private void list(PrintWriter writer) {
  +    protected void list(PrintWriter writer) {
   
           if (debug >= 1)
            log("list: Listing contexts for virtual host '" +
  @@ -397,33 +397,33 @@
               String displayPath = contextPaths[i];
               if( displayPath.equals("") )
                   displayPath = "/";
  -         if (context != null ) {
  +            if (context != null ) {
                   if (context.getAvailable()) {
                       writer.println(sm.getString("managerServlet.listitem",
  -                        displayPath,
  -                        "running",
  -                        "" + context.getManager().findSessions().length));
  +                                                displayPath,
  +                                                "running",
  +                                      "" + 
context.getManager().findSessions().length));
                   } else {
                       writer.println(sm.getString("managerServlet.listitem",
  -                        displayPath,   
  -                        "stopped",      
  -                        "0"));
  +                                                displayPath,   
  +                                                "stopped",      
  +                                                "0"));
                   }
               }
           }
       }
  -
  -
  +    
  +    
       /**
        * Reload the web application at the specified context path.
        *
        * @param writer Writer to render to
        * @param path Context path of the application to be restarted
        */
  -    private void reload(PrintWriter writer, String path) {
  +    protected void reload(PrintWriter writer, String path) {
   
           if (debug >= 1)
  -         log("restart: Reloading web application at '" + path + "'");
  +            log("restart: Reloading web application at '" + path + "'");
   
           if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
               writer.println(sm.getString("managerServlet.invalidPath", path));
  @@ -432,20 +432,20 @@
           String displayPath = path;
           if( path.equals("/") )
               path = "";
  -
  +        
           try {
            Context context = deployer.findDeployedApp(path);
            if (context == null) {
                writer.println(sm.getString("managerServlet.noContext", displayPath));
  -             return;
  +            return;
            }
            context.reload();
            writer.println(sm.getString("managerServlet.reloaded", displayPath));
  -     } catch (Throwable t) {
  -         getServletContext().log("ManagerServlet.reload[" + displayPath + "]", t);
  -         writer.println(sm.getString("managerServlet.exception",
  -                                     t.toString()));
  -     }
  +        } catch (Throwable t) {
  +            getServletContext().log("ManagerServlet.reload[" + displayPath + "]", 
t);
  +            writer.println(sm.getString("managerServlet.exception",
  +                                        t.toString()));
  +        }
   
       }
   
  @@ -456,10 +456,10 @@
        * @param writer Writer to render to
        * @param path Context path of the application to be removed
        */
  -    private void remove(PrintWriter writer, String path) {
  +    protected void remove(PrintWriter writer, String path) {
   
           if (debug >= 1)
  -         log("remove: Removing web application at '" + path + "'");
  +            log("remove: Removing web application at '" + path + "'");
   
           if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
               writer.println(sm.getString("managerServlet.invalidPath", path));
  @@ -468,22 +468,22 @@
           String displayPath = path;
           if( path.equals("/") )
               path = "";
  -
  +        
           try {
  -         Context context = deployer.findDeployedApp(path);
  -         if (context == null) {
  -             writer.println(sm.getString("managerServlet.noContext", displayPath));
  -             return;
  -         }
  +            Context context = deployer.findDeployedApp(path);
  +            if (context == null) {
  +                writer.println(sm.getString("managerServlet.noContext", 
displayPath));
  +                return;
  +            }
               deployer.remove(path);
  -         writer.println(sm.getString("managerServlet.removed", displayPath));
  -     } catch (Throwable t) {
  -         getServletContext().log("ManagerServlet.remove[" + displayPath + "]",
  -                                 t);
  -         writer.println(sm.getString("managerServlet.exception",
  -                                     t.toString()));
  -     }
  -
  +            writer.println(sm.getString("managerServlet.removed", displayPath));
  +        } catch (Throwable t) {
  +            getServletContext().log("ManagerServlet.remove[" + displayPath + "]",
  +                                    t);
  +            writer.println(sm.getString("managerServlet.exception",
  +                                        t.toString()));
  +        }
  +        
       }
   
   
  @@ -495,7 +495,7 @@
        * @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) {
  +    protected void sessions(PrintWriter writer, String path) {
    
           if (debug >= 1)
               log("sessions: Session information for web application at '" + path + 
"'");
  @@ -514,11 +514,11 @@
                   return;
               }
               writer.println(sm.getString("managerServlet.sessions", displayPath));
  -         writer.println(sm.getString("managerServlet.sessiondefaultmax",
  -                "" + context.getManager().getMaxInactiveInterval()/60));
  -         Session [] sessions = context.getManager().findSessions();
  +            writer.println(sm.getString("managerServlet.sessiondefaultmax",
  +                                "" + 
context.getManager().getMaxInactiveInterval()/60));
  +            Session [] sessions = context.getManager().findSessions();
               int [] timeout = new int[60];
  -         int notimeout = 0;
  +            int notimeout = 0;
               for (int i = 0; i < sessions.length; i++) {
                   int time = sessions[i].getMaxInactiveInterval()/(10*60);
                   if (time < 0)
  @@ -530,34 +530,36 @@
               }
               if (timeout[0] > 0)
                   writer.println(sm.getString("managerServlet.sessiontimeout",
  -                    "<10" + timeout[0]));
  +                                            "<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]));
  +                                     "" + (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]));
  +                                            ">=" + timeout.length*10,
  +                                            "" + timeout[timeout.length-1]));
               if (notimeout > 0)
  -               writer.println(sm.getString("managerServlet.sessiontimeout",
  -                   "unlimited","" + notimeout));
  +                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) {
  +    protected void start(PrintWriter writer, String path) {
    
           if (debug >= 1)
               log("start: Starting web application at '" + path + "'");
  @@ -569,7 +571,7 @@
           String displayPath = path;
           if( path.equals("/") )
               path = "";
  - 
  +        
           try {
               Context context = deployer.findDeployedApp(path);
               if (context == null) {
  @@ -584,7 +586,7 @@
               writer.println(sm.getString("managerServlet.exception",
                                           t.toString()));
           }
  -       
  +        
       }
   
   
  @@ -594,7 +596,7 @@
        * @param writer Writer to render to
        * @param path Context path of the application to be stopped
        */
  -    private void stop(PrintWriter writer, String path) {
  +    protected void stop(PrintWriter writer, String path) {
   
           if (debug >= 1)
               log("stop: Stopping web application at '" + path + "'");
  
  
  
  1.1                  
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/HTMLManagerServlet.java
  
  Index: HTMLManagerServlet.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/HTMLManagerServlet.java,v
 1.1 2001/05/27 21:09:11 bip Exp $
   * $Revision: 1.1 $
   * $Date: 2001/05/27 21:09:11 $
   *
   * ====================================================================
   *
   * 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.servlets;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import org.apache.catalina.Context;
  import org.apache.catalina.Globals;
  
  /**
   * Servlet that enables remote management of the web applications installed
   * within the same virtual host as this web application is.  Normally, this
   * functionality will be protected by a security constraint in the web
   * application deployment descriptor.  However, this requirement can be
   * relaxed during testing.
   * <p>
   * The difference between this <code>ManagerServlet</code> and this
   * Servlet is that this Servlet prints out a HTML interface which
   * makes it easier to administrate.
   * <p>
   * However if you use a software that parses the output of
   * <code>ManagerServlet</code you won't be able to upgrade
   * to this Servlet since the output are not in the
   * same format ar from <code>ManagerServlet</code>
   *
   * @author Bip Thelin
   * @version $Revision: 1.1 $, $Date: 2001/05/27 21:09:11 $
   * @see ManagerServlet
   */
  
  public final class HTMLManagerServlet extends ManagerServlet {
  
      // --------------------------------------------------------- Public Methods
  
      /**
       * Render a HTML list of the currently
       * active Contexts in our virtual host.
       *
       * @param writer Writer to render to
       */
      public void list(PrintWriter writer) {
  
          if (debug >= 1)
              log("list: Listing contexts for virtual host '" +
                  deployer.getName() + "'");
          
          writer.print("<html>\n<head>\n<title>");
          writer.print("Listed applications for virtual host ");
          writer.print(deployer.getName()+"</title>\n</head>\n");
          writer.print("<body bgcolor=\"#FFFFFF\">\n");
          writer.print("<form method=\"get\" action=\"install\">");
          writer.print("<table cellspacing=\"0\"");
          writer.print("cellpadding=\"3\" align=\"center\">\n");
          writer.print("<tr><td colspan=\"3\"><font size=\"+2\"");
          writer.print(" face=\"Arial, Helvetica, sans-serif\">\n");
          writer.print("<strong>Listed applications for virtual host ");
          writer.print(deployer.getName()+"</strong>\n</font></td>\n</tr>\n");
          writer.print("<tr bgcolor=\"#CCCCCC\">\n");
          writer.print("<td align=\"left\"><font size=\"+1\"");
          writer.print(" face=\"Arial, Helvetica, sans-serif\">\n");
          writer.print("<strong>Path</strong></font>\n</td>");
          writer.print("<td align=\"center\"><font size=\"+1\"");
          writer.print(" face=\"Arial, Helvetica, sans-serif\">\n");
          writer.print("<strong>Status</strong></font></td>\n");
          writer.print("<td align=\"right\"><font size=\"+1\"");
          writer.print(" face=\"Arial, Helvetica, sans-serif\">\n");
          writer.print("<strong>Sessions</strong></font></td>\n");
          writer.print("<td align=\"right\"><font size=\"+1\"");
          writer.print(" face=\"Arial, Helvetica, sans-serif\">\n");
          writer.print("<strong>Reload</strong></font></td>\n");
          writer.print("<td align=\"right\"><font size=\"+1\"");
          writer.print(" face=\"Arial, Helvetica, sans-serif\">\n");
          writer.print("<strong>Remove</strong></font></td>\n</tr>\n");
          
          String contextPaths[] = deployer.findDeployedApps();
          
          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 ) {
                  writer.print("<tr bgcolor=\"#FFFFFF\">\n");
                  writer.print("<td align=\"left\"><font size=\"1\"");
                  writer.print(" face=\"Arial, Helvetica, sans-serif\">\n");
                  writer.print(displayPath+"</font>\n</td>");
                  writer.print("<td align=\"center\"><font size=\"1\"");
                  writer.print(" face=\"Arial, Helvetica, sans-serif\">\n");
                  
                  if (context.getAvailable()) {
                      writer.print("running / <a href=\"stop?path="+displayPath);
                      writer.print("\">stop</a>");
                  } else {
                      writer.print("<a href=\"start?path="+displayPath);
                      writer.print("\">start</a> / stopped");
                  }
                  
                  writer.print("</font></td>\n");
                  writer.print("<td align=\"right\"><font size=\"1\"");
                  writer.print(" face=\"Arial, Helvetica, sans-serif\">\n");
                  writer.print("<a href=\"sessions?path="+displayPath+"\">");
                  writer.print(context.getManager().findSessions().length);
                  writer.print("</a></font></td>\n");
                  writer.print("<td align=\"right\"><font size=\"1\"");
                  writer.print(" face=\"Arial, Helvetica, sans-serif\">\n");
                  
                  if (context.getAvailable()) {
                      writer.print("<a href=\"reload?path="+displayPath+"\">");
                      writer.print("Reload &#187;");
                      writer.print("</a></font></td>\n");
                  } else {
                      writer.print("-</font></td>");
                  }
                  
                  writer.print("<td align=\"right\"><font size=\"1\"");
                  writer.print(" face=\"Arial, Helvetica, sans-serif\">\n");
                  writer.print("<a href=\"remove?path="+displayPath+"\">");
                  writer.print("Remove &#187;");
                  writer.print("</a></font></td>\n</tr>\n");
              }
          }
          
          writer.print("<tr><td colspan=\"5\">&nbsp;</td></tr>");
          writer.print("<tr><td>");
          writer.print("<font size=\"2\"");
          writer.print(" face=\"Arial, Helvetica, sans-serif\">");
          writer.print("<b>Install a webapp</b></font></td>\n");
          writer.print("<td><font size=\"2\" face=\"Arial, Helvetica, sans-serif\">");
          writer.print("Path:&nbsp;</font>");
          writer.print("<input type=\"text\" name=\"path\" size=\"25\"></td>");
          writer.print("<td><font size=\"2\" face=\"Arial, Helvetica, sans-serif\">");
          writer.print("War-URL:&nbsp;</font>");
          writer.print("<input type=\"text\" name=\"war\" size=\"25\"></td>");
          writer.print("<td colspan=\"2\">");
          writer.print("&nbsp;<input type=\"submit\" value=\"install\"></td></tr>\n");
          writer.print("<tr><td colspan=\"5\" bgcolor=\"#CCCCCC\"><font size=\"-1\" ");
          writer.print(" face=\"Arial, Helvetica, sans-serif\">\n");
          writer.print(Globals.SERVER_INFO+"</font></td>\n</tr>\n");
          writer.print("</table>\n</form>\n</body>\n</html>");
      }
      
      /**
       * Reload the web application at the specified context path.
       *
       * @param writer Writer to render to
       * @param path Context path of the application to be restarted
       */
      protected void reload(PrintWriter writer, String path) {
          
          if (debug >= 1)
              log("restart: Reloading web application at '" + path + "'");
          
          if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
              writer.println(sm.getString("managerServlet.invalidPath", path));
              list(writer);
              
              return;
          }
          
          String displayPath = path;
          
          if( path.equals("/") )
              path = "";
          
          try {
              Context context = deployer.findDeployedApp(path);
              
              if (context == null) {
                  writer.println(sm.getString("managerServlet.noContext", 
displayPath));
                  list(writer);
                  
                  return;
              }
              
              context.reload();
              list(writer);
          } catch (Throwable t) {
              getServletContext().log("ManagerServlet.reload[" + displayPath + "]", t);
              writer.println(sm.getString("managerServlet.exception",
                                          t.toString()));
          }
      }
      
      /**
       * Remove the web application at the specified context path.
       *
       * @param writer Writer to render to
       * @param path Context path of the application to be removed
       */
      protected void remove(PrintWriter writer, String path) {
          
          if (debug >= 1)
              log("remove: Removing web application at '" + path + "'");
          
          if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
              writer.println(sm.getString("managerServlet.invalidPath", path));
              list(writer);
              
              return;
          }
          
          String displayPath = path;
          
          if( path.equals("/") )
              path = "";
          
          try {
              Context context = deployer.findDeployedApp(path);
              
              if (context == null) {
                  writer.println(sm.getString("managerServlet.noContext", 
displayPath));
                  list(writer);
                  
                  return;
              }
              
              deployer.remove(path);
              list(writer);
          } catch (Throwable t) {
              getServletContext().log("ManagerServlet.remove[" + 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
       */
      public 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));
              list(writer);
              
              return;
          }
          
          String displayPath = path;
          
          if( path.equals("/") )
              path = "";
          
          try {
              Context context = deployer.findDeployedApp(path);
              
              if (context == null) {
                  writer.println(sm.getString("managerServlet.noContext", 
displayPath));
                  list(writer);
                  
                  return;
              }
              
              deployer.start(path);
              list(writer);
          } 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
       */
      protected 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));
              list(writer);
              
              return;
          }
  
          String displayPath = path;
  
          if( path.equals("/") )
              path = "";
          
          try {
              Context context = deployer.findDeployedApp(path);
              
              if (context == null) {
                  writer.println(sm.getString("managerServlet.noContext", 
displayPath));
                  list(writer);
                  
                  return;
              }          
              
              deployer.stop(path);
              list(writer);
          } catch (Throwable t) {
              getServletContext().log("ManagerServlet.stop[" + displayPath + "]",
                                      t);                                  
              writer.println(sm.getString("managerServlet.exception",
                                          t.toString()));            
          }
      }
  }
  
  
  

Reply via email to