tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@apache.org
Subject cvs commit: jakarta-tomcat-4.0/tester/web/WEB-INF web.xml
Date Thu, 03 May 2001 18:41:48 GMT
craigmcc    01/05/03 11:41:48

  Modified:    tester/src/bin tester.xml
               tester/src/tester/org/apache/tester Include03.java
               tester/web/WEB-INF web.xml
  Added:       tester/src/tester/org/apache/tester Forward03.java
                        Forward03a.java
               tester/web Forward03b.jsp Include03b.jsp
  Log:
  Add additional tests for setting request attributes in forwarded-to as well
  as included servlets.
  
  Revision  Changes    Path
  1.38      +29 -3     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.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- tester.xml	2001/05/02 20:44:39	1.37
  +++ tester.xml	2001/05/03 18:41:30	1.38
  @@ -375,14 +375,40 @@
            request="${context.path}/WrappedInclude02?exception=NullPointerException"
         outContent="Include02 PASSED" debug="${debug}"/>
   
  -    <!-- ========== Included Servlet Sets Attribute ======================= -->
  +    <!-- ========== Forwarded Servlet/Page Sets Attribute ================ -->
   
       <tester host="${host}" port="${port}" protocol="${protocol}"
  -         request="${context.path}/Include03"
  +         request="${context.path}/Forward03?path=/Forward03a"
  +      outContent="Forward03 PASSED" debug="${debug}"/>
  +
  +    <tester host="${host}" port="${port}" protocol="${protocol}"
  +         request="${context.path}/WrappedForward03?path=/Forward03a"
  +      outContent="Forward03 PASSED" debug="${debug}"/>
  +
  +    <tester host="${host}" port="${port}" protocol="${protocol}"
  +         request="${context.path}/Forward03?path=/Forward03b.jsp"
  +      outContent="Forward03 PASSED" debug="${debug}"/>
  +
  +    <tester host="${host}" port="${port}" protocol="${protocol}"
  +         request="${context.path}/WrappedForward03?path=/Forward03b.jsp"
  +      outContent="Forward03 PASSED" debug="${debug}"/>
  +
  +    <!-- ========== Included Servlet/Page Sets Attribute ================= -->
  +
  +    <tester host="${host}" port="${port}" protocol="${protocol}"
  +         request="${context.path}/Include03?path=/Include03a"
  +      outContent="Include03 PASSED" debug="${debug}"/>
  +
  +    <tester host="${host}" port="${port}" protocol="${protocol}"
  +         request="${context.path}/WrappedInclude03?path=/Include03a"
  +      outContent="Include03 PASSED" debug="${debug}"/>
  +
  +    <tester host="${host}" port="${port}" protocol="${protocol}"
  +         request="${context.path}/Include03?path=/Include03b.jsp"
         outContent="Include03 PASSED" debug="${debug}"/>
   
       <tester host="${host}" port="${port}" protocol="${protocol}"
  -         request="${context.path}/WrappedInclude03"
  +         request="${context.path}/WrappedInclude03?path=/Include03b.jsp"
         outContent="Include03 PASSED" debug="${debug}"/>
   
     </target>
  
  
  
  1.2       +14 -3     jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Include03.java
  
  Index: Include03.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Include03.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Include03.java	2001/05/02 20:44:48	1.1
  +++ Include03.java	2001/05/03 18:41:37	1.2
  @@ -68,8 +68,12 @@
    * The spec is silent on this topic, but it seems consistent with the overall
    * intent to behave in this manner.
    *
  + * The test includes either a servlet ("/Include03a") or a JSP page
  + * ("/Include03b.jsp") depending on the value specified for the "path"
  + * parameter.  The default is the servlet.
  + *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2001/05/02 20:44:48 $
  + * @version $Revision: 1.2 $ $Date: 2001/05/03 18:41:37 $
    */
   
   public class Include03 extends HttpServlet {
  @@ -90,19 +94,26 @@
           response.setContentType("text/plain");
   	PrintWriter writer = response.getWriter();
   
  +        // Acquire the path to which we will issue an include
  +        String path = request.getParameter("path");
  +        if (path == null)
  +            path = "/Include03a";
  +
           // Create a request dispatcher and call include() on it
           RequestDispatcher rd =
  -            getServletContext().getRequestDispatcher("/Include03a");
  +            getServletContext().getRequestDispatcher(path);
           if (rd == null) {
               sb.append(" No RequestDispatcher returned/");
           } else {
               rd.include(request, response);
           }
  +        response.resetBuffer();
   
           // We MUST be able to see the attribute created by the includee
           String value = null;
           try {
  -            value = (String) request.getAttribute("Include03a");
  +            value = (String)
  +                request.getAttribute(path.substring(1));
           } catch (ClassCastException e) {
               sb.append(" Returned attribute not of type String/");
           }
  
  
  
  1.1                  jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Forward03.java
  
  Index: Forward03.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 <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 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 ensure that a forwarded-to servlet can receive request attributes
   * set by the calling servlet, as well as set their own request attributes.
   *
   * The test forwards to either a servlet ("/Forward03a") or a JSP page
   * ("/Forward03b.jsp") depending on the value specified for the "path"
   * parameter.  The default is the servlet.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2001/05/03 18:41:36 $
   */
  
  public class Forward03 extends HttpServlet {
  
  
      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();
  
          // Acquire the path to which we will issue a forward
          String path = request.getParameter("path");
          if (path == null)
              path = "/Forward03a";
  
          // Write the request attribute we will be forwarding
          request.setAttribute("Forward03", "This is the forwarded attribute");
          if (request.getAttribute("Forward03") == null)
              sb.append(" Cannot retrieve attribute to forward/");
  
          // Create a request dispatcher and call forward() on it
          RequestDispatcher rd =
              getServletContext().getRequestDispatcher(path);
          if (rd == null) {
              sb.append(" No RequestDispatcher returned/");
          } else {
              if (sb.length() < 1)
                  rd.forward(request, response);
          }
  
          // Write our response if an error occurred
          if (sb.length() >= 1) {
              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/Forward03a.java
  
  Index: Forward03a.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 <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 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 ensure that a forwarded-to servlet can receive request attributes
   * set by the calling servlet, as well as set their own request attributes.
   *
   * The test forwards to either a servlet ("/Forward03a") or a JSP page
   * ("/Forward03b.jsp") depending on the value specified for the "path"
   * parameter.  The default is the servlet.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2001/05/03 18:41:37 $
   */
  
  public class Forward03a 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();
  
          // Verify that we can retrieve the forwarded attribute
          if (request.getAttribute("Forward03") == null)
              sb.append(" Cannot retrieve forwarded attribute/");
  
          // Verify that we can set and retrieve our own attribute
          request.setAttribute("Forward03a", "This is our own attribute");
          if (request.getAttribute("Forward03a") == null)
              sb.append(" Cannot retrieve our own attribute");
  
          // Verify that no special attributes are present
          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("Forward03 PASSED");
          else {
              writer.print("Forward03 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/web/Forward03b.jsp
  
  Index: Forward03b.jsp
  ===================================================================
  <%
    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" };
  
    StringBuffer sb = new StringBuffer();
    if (request.getAttribute("Forward03") == null)
      sb.append(" Cannot retrieve forwarded attribute/");
    request.setAttribute("Forward03b", "This is our very own attribute");
    if (request.getAttribute("Forward03b") == null)
      sb.append(" Cannot retrieve our own attribute/");
  
    for (int i = 0; i < specials.length; i++) {
      if (request.getAttribute(specials[i]) != null) {
        sb.append(" Exposed attribute ");
        sb.append(specials[i]);
        sb.append("/");
      }
    }
  
    if (sb.length() < 1) {
      out.println("Forward03 PASSED");
    } else {
      out.print("Forward03 FAILED - ");
      out.println(sb.toString());
    }
  %>
  
  
  
  1.1                  jakarta-tomcat-4.0/tester/web/Include03b.jsp
  
  Index: Include03b.jsp
  ===================================================================
  <% request.setAttribute("Include03b.jsp", "This is a new attribute"); %>
  
  
  
  1.28      +30 -5     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.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- web.xml	2001/05/02 20:44:54	1.27
  +++ web.xml	2001/05/03 18:41:45	1.28
  @@ -109,6 +109,11 @@
   
       <filter-mapping>
           <filter-name>HttpFilter</filter-name>
  +        <url-pattern>/WrappedForward03</url-pattern>
  +    </filter-mapping>
  +
  +    <filter-mapping>
  +        <filter-name>HttpFilter</filter-name>
           <url-pattern>/WrappedGetHeaders01</url-pattern>
       </filter-mapping>
   
  @@ -343,6 +348,16 @@
       </servlet>
   
       <servlet>
  +        <servlet-name>Forward03</servlet-name>
  +        <servlet-class>org.apache.tester.Forward03</servlet-class>
  +    </servlet>
  +
  +    <servlet>
  +        <servlet-name>Forward03a</servlet-name>
  +        <servlet-class>org.apache.tester.Forward03a</servlet-class>
  +    </servlet>
  +
  +    <servlet>
           <servlet-name>GetHeaders01</servlet-name>
           <servlet-class>org.apache.tester.GetHeaders01</servlet-class>
       </servlet>
  @@ -627,6 +642,21 @@
       </servlet-mapping>
   
       <servlet-mapping>
  +        <servlet-name>Forward03</servlet-name>
  +        <url-pattern>/Forward03</url-pattern>
  +    </servlet-mapping>
  +
  +    <servlet-mapping>
  +        <servlet-name>Forward03</servlet-name>
  +        <url-pattern>/WrappedForward03</url-pattern>
  +    </servlet-mapping>
  +
  +    <servlet-mapping>
  +        <servlet-name>Forward03a</servlet-name>
  +        <url-pattern>/Forward03a</url-pattern>
  +    </servlet-mapping>
  +
  +    <servlet-mapping>
           <servlet-name>GetHeaders01</servlet-name>
           <url-pattern>/GetHeaders01</url-pattern>
       </servlet-mapping>
  @@ -734,11 +764,6 @@
       <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>
  
  
  

Mime
View raw message