craigmcc    01/05/13 17:02:33

  Modified:    catalina/src/share/org/apache/catalina/core
                        StandardWrapper.java
               catalina/src/share/org/apache/catalina/servlets
                        InvokerServlet.java LocalStrings.properties
                        ManagerServlet.java
  Added:       catalina/src/share/org/apache/catalina ContainerServlet.java
  Log:
  Introduce the concept of a ContainerServlet, which require access to
  Catalina internal implementation objects to perform their functions.  Such
  servlets must be:
  - In a subpackage of "org.apache.catalina"
  - Loaded by the Catalina class loader (rather than the web app class
    loader)
  
  Modify the only two servlets that require this functionality
  (InvokerServlet and ManagerServlet) to gain access to Catalina internals
  via the wrapper that is assigned by the container, rather than by casting
  the servlet API objects that are passed.  This allows these servlets to be
  oblivious to the introduction of facades around the servlet API objects.
  
  Revision  Changes    Path
  1.1                  
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/ContainerServlet.java
  
  Index: ContainerServlet.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/ContainerServlet.java,v
 1.1 2001/05/14 00:02:32 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2001/05/14 00:02:32 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 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;
  
  
  /**
   * A <b>ContainerServlet</b> is a servlet that has access to Catalina
   * internal functionality, and is loaded from the Catalina class loader
   * instead of the web application class loader.  The property setter
   * methods must be called by the container whenever a new instance of
   * this servlet is put into service.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2001/05/14 00:02:32 $
   */
  
  public interface ContainerServlet {
  
  
      // ------------------------------------------------------------- Properties
  
  
      /**
       * Return the Wrapper with which this Servlet is associated.
       */
      public Wrapper getWrapper();
  
  
      /**
       * Set the Wrapper with which this Servlet is associated.
       *
       * @param wrapper The new associated Wrapper
       */
      public void setWrapper(Wrapper wrapper);
  
  
  }
  
  
  
  1.22      +12 -4     
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapper.java
  
  Index: StandardWrapper.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapper.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- StandardWrapper.java      2001/05/09 23:54:13     1.21
  +++ StandardWrapper.java      2001/05/14 00:02:32     1.22
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapper.java,v
 1.21 2001/05/09 23:54:13 craigmcc Exp $
  - * $Revision: 1.21 $
  - * $Date: 2001/05/09 23:54:13 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapper.java,v
 1.22 2001/05/14 00:02:32 craigmcc Exp $
  + * $Revision: 1.22 $
  + * $Date: 2001/05/14 00:02:32 $
    *
    * ====================================================================
    *
  @@ -78,6 +78,7 @@
   import javax.servlet.UnavailableException;
   import javax.servlet.http.HttpServletResponse;
   import org.apache.catalina.Container;
  +import org.apache.catalina.ContainerServlet;
   import org.apache.catalina.Context;
   import org.apache.catalina.InstanceEvent;
   import org.apache.catalina.InstanceListener;
  @@ -104,7 +105,7 @@
    * make them efficient are counter-productive.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.21 $ $Date: 2001/05/09 23:54:13 $
  + * @version $Revision: 1.22 $ $Date: 2001/05/14 00:02:32 $
    */
   
   public final class StandardWrapper
  @@ -809,6 +810,13 @@
            throw new ServletException
                (sm.getString("standardWrapper.instantiate", actualClass), e);
        }
  +
  +        // Special handling for ContainerServlet instances
  +        if ((servlet instanceof ContainerServlet) &&
  +            isContainerServlet(actualClass)) {
  +            ((ContainerServlet) servlet).setWrapper(this);
  +        }
  +
   
        // Call the initialization method of this servlet
        try {
  
  
  
  1.4       +47 -12    
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/InvokerServlet.java
  
  Index: InvokerServlet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/InvokerServlet.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- InvokerServlet.java       2000/11/10 01:19:17     1.3
  +++ InvokerServlet.java       2001/05/14 00:02:32     1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/InvokerServlet.java,v
 1.3 2000/11/10 01:19:17 craigmcc Exp $
  - * $Revision: 1.3 $
  - * $Date: 2000/11/10 01:19:17 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/InvokerServlet.java,v
 1.4 2001/05/14 00:02:32 craigmcc Exp $
  + * $Revision: 1.4 $
  + * $Date: 2001/05/14 00:02:32 $
    *
    * ====================================================================
    *
  @@ -69,13 +69,13 @@
   import javax.servlet.RequestDispatcher;
   import javax.servlet.Servlet;
   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.ContainerServlet;
   import org.apache.catalina.Context;
   import org.apache.catalina.Globals;
  -import org.apache.catalina.HttpRequest;
  -import org.apache.catalina.HttpResponse;
   import org.apache.catalina.Wrapper;
   import org.apache.catalina.util.StringManager;
   
  @@ -86,11 +86,11 @@
    * in the web application deployment descriptor.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.3 $ $Date: 2000/11/10 01:19:17 $
  + * @version $Revision: 1.4 $ $Date: 2001/05/14 00:02:32 $
    */
   
   public final class InvokerServlet
  -    extends HttpServlet {
  +    extends HttpServlet implements ContainerServlet {
   
   
       // ----------------------------------------------------- Instance Variables
  @@ -115,6 +115,41 @@
           StringManager.getManager(Constants.Package);
   
   
  +    /**
  +     * The Wrapper container associated with this servlet.
  +     */
  +    private Wrapper wrapper = null;
  +
  +
  +    // ----------------------------------------------- ContainerServlet Methods
  +
  +
  +    /**
  +     * Return the Wrapper with which we are associated.
  +     */
  +    public Wrapper getWrapper() {
  +
  +        return (this.wrapper);
  +
  +    }
  +
  +
  +    /**
  +     * Set the Wrapper with which we are associated.
  +     *
  +     * @param wrapper The new wrapper
  +     */
  +    public void setWrapper(Wrapper wrapper) {
  +
  +        this.wrapper = wrapper;
  +        if (wrapper == null)
  +            context = null;
  +        else
  +            context = (Context) wrapper.getParent();
  +
  +    }
  +
  +
       // --------------------------------------------------------- Public Methods
   
   
  @@ -187,6 +222,11 @@
        */
       public void init() throws ServletException {
   
  +        // Ensure that our ContainerServlet properties have been set
  +        if ((wrapper == null) || (context == null))
  +            throw new UnavailableException
  +                (sm.getString("invokerServlet.noWrapper"));
  +
        // Set our properties from the initialization parameters
        String value = null;
        try {
  @@ -195,11 +235,6 @@
        } catch (Throwable t) {
            ;
        }
  -
  -     // Identify the internal container resources we need
  -     Wrapper wrapper = (Wrapper) getServletConfig();
  -     context = (Context) wrapper.getParent();
  -
        if (debug >= 1)
            log("init: Associated with Context '" + context.getPath() + "'");
   
  
  
  
  1.7       +2 -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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- LocalStrings.properties   2001/03/31 14:20:01     1.6
  +++ LocalStrings.properties   2001/05/14 00:02:32     1.7
  @@ -5,6 +5,7 @@
   invokerServlet.cannotCreate=Cannot create servlet wrapper for path {0}
   invokerServlet.invalidPath=No servlet name or class was specified in path {0}
   invokerServlet.notNamed=Cannot call invoker servlet with a named dispatcher
  +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.exception=FAIL - Encountered exception {0}
  @@ -17,6 +18,7 @@
   managerServlet.noContext=FAIL - No context exists for path {0}
   managerServlet.noPath=FAIL - No context path was specified
   managerServlet.noRole=FAIL - User does not possess role {0}
  +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.sessiondefaultmax=Default maximum session inactive interval {0} 
minutes
  
  
  
  1.5       +49 -11    
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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ManagerServlet.java       2001/03/26 03:23:35     1.4
  +++ ManagerServlet.java       2001/05/14 00:02:32     1.5
  @@ -1,7 +1,7 @@
   /*
  - * $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 $
  + * $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 $
    *
    * ====================================================================
    *
  @@ -74,10 +74,9 @@
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
   import org.apache.catalina.Container;
  +import org.apache.catalina.ContainerServlet;
   import org.apache.catalina.Context;
   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;
  @@ -153,11 +152,11 @@
    * </ul>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.4 $ $Date: 2001/03/26 03:23:35 $
  + * @version $Revision: 1.5 $ $Date: 2001/05/14 00:02:32 $
    */
   
   public final class ManagerServlet
  -    extends HttpServlet {
  +    extends HttpServlet implements ContainerServlet {
   
   
       // ----------------------------------------------------- Instance Variables
  @@ -190,6 +189,44 @@
         StringManager.getManager(Constants.Package);
   
   
  +    /**
  +     * The Wrapper container associated with this servlet.
  +     */
  +    private Wrapper wrapper = null;
  +
  +
  +    // ----------------------------------------------- ContainerServlet Methods
  +
  +
  +    /**
  +     * Return the Wrapper with which we are associated.
  +     */
  +    public Wrapper getWrapper() {
  +
  +        return (this.wrapper);
  +
  +    }
  +
  +
  +    /**
  +     * Set the Wrapper with which we are associated.
  +     *
  +     * @param wrapper The new wrapper
  +     */
  +    public void setWrapper(Wrapper wrapper) {
  +
  +        this.wrapper = wrapper;
  +        if (wrapper == null) {
  +            context = null;
  +            deployer = null;
  +        } else {
  +            context = (Context) wrapper.getParent();
  +            deployer = (Deployer) context.getParent();
  +        }
  +
  +    }
  +
  +
       // --------------------------------------------------------- Public Methods
   
   
  @@ -261,6 +298,11 @@
        */
       public void init() throws ServletException {
   
  +        // Ensure that our ContainerServlet properties have been set
  +        if ((wrapper == null) || (context == null))
  +            throw new UnavailableException
  +                (sm.getString("managerServlet.noWrapper"));
  +
           // Verify that we were not accessed using the invoker servlet
           String servletName = getServletConfig().getServletName();
           if (servletName == null)
  @@ -278,10 +320,6 @@
            ;
        }
   
  -     // Identify the internal container resources we need
  -     Wrapper wrapper = (Wrapper) getServletConfig();
  -     context = (Context) wrapper.getParent();
  -     deployer = (Deployer) context.getParent();
   
        // Log debugging messages as necessary
        if (debug >= 1) {
  
  
  

Reply via email to