craigmcc    01/04/13 17:03:18

  Modified:    tester/src/bin tester.xml
               tester/web/WEB-INF web.xml
  Added:       tester/src/tester/org/apache/tester ErrorPage05.java
                        ErrorPage06.java
               tester/web ErrorPage06.html ErrorPage06.jsp
  Log:
  Add additional tests of the <error-page> mechanism to ensure that
  RuntimeException errors thrown by a servlet are also handled correctly,
  and that an error page handler can be any of a servlet, a JSP page, and an
  HTML page.
  
  Revision  Changes    Path
  1.28      +35 -2     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.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- tester.xml        2001/04/11 04:31:07     1.27
  +++ tester.xml        2001/04/14 00:03:17     1.28
  @@ -202,7 +202,6 @@
            request="${context.path}/ErrorPage01" debug="${debug}"
         outContent="ErrorPage02 PASSED"/>
   
  -
       <tester host="${host}" port="${port}" protocol="${protocol}"
            request="${context.path}/WrappedErrorPage01" debug="${debug}"
         outContent="ErrorPage02 PASSED"/>
  @@ -214,11 +213,45 @@
            request="${context.path}/ErrorPage03" debug="${debug}"
         outContent="ErrorPage04 PASSED"/>
   
  -
       <tester host="${host}" port="${port}" protocol="${protocol}"
            request="${context.path}/WrappedErrorPage03" debug="${debug}"
         outContent="ErrorPage04 PASSED"/>
   
  +    <tester host="${host}" port="${port}" protocol="${protocol}"
  +         request="${context.path}/ErrorPage05?type=Arithmetic"
  +           debug="${debug}"
  +          status="200"
  +      outContent="ErrorPage06 PASSED - SERVLET"/>
  +
  +    <tester host="${host}" port="${port}" protocol="${protocol}"
  +         request="${context.path}/WrappedErrorPage05?type=Arithmetic"
  +           debug="${debug}"
  +          status="200"
  +      outContent="ErrorPage06 PASSED - SERVLET"/>
  +
  +    <tester host="${host}" port="${port}" protocol="${protocol}"
  +         request="${context.path}/ErrorPage05?type=Array"
  +           debug="${debug}"
  +          status="200"
  +      outContent="ErrorPage06 PASSED - JSP"/>
  +
  +    <tester host="${host}" port="${port}" protocol="${protocol}"
  +         request="${context.path}/WrappedErrorPage05?type=Array"
  +           debug="${debug}"
  +          status="200"
  +      outContent="ErrorPage06 PASSED - JSP"/>
  +
  +    <tester host="${host}" port="${port}" protocol="${protocol}"
  +         request="${context.path}/ErrorPage05?type=Number"
  +           debug="${debug}"
  +          status="200"
  +      outContent="ErrorPage06 PASSED - HTML"/>
  +
  +    <tester host="${host}" port="${port}" protocol="${protocol}"
  +         request="${context.path}/WrappedErrorPage05?type=Number"
  +           debug="${debug}"
  +          status="200"
  +      outContent="ErrorPage06 PASSED - HTML"/>
   
     </target>
   
  
  
  
  1.1                  
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/ErrorPage05.java
  
  Index: ErrorPage05.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 javax.servlet.*;
  import javax.servlet.http.*;
  
  /**
   * Part 5 of the ErrorPage Tests.  Throws a RuntimeException of a type
   * specified by the <code>type</code> query parameter, which must be one
   * of the following:
   * <ul>
   * <li><strong>ArithmeticException</strong> - Forwarded to "/ErrorPage06".</li>
   * <li><strong>ArrayIndexOutOfBoundsException</strong> -
   *     Forwarded to "/ErrorPage06.jsp".</li>
   * <li><strong>NumberFormatException</strong> -
   *     Forwarded to "/ErrorPage06.html".</li>
   * </ul>
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2001/04/14 00:03:17 $
   */
  
  public class ErrorPage05 extends HttpServlet {
  
      public void doGet(HttpServletRequest request, HttpServletResponse response)
          throws IOException, ServletException {
  
          response.setContentType("text/plain");
          PrintWriter writer = response.getWriter();
  
          // Write a FAILED message that should get replaced by the error text
          writer.println("ErrorPage05 FAILED - Original response returned");
  
          // Throw the specified exception
          String type = request.getParameter("type");
          if ("Arithmetic".equals(type)) {
              throw new ArithmeticException
                  ("ErrorPage05 Threw ArithmeticException");
          } else if ("Array".equals(type)) {
              throw new ArrayIndexOutOfBoundsException
                  ("ErrorPage05 Threw ArrayIndexOutOfBoundsException");
          } else if ("Number".equals(type)) {
              throw new NumberFormatException
                  ("ErrorPage05 Threw NumberFormatException");
          }
  
      }
  
  }
  
  
  
  1.1                  
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/ErrorPage06.java
  
  Index: ErrorPage06.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 javax.servlet.*;
  import javax.servlet.http.*;
  
  /**
   * Part 6 of the ErrorPage Tests.  Should be mapped by the container when
   * the ErrorPage05 servlet returns the appropriate exception.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2001/04/14 00:03:17 $
   */
  
  public class ErrorPage06 extends HttpServlet {
  
  
      public void doGet(HttpServletRequest request, HttpServletResponse response)
          throws IOException, ServletException {
  
          response.reset();
          response.setContentType("text/plain");
          PrintWriter writer = response.getWriter();
  
          // Accumulate all the reasons this request might fail
          StringBuffer sb = new StringBuffer();
          Object value = null;
  
          value = request.getAttribute("javax.servlet.error.exception");
          if (value == null)
              sb.append(" exception is missing/");
          else if (!(value instanceof java.lang.ArithmeticException)) {
              sb.append(" exception class is ");
              sb.append(value.getClass().getName());
              sb.append("/");
          }
  
          value = request.getAttribute("javax.servlet.error.exception_type");
          if (value == null)
              sb.append(" exception_type is missing/");
          else if (!(value instanceof Class)) {
              sb.append(" exception_type class is ");
              sb.append(value.getClass().getName());
              sb.append("/");
          } else {
              Class clazz = (Class) value;
              if (!"java.lang.ArithmeticException".equals(clazz.getName())) {
                  sb.append(" exception_type class is ");
                  sb.append(clazz.getName());
                  sb.append("/");
              }
          }
  
          value = request.getAttribute("javax.servlet.error.message");
          if (value == null)
              sb.append(" message is missing/");
          else if (!(value instanceof String)) {
              sb.append(" message class is ");
              sb.append(value.getClass().getName());
              sb.append("/");
          } else {
              String message = (String) value;
              if (!message.equals("ErrorPage05 Threw ArithmeticException")) {
                  sb.append(" message content is ");
                  sb.append(message);
                  sb.append("/");
              }
          }
  
          value = request.getAttribute("javax.servlet.error.request_uri");
          if (value == null)
              sb.append(" request_uri is missing/");
          else if (!(value instanceof String)) {
              sb.append(" request_uri class is ");
              sb.append(value.getClass().getName());
              sb.append("/");
          } else {
              String request_uri = (String) value;
              String test1 = request.getContextPath() + "/ErrorPage05";
              String test2 = request.getContextPath() + "/WrappedErrorPage05";
              if (!request_uri.equals(test1) && !request_uri.equals(test2)) {
                  sb.append(" request_uri is ");
                  sb.append(request_uri);
                  sb.append("/");
              }
          }
  
          value = request.getAttribute("javax.servlet.error.servlet_name");
          if (value == null)
              sb.append(" servlet_name is missing/");
          else if (!(value instanceof String)) {
              sb.append(" servlet_name class is ");
              sb.append(value.getClass().getName());
              sb.append("/");
          } else {
              String servlet_name = (String) value;
              if (!"ErrorPage05".equals(servlet_name)) {
                  sb.append(" servlet_name is ");
                  sb.append(servlet_name);
                  sb.append("/");
              }
          }
  
          // Report ultimate success or failure
          if (sb.length() < 1)
              writer.println("ErrorPage06 PASSED - SERVLET");
          else
              writer.println("ErrorPage06 FAILED -" + 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/ErrorPage06.html
  
  Index: ErrorPage06.html
  ===================================================================
  ErrorPage06 PASSED - HTML
  
  
  
  1.1                  jakarta-tomcat-4.0/tester/web/ErrorPage06.jsp
  
  Index: ErrorPage06.jsp
  ===================================================================
  <%@ page contentType="text/plain" %>ErrorPage06 PASSED - JSP
  <%
    Exception e = (Exception)
     request.getAttribute("javax.servlet.error.exception");
    out.println("EXCEPTION:  " + e);
    Class et = (Class)
     request.getAttribute("javax.servlet.error.exception_type");
    out.println("EXCEPTION_TYPE:  " + et.getName());
    String m = (String)
     request.getAttribute("javax.servlet.error.message");
    out.println("MESSAGE:  " + m);
    String ru = (String)
     request.getAttribute("javax.servlet.error.request_uri");
    out.println("REQUEST_URI:  " + ru);
    String sn = (String)
     request.getAttribute("javax.servlet.error.servlet_name");
    out.println("SERVLET_NAME:  " + sn);
  %>
  
  
  
  1.20      +55 -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.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- web.xml   2001/04/11 04:31:08     1.19
  +++ web.xml   2001/04/14 00:03:17     1.20
  @@ -77,6 +77,16 @@
   
       <filter-mapping>
           <filter-name>HttpFilter</filter-name>
  +        <url-pattern>/WrappedErrorPage05</url-pattern>
  +    </filter-mapping>
  +
  +    <filter-mapping>
  +        <filter-name>HttpFilter</filter-name>
  +        <url-pattern>/WrappedErrorPage06</url-pattern>
  +    </filter-mapping>
  +
  +    <filter-mapping>
  +        <filter-name>HttpFilter</filter-name>
           <url-pattern>/WrappedForward01</url-pattern>
       </filter-mapping>
   
  @@ -258,6 +268,16 @@
       </servlet>
   
       <servlet>
  +        <servlet-name>ErrorPage05</servlet-name>
  +        <servlet-class>org.apache.tester.ErrorPage05</servlet-class>
  +    </servlet>
  +
  +    <servlet>
  +        <servlet-name>ErrorPage06</servlet-name>
  +        <servlet-class>org.apache.tester.ErrorPage06</servlet-class>
  +    </servlet>
  +
  +    <servlet>
           <servlet-name>Forward01</servlet-name>
           <servlet-class>org.apache.tester.Forward01</servlet-class>
       </servlet>
  @@ -477,6 +497,26 @@
       </servlet-mapping>
   
       <servlet-mapping>
  +        <servlet-name>ErrorPage05</servlet-name>
  +        <url-pattern>/ErrorPage05</url-pattern>
  +    </servlet-mapping>
  +
  +    <servlet-mapping>
  +        <servlet-name>ErrorPage05</servlet-name>
  +        <url-pattern>/WrappedErrorPage05</url-pattern>
  +    </servlet-mapping>
  +
  +    <servlet-mapping>
  +        <servlet-name>ErrorPage06</servlet-name>
  +        <url-pattern>/ErrorPage06</url-pattern>
  +    </servlet-mapping>
  +
  +    <servlet-mapping>
  +        <servlet-name>ErrorPage06</servlet-name>
  +        <url-pattern>/WrappedErrorPage06</url-pattern>
  +    </servlet-mapping>
  +
  +    <servlet-mapping>
           <servlet-name>Forward01</servlet-name>
           <url-pattern>/Forward01</url-pattern>
       </servlet-mapping>
  @@ -752,6 +792,21 @@
       <error-page>
           <exception-type>org.apache.tester.TesterException</exception-type>
           <location>/ErrorPage04</location>
  +    </error-page>
  +
  +    <error-page>
  +        <exception-type>java.lang.ArithmeticException</exception-type>
  +        <location>/ErrorPage06</location>
  +    </error-page>
  +
  +    <error-page>
  +        <exception-type>java.lang.ArrayIndexOutOfBoundsException</exception-type>
  +        <location>/ErrorPage06.jsp</location>
  +    </error-page>
  +
  +    <error-page>
  +        <exception-type>java.lang.NumberFormatException</exception-type>
  +        <location>/ErrorPage06.html</location>
       </error-page>
   
   
  
  
  

Reply via email to