craigmcc    01/12/12 14:34:20

  Modified:    tester/src/bin tester.xml
               tester/web/WEB-INF web.xml
  Added:       tester/src/tester/org/apache/tester Redirect01.java
                        Redirect01a.java
               tester/web Redirect02.jsp Redirect02a.jsp Redirect03.jsp
                        Redirect03a.jsp
  Log:
  Add unit tests to demonstrate that response.sendRedirect() is handled
  correctly, including ignoring any subsequent output, from either a servlet
  or a JSP page.
  
  Revision  Changes    Path
  1.75      +20 -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.74
  retrieving revision 1.75
  diff -u -r1.74 -r1.75
  --- tester.xml        2001/12/12 02:26:10     1.74
  +++ tester.xml        2001/12/12 22:34:20     1.75
  @@ -1464,6 +1464,26 @@
         outHeaders="Content-Language:en-US"/>
   
   
  +    <!-- ========== SendRedirect Handling ================================= -->
  +
  +    <tester host="${host}" port="${port}" protocol=""
  +         request="${context.path}/Redirect01" debug="${debug}"
  +      outContent="Redirect01a PASSED" redirect="true"/>
  +
  +    <tester host="${host}" port="${port}" protocol=""
  +         request="${context.path}/WrappedRedirect01" debug="${debug}"
  +      outContent="Redirect01a PASSED" redirect="true"/>
  +
  +    <!-- JSP page includes "return" after redirect -->
  +    <tester host="${host}" port="${port}" protocol=""
  +         request="${context.path}/Redirect02.jsp" debug="${debug}"
  +      outContent="Redirect02a.jsp PASSED" redirect="true"/>
  +
  +    <!-- Same as "Redirect02.jsp" except without the "return" -->
  +    <tester host="${host}" port="${port}" protocol=""
  +         request="${context.path}/Redirect03.jsp" debug="${debug}"
  +      outContent="Redirect03a.jsp PASSED" redirect="true"/>
  +
     </target>
   
   
  
  
  
  1.1                  
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Redirect01.java
  
  Index: Redirect01.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 <[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 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 java.util.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  
  /**
   * Positive test for HttpServletResponse.sendRedirect().
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2001/12/12 22:34:20 $
   */
  
  public class Redirect01 extends HttpServlet {
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Process a servlet request and create the corresponding response.
       *
       * @param request The request we are processing
       * @param response The response we are creating
       *
       * @exception IOException if an input/output error occurs
       * @exception ServletException if a servlet error occurs
       */
      public void doGet(HttpServletRequest request,
                        HttpServletResponse response)
          throws IOException, ServletException {
  
          response.setContentType("text/plain");
          PrintWriter writer = response.getWriter();
  
          try {
              response.sendRedirect(request.getContextPath() + "/Redirect01a");
              return;
          } catch (IllegalStateException e) {
              writer.println("Redirect01 FAILED - Threw IllegaStateException");
              e.printStackTrace(writer);
          }
          try {
              writer.println("Redirect01 FAILED - Output text after redirect");
          } catch (Throwable t) {
              throw new ServletException("Redirect01 Post-Redirect Output Error",
                                         t);
          }
          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/Redirect01a.java
  
  Index: Redirect01a.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 <[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 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 java.util.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  
  /**
   * Positive test for HttpServletResponse.sendRedirect().
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2001/12/12 22:34:20 $
   */
  
  public class Redirect01a extends HttpServlet {
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Process a servlet request and create the corresponding response.
       *
       * @param request The request we are processing
       * @param response The response we are creating
       *
       * @exception IOException if an input/output error occurs
       * @exception ServletException if a servlet error occurs
       */
      public void doGet(HttpServletRequest request,
                        HttpServletResponse response)
          throws IOException, ServletException {
  
          response.setContentType("text/plain");
          PrintWriter writer = response.getWriter();
          writer.println("Redirect01a PASSED");
          while (true) {
              String message = StaticLogger.read();
              if (message == null)
                  break;
              writer.println(message);
          }
          StaticLogger.reset();
  
      }
  
  
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/tester/web/Redirect02.jsp
  
  Index: Redirect02.jsp
  ===================================================================
  <%@ page contentType="text/plain" %><% String dummy = null; if (dummy == null) { 
response.sendRedirect(request.getContextPath() + "/Redirect02a.jsp"); return; } 
%>Redirect02.jsp FAILED - Content should not be visible
  
  
  
  1.1                  jakarta-tomcat-4.0/tester/web/Redirect02a.jsp
  
  Index: Redirect02a.jsp
  ===================================================================
  <%@ page contentType="text/plain" %>Redirect02a.jsp PASSED
  
  
  
  1.1                  jakarta-tomcat-4.0/tester/web/Redirect03.jsp
  
  Index: Redirect03.jsp
  ===================================================================
  <%@ page contentType="text/plain" %><% String dummy = null; if (dummy == null) { 
response.sendRedirect(request.getContextPath() + "/Redirect03a.jsp");  } 
%>Redirect03.jsp FAILED - Content should not be visible
  
  
  
  1.1                  jakarta-tomcat-4.0/tester/web/Redirect03a.jsp
  
  Index: Redirect03a.jsp
  ===================================================================
  <%@ page contentType="text/plain" %>Redirect03a.jsp PASSED
  
  
  
  1.55      +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.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- web.xml   2001/11/12 21:37:28     1.54
  +++ web.xml   2001/12/12 22:34:20     1.55
  @@ -335,6 +335,11 @@
   
       <filter-mapping>
           <filter-name>HttpFilter</filter-name>
  +        <url-pattern>/WrappedRedirect01</url-pattern>
  +    </filter-mapping>
  +
  +    <filter-mapping>
  +        <filter-name>HttpFilter</filter-name>
           <url-pattern>/WrappedReflection01</url-pattern>
       </filter-mapping>
   
  @@ -887,6 +892,16 @@
       </servlet>
   
       <servlet>
  +        <servlet-name>Redirect01</servlet-name>
  +        <servlet-class>org.apache.tester.Redirect01</servlet-class>
  +    </servlet>
  +
  +    <servlet>
  +        <servlet-name>Redirect01a</servlet-name>
  +        <servlet-class>org.apache.tester.Redirect01a</servlet-class>
  +    </servlet>
  +
  +    <servlet>
           <servlet-name>Reflection01</servlet-name>
           <servlet-class>org.apache.tester.Reflection01</servlet-class>
       </servlet>
  @@ -1646,6 +1661,26 @@
       <servlet-mapping>
           <servlet-name>Lifecycle03</servlet-name>
           <url-pattern>/WrappedLifecycle03</url-pattern>
  +    </servlet-mapping>
  +
  +    <servlet-mapping>
  +        <servlet-name>Redirect01</servlet-name>
  +        <url-pattern>/Redirect01</url-pattern>
  +    </servlet-mapping>
  +
  +    <servlet-mapping>
  +        <servlet-name>Redirect01</servlet-name>
  +        <url-pattern>/WrappedRedirect01</url-pattern>
  +    </servlet-mapping>
  +
  +    <servlet-mapping>
  +        <servlet-name>Redirect01a</servlet-name>
  +        <url-pattern>/Redirect01a</url-pattern>
  +    </servlet-mapping>
  +
  +    <servlet-mapping>
  +        <servlet-name>Redirect01a</servlet-name>
  +        <url-pattern>/WrappedRedirect01a</url-pattern>
       </servlet-mapping>
   
       <servlet-mapping>
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to