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/03/12 22:14:16 UTC

cvs commit: jakarta-tomcat-4.0/webapps/tomcat-docs manager-howto.xml

craigmcc    02/03/12 13:14:16

  Modified:    catalina/src/share/org/apache/catalina/servlets
                        LocalStrings.properties ManagerServlet.java
               webapps/tomcat-docs manager-howto.xml
  Added:       catalina/src/share/org/apache/catalina/ant
                        ResourcesTask.java
  Log:
  Add a new "/resources" command that will enumerate the available global JNDI
  resources (either all of them, or all of them for a specific type like
  javax.sql.DataSource).  This is useful to tools that want to package up
  webapps and create the <Context> configuration element, with embedded
  <ResourceLink> elements that link resource references in the web.xml to
  the corresponding actual resources.
  
  Revision  Changes    Path
  1.1                  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/ant/ResourcesTask.java
  
  Index: ResourcesTask.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/ant/ResourcesTask.java,v 1.1 2002/03/12 21:14:15 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2002/03/12 21:14:15 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 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 apache@apache.org.
   *
   * 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/>.
   *
   */
  
  
  package org.apache.catalina.ant;
  
  
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.Task;
  
  
  /**
   * Ant task that implements the <code>/list</code> command, supported by the
   * Tomcat manager application.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2002/03/12 21:14:15 $
   * @since 4.1
   */
  public class ResourcesTask extends AbstractCatalinaTask {
  
  
      // ------------------------------------------------------------- Properties
  
  
      /**
       * The fully qualified class name of the resource type being requested
       * (if any).
       */
      protected String type = null;
  
      public String getType() {
          return (this.type);
      }
  
      public void setType(String type) {
          this.type = type;
      }
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Execute the requested operation.
       *
       * @exception BuildException if an error occurs
       */
      public void execute() throws BuildException {
  
          super.execute();
          if (type != null) {
              execute("/resources?type=" + type);
          } else {
              execute("/resources");
          }
  
      }
  
  
  }
  
  
  
  1.14      +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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- LocalStrings.properties	27 Feb 2002 22:43:56 -0000	1.13
  +++ LocalStrings.properties	12 Mar 2002 21:14:15 -0000	1.14
  @@ -24,6 +24,7 @@
   managerServlet.noContext=FAIL - No context exists for path {0}
   managerServlet.noDirectory=FAIL - Non-directory document base for path {0}
   managerServlet.noDocBase=FAIL - Cannot remove document base for path {0}
  +managerServlet.noGlobal=FAIL - No global JNDI resources are available
   managerServlet.noPath=FAIL - No context path was specified
   managerServlet.noReload=FAIL - Reload not supported on WAR deployed at path {0}
   managerServlet.noRename=FAIL - Cannot deploy uploaded WAR for path {0}
  @@ -31,6 +32,8 @@
   managerServlet.noWrapper=Container has not called setWrapper() for this servlet
   managerServlet.reloaded=OK - Reloaded application at context path {0}
   managerServlet.removed=OK - Removed application at context path {0}
  +managerServlet.resourcesAll=OK - Listed global resources of all types
  +managerServlet.resourcesType=OK - Listed global resources of type {0}
   managerServlet.sessiondefaultmax=Default maximum session inactive interval {0} minutes
   managerServlet.sessiontimeout={0} minutes:{1} sessions
   managerServlet.sessions=OK - Session information for application at context path {0}
  
  
  
  1.17      +82 -4     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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- ManagerServlet.java	1 Mar 2002 03:04:44 -0000	1.16
  +++ ManagerServlet.java	12 Mar 2002 21:14:15 -0000	1.17
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/ManagerServlet.java,v 1.16 2002/03/01 03:04:44 craigmcc Exp $
  - * $Revision: 1.16 $
  - * $Date: 2002/03/01 03:04:44 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/ManagerServlet.java,v 1.17 2002/03/12 21:14:15 craigmcc Exp $
  + * $Revision: 1.17 $
  + * $Date: 2002/03/12 21:14:15 $
    *
    * ====================================================================
    *
  @@ -75,6 +75,8 @@
   import java.util.Enumeration;
   import java.util.jar.JarEntry;
   import java.util.jar.JarFile;
  +import javax.naming.NameClassPair;
  +import javax.naming.NamingEnumeration;
   import javax.naming.directory.DirContext;
   import javax.servlet.ServletException;
   import javax.servlet.ServletInputStream;
  @@ -88,8 +90,11 @@
   import org.apache.catalina.Deployer;
   import org.apache.catalina.Globals;
   import org.apache.catalina.Host;
  +import org.apache.catalina.Server;
  +import org.apache.catalina.ServerFactory;
   import org.apache.catalina.Session;
   import org.apache.catalina.Wrapper;
  +import org.apache.catalina.core.StandardServer;
   import org.apache.catalina.util.StringManager;
   import org.apache.naming.resources.ProxyDirContext;
   import org.apache.naming.resources.WARDirContext;
  @@ -131,6 +136,9 @@
    *     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>/resources?type=xxxx</b> - Enumerate the available global JNDI
  + *     resources, optionally limited to those of the specified type
  + *     (fully qualified Java class name), if available.</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>
  @@ -182,7 +190,7 @@
    * </ul>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.16 $ $Date: 2002/03/01 03:04:44 $
  + * @version $Revision: 1.17 $ $Date: 2002/03/12 21:14:15 $
    */
   
   public class ManagerServlet
  @@ -213,6 +221,13 @@
   
   
       /**
  +     * The global JNDI <code>NamingContext</code> for this server,
  +     * if available.
  +     */
  +    protected javax.naming.Context global = null;
  +
  +
  +    /**
        * The string manager for this package.
        */
       protected static StringManager sm =
  @@ -294,6 +309,7 @@
               command = request.getServletPath();
           String config = request.getParameter("config");
           String path = request.getParameter("path");
  +        String type = request.getParameter("type");
           String war = request.getParameter("war");
   
           // Prepare our output writer to generate the response message
  @@ -311,6 +327,8 @@
               reload(writer, path);
           } else if (command.equals("/remove")) {
               remove(writer, path);
  +        } else if (command.equals("/resources")) {
  +            resources(writer, type);
           } else if (command.equals("/sessions")) {
               sessions(writer, path);
           } else if (command.equals("/start")) {
  @@ -403,11 +421,19 @@
               ;
           }
   
  +        // Acquire global JNDI resources if available
  +        Server server = ServerFactory.getServer();
  +        if ((server != null) && (server instanceof StandardServer)) {
  +            global = ((StandardServer) server).getGlobalNamingContext();
  +        }
   
           // Log debugging messages as necessary
           if (debug >= 1) {
               log("init: Associated with Deployer '" +
                   deployer.getName() + "'");
  +            if (global != null) {
  +                log("init: Global resources are available");
  +            }
           }
   
       }
  @@ -703,6 +729,58 @@
               writer.println(sm.getString("managerServlet.removed", displayPath));
           } catch (Throwable t) {
               log("ManagerServlet.remove[" + displayPath + "]", t);
  +            writer.println(sm.getString("managerServlet.exception",
  +                                        t.toString()));
  +        }
  +
  +    }
  +
  +
  +    /**
  +     * Render a list of available global JNDI resources.
  +     *
  +     * @param type Fully qualified class name of the resource type of interest,
  +     *  or <code>null</code> to list resources of all types
  +     */
  +    protected void resources(PrintWriter writer, String type) {
  +
  +        if (debug >= 1) {
  +            if (type != null) {
  +                log("resources:  Listing resources of type " + type);
  +            } else {
  +                log("resources:  Listing resources of all types");
  +            }
  +        }
  +
  +        // Is the global JNDI resources context available?
  +        if (global == null) {
  +            writer.println(sm.getString("managerServlet.noGlobal"));
  +            return;
  +        }
  +
  +        // Enumerate the global JNDI resources of the requested type
  +        if (type != null) {
  +            writer.println(sm.getString("managerServlet.resourcesType",
  +                                        type));
  +        } else {
  +            writer.println(sm.getString("managerServlet.resourcesAll"));
  +        }
  +        try {
  +            NamingEnumeration items = global.list("");
  +            while (items.hasMore()) {
  +                NameClassPair item = (NameClassPair) items.next();
  +                if ((type != null) &&
  +                    (!type.equals(item.getClassName()))) {
  +                    continue;
  +                }
  +                writer.print(item.getName());
  +                writer.print(':');
  +                writer.print(item.getClassName());
  +                // Do we want a description if available?
  +                writer.println();
  +            }
  +        } catch (Throwable t) {
  +            log("ManagerServlet.resources[" + type + "]", t);
               writer.println(sm.getString("managerServlet.exception",
                                           t.toString()));
           }
  
  
  
  1.11      +63 -8     jakarta-tomcat-4.0/webapps/tomcat-docs/manager-howto.xml
  
  Index: manager-howto.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/tomcat-docs/manager-howto.xml,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- manager-howto.xml	27 Feb 2002 05:40:57 -0000	1.10
  +++ manager-howto.xml	12 Mar 2002 21:14:16 -0000	1.11
  @@ -36,6 +36,9 @@
   <li>Reload an existing web application, to reflect changes in the
       contents of <code>/WEB-INF/classes</code> or <code>/WEB-INF/lib</code>.
       </li>
  +<li>List the available global JNDI resources, for use in deployment
  +    tools that are preparing <code>&lt;ResourceLink&gt;</code> elements
  +    nested in a <code>&lt;Context&gt;</code> deployment description.</li>
   <li>Remove an installed web application.</li>
   <li>Start a stopped application (thus making it available again).</li>
   <li>Stop an existing application (so that it becomes unavailable), but
  @@ -434,6 +437,57 @@
   
   </subsection>
   
  +<subsection name="List Available Global JNDI Resources">
  +
  +<source>
  +http://localhost:8080/manager/resources[?type=xxxxx]
  +</source>
  +
  +<p>List the global JNDI resources that are available for use in resource
  +links for context configuration files.  If you specify the <code>type</code>
  +request parameter, the value must be the fully qualified Java class name of
  +the resource type you are interested in (for example, you would specify
  +<code>javax.sql.DataSource</code> to acquire the names of all available
  +JDBC data sources).  If you do not specify the <code>type</code> request
  +parameter, resources of all types will be returned.</p>
  +
  +<p>Depending on whether the <code>type</code> request parameter is specfied
  +or not, the first line of a normal response will be:</p>
  +<pre>
  +  OK - Listed global resources of all types
  +</pre>
  +<p>or</p>
  +<pre>
  +  OK - Listed global resources of type xxxxx
  +</pre>
  +<p>followed by one line for each resource.  Each line is composed of fields
  +delimited by colon characters (":"), as follows:</p>
  +<ul>
  +<li><em>Global Resource Name</em> - The name of this global JNDI resource,
  +    which would be used in the <code>global</code> attribute of a
  +    <code>&lt;ResourceLink&gt;</code> element.</li>
  +<li><em>Global Resource Type</em> - The fully qualified Java class name of
  +    this global JNDI resource.</li>
  +</ul>
  +
  +<p>If an error occurs, the response will start with <code>FAIL</code> and
  +include an error message.  Possible causes for problems include:</p>
  +<ul>
  +<li><em>Encountered exception</em>
  +    <blockquote>
  +    <p>An exception was encountered trying to enumerate the global JNDI
  +    resources.  Check the Tomcat 4 logs for the details.</p>
  +    </blockquote></li>
  +<li><em>No global JNDI resources are available</em>
  +    <blockquote>
  +    <p>The Tomcat server you are running has been configured without
  +    global JNDI resources.</p>
  +    </blockquote></li>
  +</ul>
  +
  +
  +</subsection>
  +
   <subsection name="Session Statistics">
   
   <source>
  @@ -637,14 +691,15 @@
     &lt;property name="password" value="mypassword"/&gt;
   
     &lt;-- Configure the custom Ant tasks for the Manager application --&gt;
  -  &lt;taskdef name="deploy"   classname="org.apache.catalina.ant.DeployTask"/&gt;
  -  &lt;taskdef name="install"  classname="org.apache.catalina.ant.InstallTask"/&gt;
  -  &lt;taskdef name="list"     classname="org.apache.catalina.ant.ListTask"/&gt;
  -  &lt;taskdef name="reload"   classname="org.apache.catalina.ant.ReloadTask"/&gt;
  -  &lt;taskdef name="remove"   classname="org.apache.catalina.ant.RemoveTask"/&gt;
  -  &lt;taskdef name="start"    classname="org.apache.catalina.ant.StartTask"/&gt;
  -  &lt;taskdef name="stop"     classname="org.apache.catalina.ant.StopTask"/&gt;
  -  &lt;taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask"/&gt;
  +  &lt;taskdef name="deploy"    classname="org.apache.catalina.ant.DeployTask"/&gt;
  +  &lt;taskdef name="install"   classname="org.apache.catalina.ant.InstallTask"/&gt;
  +  &lt;taskdef name="list"      classname="org.apache.catalina.ant.ListTask"/&gt;
  +  &lt;taskdef name="reload"    classname="org.apache.catalina.ant.ReloadTask"/&gt;
  +  &lt;taskdef name="remove"    classname="org.apache.catalina.ant.RemoveTask"/&gt;
  +  &lt;taskdef name="resources" classname="org.apache.catalina.ant.ResourcesTask"/&gt;
  +  &lt;taskdef name="start"     classname="org.apache.catalina.ant.StartTask"/&gt;
  +  &lt;taskdef name="stop"      classname="org.apache.catalina.ant.StopTask"/&gt;
  +  &lt;taskdef name="undeploy"  classname="org.apache.catalina.ant.UndeployTask"/&gt;
   
     &lt;-- Executable Targets --&gt;
     &lt;target name="compile" description="Compile web application"&gt;
  
  
  

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