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...@locus.apache.org on 2000/01/30 07:56:21 UTC

cvs commit: jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core StandardWrapper.java StandardWrapperValve.java LocalStrings.properties

craigmcc    00/01/29 22:56:20

  Modified:    proposals/catalina/src/share/org/apache/tomcat Wrapper.java
               proposals/catalina/src/share/org/apache/tomcat/core
                        LocalStrings.properties
  Added:       proposals/catalina/src/share/org/apache/tomcat/core
                        StandardWrapper.java StandardWrapperValve.java
  Log:
  Initial check-in of the standard Wrapper implementation, with the major
  functional methods still needing to be fleshed out.  The Wrapper interface
  itself was modified to include property setting methods corresponding to
  the <servlet> element in the web application deployment descriptor.
  
  NOTE:  One implication of the new "configure from the outside" philosophy
  is that a core component (like StandardWrapper) should not rely on the
  existence of any of the "deployment" objects that are currently created
  when reading the web.xml file.  Instead, the corresponding raw properties
  need to be provided.  For the Wrapper implementation, this is a fairly
  short list.  For the Context implementation, this means some surgery is
  necessary to replace getDescriptor/setDescriptor with the corresponding
  values (only those that affect execution) as properties.
  
  Revision  Changes    Path
  1.3       +84 -17    jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Wrapper.java
  
  Index: Wrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Wrapper.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Wrapper.java	2000/01/29 03:47:28	1.2
  +++ Wrapper.java	2000/01/30 06:56:20	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Wrapper.java,v 1.2 2000/01/29 03:47:28 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/01/29 03:47:28 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Wrapper.java,v 1.3 2000/01/30 06:56:20 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2000/01/30 06:56:20 $
    *
    * ====================================================================
    *
  @@ -89,7 +89,7 @@
    * <code>IllegalArgumentException</code>.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2000/01/29 03:47:28 $
  + * @version $Revision: 1.3 $ $Date: 2000/01/30 06:56:20 $
    */
   
   public interface Wrapper extends Container {
  @@ -98,10 +98,64 @@
       // ------------------------------------------------------------- Properties
   
   
  +    /**
  +     * Return the context-relative URI of the JSP file for this servlet.
  +     */
  +    public String getJspFile();
  +
  +
  +    /**
  +     * Set the context-relative URI of the JSP file for this servlet.
  +     *
  +     * @param jspFile JSP file URI
  +     */
  +    public void setJspFile(String jspFile);
  +
  +
  +    /**
  +     * Return the load-on-startup order value (negative value means
  +     * load on first call).
  +     */
  +    public int getLoadOnStartup();
  +
  +
  +    /**
  +     * Set the load-on-startup order value (negative value means
  +     * load on first call).
  +     *
  +     * @param value New load-on-startup value
  +     */
  +    public void setLoadOnStartup(int value);
  +
  +
  +    /**
  +     * Return the fully qualified servlet class name for this servlet.
  +     */
  +    public String getServletClass();
  +
  +
  +    /**
  +     * Set the fully qualified servlet class name for this servlet.
  +     *
  +     * @param servletClass Servlet class name
  +     */
  +    public void setServletClass(String servletClass);
  +
  +
  +
       // --------------------------------------------------------- Public Methods
   
   
       /**
  +     * Add a new servlet initialization parameter for this servlet.
  +     *
  +     * @param name Name of this initialization parameter to add
  +     * @param value Value of this initialization parameter to add
  +     */
  +    public void addInitParameter(String name, String value);
  +
  +
  +    /**
        * Add a new security role reference record to the set of records for
        * this servlet.
        *
  @@ -109,8 +163,7 @@
        * @param link Role name used within the web application
        * @param description Description of this security role reference
        */
  -    public void addSecurityRole(String name, String link,
  -				String description);
  +    public void addSecurityReference(String name, String link);
   
   
       /**
  @@ -138,29 +191,35 @@
   
   
       /**
  -     * Return the security role reference description associated with the
  -     * specified role name, if any; otherwise return <code>null</code>.
  +     * Return the value for the specified initialization parameter name,
  +     * if any; otherwise return <code>null</code>.
        *
  -     * @param name Security role used within this servlet
  +     * @param name Name of the requested initialization parameter
  +     */
  +    public String findInitParameter(String name);
  +
  +
  +    /**
  +     * Return the names of all defined initialization parameters for this
  +     * servlet.
        */
  -    public String findSecurityDescription(String name);
  +    public String[] findInitParameterNames();
   
   
       /**
  -     * Return the security role link associated with the specified role name,
  -     * if any.  If no mapping has been defined, the role name itself is
  -     * returned.
  +     * Return the security role link for the specified security role
  +     * reference name, if any; otherwise return <code>null</code>.
        *
  -     * @param name Security role used within this servlet
  +     * @param name Security role reference used within this servlet
        */
  -    public String findSecurityLink(String name);
  +    public String findSecurityReference(String name);
   
   
       /**
        * Return the set of security role reference names associated with
        * this servlet, if any; otherwise return a zero-length array.
        */
  -    public String[] findSecurityNames();
  +    public String[] findSecurityReferenceNames();
   
   
       /**
  @@ -176,11 +235,19 @@
   
   
       /**
  +     * Remove the specified initialization parameter from this servlet.
  +     *
  +     * @param name Name of the initialization parameter to remove
  +     */
  +    public void removeInitParameter(String name);
  +
  +
  +    /**
        * Remove any security role reference for the specified role name.
        *
        * @param name Security role used within this servlet to be removed
        */
  -    public void removeSecurityRole(String name);
  +    public void removeSecurityReference(String name);
   
   
       /**
  
  
  
  1.4       +1 -1      jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/LocalStrings.properties
  
  Index: LocalStrings.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/LocalStrings.properties,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LocalStrings.properties	2000/01/29 03:47:29	1.3
  +++ LocalStrings.properties	2000/01/30 06:56:20	1.4
  @@ -20,4 +20,4 @@
   standardHost.unfoundContext=Cannot find context for request URI $0
   standardResources.malformedPath=Path must start with '/'
   standardResources.malformedURL=Malformed URL
  -
  +standardWrapper.noChild=Wrapper cannot have a child Container
  
  
  
  1.1                  jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardWrapper.java
  
  Index: StandardWrapper.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardWrapper.java,v 1.1 2000/01/30 06:56:20 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/01/30 06:56:20 $
   *
   * ====================================================================
   *
   * 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 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/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  
  package org.apache.tomcat.core;
  
  
  import java.io.IOException;
  import java.util.Enumeration;
  import java.util.Hashtable;
  import java.util.Vector;
  import javax.servlet.Servlet;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletResponse;
  import org.apache.tomcat.Container;
  import org.apache.tomcat.Context;
  import org.apache.tomcat.Request;
  import org.apache.tomcat.Response;
  import org.apache.tomcat.Wrapper;
  
  
  /**
   * Standard implementation of the <b>Wrapper</b> interface that represents
   * an individual servlet definition.  No child Containers are allowed, and
   * the parent Container must be a Context.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/01/30 06:56:20 $
   */
  
  public final class StandardWrapper
      extends ContainerBase
      implements Wrapper {
  
  
      // ----------------------------------------------------------- Constructors
  
  
      /**
       * Create a new StandardWrapper component with the default basic Valve.
       */
      public StandardWrapper() {
  
  	super();
  	setBasic(new StandardWrapperValve());
  
      }
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * The descriptive information string for this implementation.
       */
      private static final String info =
  	"org.apache.tomcat.core.StandardWrapper/1.0";
  
  
      /**
       * The context-relative URI of the JSP file for this servlet.
       */
      private String jspFile = null;
  
  
      /**
       * The load-on-startup order value (negative value means load on
       * first call) for this servlet.
       */
      private int loadOnStartup = -1;
  
  
      /**
       * The initialization parameters for this servlet, keyed by
       * parameter name.
       */
      private Hashtable parameters = new Hashtable();
  
  
      /**
       * The security role references for this servlet, keyed by role name
       * used in the servlet.  The corresponding value is the role name of
       * the web application itself.
       */
      private Hashtable references = new Hashtable();
  
  
      /**
       * The fully qualified servlet class name for this servlet.
       */
      private String servletClass = null;
  
  
      // ------------------------------------------------------------- Properties
  
  
      /**
       * Return descriptive information about this Container implementation and
       * the corresponding version number, in the format
       * <code>&lt;description&gt;/&lt;version&gt;</code>.
       */
      public String getInfo() {
  
  	return (info);
  
      }
  
  
      /**
       * Return the context-relative URI of the JSP file for this servlet.
       */
      public String getJspFile() {
  
  	return (this.jspFile);
  
      }
  
  
      /**
       * Set the context-relative URI of the JSP file for this servlet.
       *
       * @param jspFile JSP file URI
       */
      public void setJspFile(String jspFile) {
  
  	String oldJspFile = this.jspFile;
  	this.jspFile = jspFile;
  	support.firePropertyChange("jspFile", oldJspFile, this.jspFile);
  
      }
  
  
      /**
       * Return the load-on-startup order value (negative value means
       * load on first call).
       */
      public int getLoadOnStartup() {
  
  	return (this.loadOnStartup);
  
      }
  
  
      /**
       * Set the load-on-startup order value (negative value means
       * load on first call).
       *
       * @param value New load-on-startup value
       */
      public void setLoadOnStartup(int value) {
  
  	int oldLoadOnStartup = this.loadOnStartup;
  	this.loadOnStartup = value;
  	support.firePropertyChange("loadOnStartup",
  				   new Integer(oldLoadOnStartup),
  				   new Integer(this.loadOnStartup));
  
      }
  
  
  
      /**
       * Set the parent Container of this Wrapper, but only if it is a Context.
       *
       * @param container Proposed parent Container
       */
      public void setParent(Container container) {
  
  	if (!(container instanceof Context))
  	    throw new IllegalArgumentException
  		(sm.getString("standardWrapper.notContext"));
  	super.setParent(container);
  
      }
  
  
      /**
       * Return the fully qualified servlet class name for this servlet.
       */
      public String getServletClass() {
  
  	return (this.servletClass);
  
      }
  
  
      /**
       * Set the fully qualified servlet class name for this servlet.
       *
       * @param servletClass Servlet class name
       */
      public void setServletClass(String servletClass) {
  
  	String oldServletClass = this.servletClass;
  	this.servletClass = servletClass;
  	support.firePropertyChange("servletClass", oldServletClass,
  				   this.servletClass);
  
      }
  
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Refuse to add a child Container, because Wrappers are the lowest level
       * of the Container hierarchy.
       *
       * @param child Child container to be added
       */
      public void addChild(Container child) {
  
  	throw new IllegalStateException
  	    (sm.getString("standardWrapper.noChild"));
  
      }
  
  
      /**
       * Add a new servlet initialization parameter for this servlet.
       *
       * @param name Name of this initialization parameter to add
       * @param value Value of this initialization parameter to add
       */
      public void addInitParameter(String name, String value) {
  
  	parameters.put(name, value);
  	fireContainerEvent("addInitParameter", name);
  
      }
  
  
      /**
       * Add a new security role reference record to the set of records for
       * this servlet.
       *
       * @param name Role name used within this servlet
       * @param link Role name used within the web application
       */
      public void addSecurityReference(String name, String link) {
  
  	references.put(name, link);
  	fireContainerEvent("addSecurityReference", name);
  
      }
  
  
  
      /**
       * Allocate an initialized instance of this Servlet that is ready to have
       * its <code>service()</code> method called.  If the servlet class does
       * not implement <code>SingleThreadModel</code>, the (only) initialized
       * instance may be returned immediately.  If the servlet class implements
       * <code>SingleThreadModel</code>, the Wrapper implementation must ensure
       * that this instance is not allocated again until it is deallocated by a
       * call to <code>deallocate()</code>.
       * <p>
       * <b>FIXME:  Provide a way to avoid waiting forever.</b>
       */
      public Servlet allocate() {
  
  	return (null);	// FIXME - allocate()
  
      }
  
  
      /**
       * Return this previously allocated servlet to the pool of available
       * instances.  If this servlet class does not implement SingleThreadModel,
       * no action is actually required.
       *
       * @param servlet The servlet to be returned
       */
      public void deallocate(Servlet servlet) {
  
  	;	// FIXME - deallocate()
  
      }
  
  
      /**
       * Return the value for the specified initialization parameter name,
       * if any; otherwise return <code>null</code>.
       *
       * @param name Name of the requested initialization parameter
       */
      public String findInitParameter(String name) {
  
  	return ((String) parameters.get(name));
  
      }
  
  
      /**
       * Return the names of all defined initialization parameters for this
       * servlet.
       */
      public String[] findInitParameterNames() {
  
  	synchronized (parameters) {
  	    String results[] = new String[parameters.size()];
  	    int n = 0;
  	    Enumeration names = parameters.keys();
  	    while (names.hasMoreElements()) {
  		results[n++] = (String) names.nextElement();
  	    }
  	    return (results);
  	}
  
      }
  
  
      /**
       * Return the security role link for the specified security role
       * reference name, if any; otherwise return <code>null</code>.
       *
       * @param name Security role reference used within this servlet
       */
      public String findSecurityReference(String name) {
  
  	return ((String) references.get(name));
  
      }
  
  
      /**
       * Return the set of security role reference names associated with
       * this servlet, if any; otherwise return a zero-length array.
       */
      public String[] findSecurityReferenceNames() {
  
  	synchronized (references) {
  	    String results[] = new String[references.size()];
  	    int n = 0;
  	    Enumeration names = references.keys();
  	    while (names.hasMoreElements()) {
  		results[n++] = (String) names.nextElement();
  	    }
  	    return (results);
  	}
  
      }
  
  
      /**
       * Load and initialize an instance of this servlet, if there is not already
       * at least one initialized instance.  This can be used, for example, to
       * load servlets that are marked in the deployment descriptor to be loaded
       * at server startup time.
       *
       * @exception ServletException if thrown by the init() method of the
       *  loaded servlet
       */
      public void load() throws ServletException {
  
  	;	// FIXME - load()
  
      }
  
  
      /**
       * Remove the specified initialization parameter from this servlet.
       *
       * @param name Name of the initialization parameter to remove
       */
      public void removeInitParameter(String name) {
  
  	if (parameters.get(name) != null) {
  	    parameters.remove(name);
  	    fireContainerEvent("removeInitParameter", name);
  	}
  
      }
  
  
      /**
       * Remove any security role reference for the specified role name.
       *
       * @param name Security role used within this servlet to be removed
       */
      public void removeSecurityReference(String name) {
  
  	if (references.get(name) != null) {
  	    references.remove(name);
  	    fireContainerEvent("removeSecurityReference", name);
  	}
  
      }
  
  
      /**
       * Unload all initialized instances of this servlet, after calling the
       * <code>destroy()</code> method for each instance.  This can be used,
       * for example, prior to shutting down the entire servlet engine, or
       * prior to reloading all of the classes from the Loader associated with
       * our Loader's repository.
       */
      public void unload() {
  
  	;	// FIXME - unload()
  
      }
  
  
      // -------------------------------------------------------- Private Methods
  
  
  }
  
  
  
  1.1                  jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardWrapperValve.java
  
  Index: StandardWrapperValve.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/StandardWrapperValve.java,v 1.1 2000/01/30 06:56:20 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/01/30 06:56:20 $
   *
   * ====================================================================
   *
   * 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 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/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  
  package org.apache.tomcat.core;
  
  
  import java.io.IOException;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletResponse;
  import org.apache.tomcat.Container;
  import org.apache.tomcat.Request;
  import org.apache.tomcat.Response;
  import org.apache.tomcat.Wrapper;
  import org.apache.tomcat.util.StringManager;
  
  
  /**
   * Valve that implements the default basic behavior for the
   * <code>StandardWrapper</code> container implementation.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/01/30 06:56:20 $
   */
  
  final class StandardWrapperValve
      extends ValveBase {
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * The string manager for this package.
       */
      private StringManager sm =
  	StringManager.getManager(Constants.Package);
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Select the appropriate child Wrapper to process this request,
       * based on the specified request URI.  If no matching Wrapper can
       * be found, return an appropriate HTTP error.
       *
       * @param request Request to be processed
       * @param response Response to be produced
       *
       * @exception IOException if an input/output error occurred
       * @exception ServletException if a servlet error occurred
       */
      public void invoke(Request request, Response response)
  	throws IOException, ServletException {
  
  	;	// FIXME - invoke()
  	// FIXME - request.setWrapper()?  to find role links etc.
  
      }
  
  
  }