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 2001/05/02 22:45:01 UTC

cvs commit: jakarta-tomcat-4.0/tester/web/WEB-INF web.xml

craigmcc    01/05/02 13:45:00

  Modified:    catalina/src/share/org/apache/catalina/core
                        ApplicationHttpRequest.java ApplicationRequest.java
               tester/src/bin tester.xml
               tester/web/WEB-INF web.xml
  Added:       tester/src/tester/org/apache/tester Include03.java
                        Include03a.java
  Log:
  Allow an "include"d servlet to set and remove request attributes, with those
  changes being made visible to the calling servlet.
  
  Add a unit test to catch any future regressions on this issue.
  
  Submitted by:	Ana <an...@yahoo.com>
  
  Revision  Changes    Path
  1.5       +38 -4     jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationHttpRequest.java
  
  Index: ApplicationHttpRequest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationHttpRequest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ApplicationHttpRequest.java	2001/04/25 21:39:20	1.4
  +++ ApplicationHttpRequest.java	2001/05/02 20:44:19	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationHttpRequest.java,v 1.4 2001/04/25 21:39:20 craigmcc Exp $
  - * $Revision: 1.4 $
  - * $Date: 2001/04/25 21:39:20 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationHttpRequest.java,v 1.5 2001/05/02 20:44:19 craigmcc Exp $
  + * $Revision: 1.5 $
  + * $Date: 2001/05/02 20:44:19 $
    *
    * ====================================================================
    *
  @@ -73,6 +73,7 @@
   import java.util.Map;
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletRequestWrapper;
  +import org.apache.catalina.Globals;
   import org.apache.catalina.HttpRequest;
   import org.apache.catalina.util.Enumerator;
   import org.apache.catalina.util.RequestUtil;
  @@ -92,12 +93,24 @@
    * keep these two classes in synchronization when making changes!
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.4 $ $Date: 2001/04/25 21:39:20 $
  + * @version $Revision: 1.5 $ $Date: 2001/05/02 20:44:19 $
    */
   
   class ApplicationHttpRequest extends HttpServletRequestWrapper {
   
   
  +    // ------------------------------------------------------- Static Variables
  +
  +
  +    /**
  +     * The set of attribute names that are special for request dispatchers.
  +     */
  +    protected static final String specials[] =
  +    { Globals.REQUEST_URI_ATTR, Globals.CONTEXT_PATH_ATTR,
  +      Globals.SERVLET_PATH_ATTR, Globals.PATH_INFO_ATTR,
  +      Globals.QUERY_STRING_ATTR };
  +
  +
       // ----------------------------------------------------------- Constructors
   
   
  @@ -214,6 +227,8 @@
   
   	synchronized (attributes) {
   	    attributes.remove(name);
  +            if (!isSpecial(name))
  +                getRequest().removeAttribute(name);
   	}
   
       }
  @@ -230,6 +245,8 @@
   
   	synchronized (attributes) {
   	    attributes.put(name, value);
  +            if (!isSpecial(name))
  +                getRequest().setAttribute(name, value);
   	}
   
       }
  @@ -577,6 +594,23 @@
   
   
       // ------------------------------------------------------ Protected Methods
  +
  +
  +    /**
  +     * Is this attribute name one of the special ones that is added only for
  +     * included servlets?
  +     *
  +     * @param name Attribute name to be tested
  +     */
  +    protected boolean isSpecial(String name) {
  +
  +        for (int i = 0; i < specials.length; i++) {
  +            if (specials[i].equals(name))
  +                return (true);
  +        }
  +        return (false);
  +
  +    }
   
   
       /**
  
  
  
  1.3       +41 -4     jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationRequest.java
  
  Index: ApplicationRequest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationRequest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ApplicationRequest.java	2000/10/16 22:44:17	1.2
  +++ ApplicationRequest.java	2001/05/02 20:44:24	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationRequest.java,v 1.2 2000/10/16 22:44:17 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/10/16 22:44:17 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationRequest.java,v 1.3 2001/05/02 20:44:24 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/05/02 20:44:24 $
    *
    * ====================================================================
    *
  @@ -70,6 +70,7 @@
   import java.util.HashMap;
   import javax.servlet.ServletRequest;
   import javax.servlet.ServletRequestWrapper;
  +import org.apache.catalina.Globals;
   import org.apache.catalina.Request;
   import org.apache.catalina.util.Enumerator;
   import org.apache.catalina.util.StringManager;
  @@ -88,12 +89,24 @@
    * keep these two classes in synchronization when making changes!
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2000/10/16 22:44:17 $
  + * @version $Revision: 1.3 $ $Date: 2001/05/02 20:44:24 $
    */
   
   class ApplicationRequest extends ServletRequestWrapper {
   
   
  +    // ------------------------------------------------------- Static Variables
  +
  +
  +    /**
  +     * The set of attribute names that are special for request dispatchers.
  +     */
  +    protected static final String specials[] =
  +    { Globals.REQUEST_URI_ATTR, Globals.CONTEXT_PATH_ATTR,
  +      Globals.SERVLET_PATH_ATTR, Globals.PATH_INFO_ATTR,
  +      Globals.QUERY_STRING_ATTR };
  +
  +
       // ----------------------------------------------------------- Constructors
   
   
  @@ -173,6 +186,8 @@
   
   	synchronized (attributes) {
   	    attributes.remove(name);
  +            if (!isSpecial(name))
  +                getRequest().removeAttribute(name);
   	}
   
       }
  @@ -189,6 +204,8 @@
   
   	synchronized (attributes) {
   	    attributes.put(name, value);
  +            if (!isSpecial(name))
  +                getRequest().setAttribute(name, value);
   	}
   
       }
  @@ -220,6 +237,26 @@
   		attributes.put(name, value);
   	    }
   	}
  +
  +    }
  +
  +
  +    // ------------------------------------------------------ Protected Methods
  +
  +
  +    /**
  +     * Is this attribute name one of the special ones that is added only for
  +     * included servlets?
  +     *
  +     * @param name Attribute name to be tested
  +     */
  +    protected boolean isSpecial(String name) {
  +
  +        for (int i = 0; i < specials.length; i++) {
  +            if (specials[i].equals(name))
  +                return (true);
  +        }
  +        return (false);
   
       }
   
  
  
  
  1.37      +10 -0     jakarta-tomcat-4.0/tester/src/bin/tester.xml
  
  Index: tester.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/tester/src/bin/tester.xml,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- tester.xml	2001/04/30 21:57:14	1.36
  +++ tester.xml	2001/05/02 20:44:39	1.37
  @@ -375,6 +375,16 @@
            request="${context.path}/WrappedInclude02?exception=NullPointerException"
         outContent="Include02 PASSED" debug="${debug}"/>
   
  +    <!-- ========== Included Servlet Sets Attribute ======================= -->
  +
  +    <tester host="${host}" port="${port}" protocol="${protocol}"
  +         request="${context.path}/Include03"
  +      outContent="Include03 PASSED" debug="${debug}"/>
  +
  +    <tester host="${host}" port="${port}" protocol="${protocol}"
  +         request="${context.path}/WrappedInclude03"
  +      outContent="Include03 PASSED" debug="${debug}"/>
  +
     </target>
   
   
  
  
  
  1.1                  jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Include03.java
  
  Index: Include03.java
  ===================================================================
  /* ========================================================================= *
   *                                                                           *
   *                 The Apache Software License,  Version 1.1                 *
   *                                                                           *
   *      Copyright (c) 1999, 2000, 2001  The Apache Software Foundation.      *
   *                           All rights reserved.                            *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * Redistribution and use in source and binary forms,  with or without modi- *
   * fication, are permitted provided that the following conditions are met:   *
   *                                                                           *
   * 1. Redistributions of source code  must retain the above copyright notice *
   *    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 <ap...@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 Software Foundation.                                            *
   *                                                                           *
   * 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 indivi- *
   * duals on behalf of the  Apache Software Foundation.  For more information *
   * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
   *                                                                           *
   * ========================================================================= */
  
  package org.apache.tester;
  
  
  import java.io.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  /**
   * Test to insure that an included servlet can set request attributes that are
   * visible to the calling servlet after the <code>include()</code> returns.
   * The spec is silent on this topic, but it seems consistent with the overall
   * intent to behave in this manner.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2001/05/02 20:44:48 $
   */
  
  public class Include03 extends HttpServlet {
  
      private static final String specials[] =
      { "javax.servlet.include.request_uri",
        "javax.servlet.include.context_path",
        "javax.servlet.include.servlet_path",
        "javax.servlet.include.path_info",
        "javax.servlet.include.query_string" };
  
  
      public void doGet(HttpServletRequest request, HttpServletResponse response)
          throws IOException, ServletException {
  
          // Prepare this response
          StringBuffer sb = new StringBuffer();
          response.setContentType("text/plain");
  	PrintWriter writer = response.getWriter();
  
          // Create a request dispatcher and call include() on it
          RequestDispatcher rd =
              getServletContext().getRequestDispatcher("/Include03a");
          if (rd == null) {
              sb.append(" No RequestDispatcher returned/");
          } else {
              rd.include(request, response);
          }
  
          // We MUST be able to see the attribute created by the includee
          String value = null;
          try {
              value = (String) request.getAttribute("Include03a");
          } catch (ClassCastException e) {
              sb.append(" Returned attribute not of type String/");
          }
          if ((sb.length() < 1) && (value == null)) {
              sb.append(" No includee-created attribute was returned/");
          }
  
          // We MUST NOT see the special attributes created by the container
          for (int i = 0; i < specials.length; i++) {
              if (request.getAttribute(specials[i]) != null) {
                  sb.append(" Returned attribute ");
                  sb.append(specials[i]);
                  sb.append("/");
              }
          }
  
          // Write our response
          if (sb.length() < 1)
              writer.println("Include03 PASSED");
          else {
              writer.print("Include03 FAILED -");
              writer.println(sb.toString());
          }
  
          while (true) {
              String message = StaticLogger.read();
              if (message == null)
                  break;
              writer.println(message);
          }
          StaticLogger.reset();
  
      }
  
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Include03a.java
  
  Index: Include03a.java
  ===================================================================
  /* ========================================================================= *
   *                                                                           *
   *                 The Apache Software License,  Version 1.1                 *
   *                                                                           *
   *      Copyright (c) 1999, 2000, 2001  The Apache Software Foundation.      *
   *                           All rights reserved.                            *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * Redistribution and use in source and binary forms,  with or without modi- *
   * fication, are permitted provided that the following conditions are met:   *
   *                                                                           *
   * 1. Redistributions of source code  must retain the above copyright notice *
   *    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 <ap...@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 Software Foundation.                                            *
   *                                                                           *
   * 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 indivi- *
   * duals on behalf of the  Apache Software Foundation.  For more information *
   * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
   *                                                                           *
   * ========================================================================= */
  
  package org.apache.tester;
  
  
  import java.io.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  /**
   * Test to insure that an included servlet can set request attributes that are
   * visible to the calling servlet after the <code>include()</code> returns.
   * The spec is silent on this topic, but it seems consistent with the overall
   * intent to behave in this manner.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2001/05/02 20:44:49 $
   */
  
  public class Include03a extends HttpServlet {
  
  
      public void doGet(HttpServletRequest request, HttpServletResponse response)
          throws IOException, ServletException {
  
          request.setAttribute("Include03a", "This is a new attribute");
  
      }
  
  }
  
  
  
  1.27      +35 -0     jakarta-tomcat-4.0/tester/web/WEB-INF/web.xml
  
  Index: web.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/tester/web/WEB-INF/web.xml,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- web.xml	2001/04/30 21:57:16	1.26
  +++ web.xml	2001/05/02 20:44:54	1.27
  @@ -149,6 +149,11 @@
   
       <filter-mapping>
           <filter-name>HttpFilter</filter-name>
  +        <url-pattern>/WrappedInclude03</url-pattern>
  +    </filter-mapping>
  +
  +    <filter-mapping>
  +        <filter-name>HttpFilter</filter-name>
           <url-pattern>/WrappedJndi01</url-pattern>
       </filter-mapping>
   
  @@ -383,6 +388,16 @@
       </servlet>
   
       <servlet>
  +        <servlet-name>Include03</servlet-name>
  +        <servlet-class>org.apache.tester.Include03</servlet-class>
  +    </servlet>
  +
  +    <servlet>
  +        <servlet-name>Include03a</servlet-name>
  +        <servlet-class>org.apache.tester.Include03a</servlet-class>
  +    </servlet>
  +
  +    <servlet>
           <servlet-name>Jndi01</servlet-name>
           <servlet-class>org.apache.tester.Jndi01</servlet-class>
           <load-on-startup>1</load-on-startup>
  @@ -704,6 +719,26 @@
       <servlet-mapping>
           <servlet-name>Include02a</servlet-name>
           <url-pattern>/WrappedInclude02a</url-pattern>
  +    </servlet-mapping>
  +
  +    <servlet-mapping>
  +        <servlet-name>Include03</servlet-name>
  +        <url-pattern>/Include03</url-pattern>
  +    </servlet-mapping>
  +
  +    <servlet-mapping>
  +        <servlet-name>Include03</servlet-name>
  +        <url-pattern>/WrappedInclude03</url-pattern>
  +    </servlet-mapping>
  +
  +    <servlet-mapping>
  +        <servlet-name>Include03a</servlet-name>
  +        <url-pattern>/Include03a</url-pattern>
  +    </servlet-mapping>
  +
  +    <servlet-mapping>
  +        <servlet-name>Include03a</servlet-name>
  +        <url-pattern>/WrappedInclude03a</url-pattern>
       </servlet-mapping>
   
       <servlet-mapping>