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...@apache.org on 2002/01/05 01:15:36 UTC

cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets LocalStrings.properties ManagerServlet.java

craigmcc    02/01/04 16:15:36

  Modified:    catalina/src/share/org/apache/catalina/servlets
                        LocalStrings.properties ManagerServlet.java
  Log:
  Update the manager servlet to support the (new-to-4.1-dev) option to
  deploy a context configuration file -- an XML file containing just the
  <Context> element and its nested elements from server.xml.  An example
  URL to install such an app would be:
  
    http://localhost:8080/manager/install?config=file:///path/to/myconfig.xml
  
  Revision  Changes    Path
  1.10      +1 -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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- LocalStrings.properties	15 Sep 2001 23:31:30 -0000	1.9
  +++ LocalStrings.properties	5 Jan 2002 00:15:36 -0000	1.10
  @@ -10,6 +10,7 @@
   invokerServlet.noWrapper=Container has not called setWrapper() for this servlet
   managerServlet.alreadyContext=FAIL - Application already exists at path {0}
   managerServlet.cannotInvoke=Cannot invoke manager servlet through invoker
  +managerServlet.configured=OK - Installed application from context file {0}
   managerServlet.exception=FAIL - Encountered exception {0}
   managerServlet.installed=OK - Installed application at context path {0}
   managerServlet.invalidPath=FAIL - Invalid context path {0} was specified
  
  
  
  1.11      +88 -32    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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ManagerServlet.java	25 Oct 2001 00:23:03 -0000	1.10
  +++ ManagerServlet.java	5 Jan 2002 00:15:36 -0000	1.11
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/ManagerServlet.java,v 1.10 2001/10/25 00:23:03 craigmcc Exp $
  - * $Revision: 1.10 $
  - * $Date: 2001/10/25 00:23:03 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/ManagerServlet.java,v 1.11 2002/01/05 00:15:36 craigmcc Exp $
  + * $Revision: 1.11 $
  + * $Date: 2002/01/05 00:15:36 $
    *
    * ====================================================================
    *
  @@ -95,6 +95,16 @@
    * The following actions and parameters (starting after the servlet path)
    * are supported:
    * <ul>
  + * <li><b>/install?config={config-url}</b> - Install and start a new
  + *     web application, based on the contents of the context configuration
  + *     file found at the specified URL.  The <code>docBase</code> attribute
  + *     of the context configuration file is used to locate the actual
  + *     WAR or directory containing the application.</li>
  + * <li><b>/install?config={config-url}&war={war-url}/</b> - Install and start
  + *     a new web application, based on the contents of the context
  + *     configuration file found at <code>{config-url}</code>, overriding the
  + *     <code>docBase</code> attribute with the contents of the web
  + *     application archive found at <code>{war-url}</code>.</li>
    * <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
  @@ -153,7 +163,7 @@
    * </ul>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.10 $ $Date: 2001/10/25 00:23:03 $
  + * @version $Revision: 1.11 $ $Date: 2002/01/05 00:15:36 $
    */
   
   public class ManagerServlet
  @@ -263,6 +273,7 @@
           String command = request.getPathInfo();
           if (command == null)
               command = request.getServletPath();
  +        String config = request.getParameter("config");
           String path = request.getParameter("path");
           String war = request.getParameter("war");
   
  @@ -274,7 +285,7 @@
           if (command == null) {
               writer.println(sm.getString("managerServlet.noCommand"));
           } else if (command.equals("/install")) {
  -            install(writer, path, war);
  +            install(writer, config, path, war);
           } else if (command.equals("/list")) {
               list(writer);
           } else if (command.equals("/reload")) {
  @@ -345,41 +356,86 @@
        * web application archive.
        *
        * @param writer Writer to render results to
  +     * @param config URL of the context configuration file to be installed
        * @param path Context path of the application to be installed
        * @param war URL of the web application archive to be installed
        */
  -    protected void install(PrintWriter writer, String path, String war) {
  +    protected void install(PrintWriter writer, String config,
  +                           String path, String war) {
   
  -        if (debug >= 1)
  -            log("install: Installing web application at '" + path +
  -                "' from '" + war + "'");
  -
  -        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));
  -            return;
  +        if (debug >= 1) {
  +            if (config != null) {
  +                if (war != null) {
  +                    log("install: Installing context configuration at '" +
  +                        config + "' from '" + war + "'");
  +                } else {
  +                    log("install: Installing context configuration at '" +
  +                        config + "'");
  +                }
  +            } else {
  +                log("install: Installing web application at '" + path +
  +                    "' from '" + war + "'");
  +            }
           }
   
  -        try {
  -            Context context =  deployer.findDeployedApp(path);
  -            if (context != null) {
  -                writer.println(sm.getString("managerServlet.alreadyContext",
  -                                            displayPath));
  +        if (config != null) {
  +
  +            if ((war != null) &&
  +                (!war.startsWith("file:") && !war.startsWith("jar:"))) {
  +                writer.println(sm.getString("managerServlet.invalidWar", war));
                   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 {
  +                if (war == null) {
  +                    deployer.install(new URL(config), null);
  +                } else {
  +                    deployer.install(new URL(config), new URL(war));
  +                }
  +                writer.println(sm.getString("managerServlet.configured",
  +                                            config));
  +            } catch (Throwable t) {
  +                getServletContext().log("ManagerServlet.configure[" +
  +                                        config + "]", t);
  +                writer.println(sm.getString("managerServlet.exception",
  +                                            t.toString()));
  +            }
  +
  +        } else {
  +
  +            if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
  +                writer.println(sm.getString("managerServlet.invalidPath",
  +                                            path));
  +                return;
  +            }
  +            String displayPath = path;
  +            if("/".equals(path)) {
  +                path = "";
  +            }
  +            if ((war == null) ||
  +                (!war.startsWith("file:") && !war.startsWith("jar:"))) {
  +                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()));
  +            }
  +
           }
   
       }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>