glenn       2003/02/19 06:42:40

  Modified:    catalina/src/share/org/apache/catalina/connector
                        ResponseBase.java
               catalina/src/share/org/apache/catalina/valves
                        ErrorDispatcherValve.java LocalStrings.properties
  Added:       catalina/src/share/org/apache/catalina/connector
                        ClientAbortException.java
  Log:
  When a remote client aborts an HTTP Request a full stack trace
  for the IOException is logged and if the web application has an
  error page it will be invoked. Logging the complete stack trace
  is not needed and is just extra overhead.  This patch logs just
  a single line with a message stating that the remote client
  aborted the request.  If the remote client aborted the request
  it is a waste of time to try and return an error page.  This
  patch detects when a remote client aborted a request and just
  terminates the request rather than try to process an error page.
  
  Revision  Changes    Path
  1.26      +9 -4      
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/ResponseBase.java
  
  Index: ResponseBase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/ResponseBase.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- ResponseBase.java 18 Mar 2002 07:15:39 -0000      1.25
  +++ ResponseBase.java 19 Feb 2003 14:42:40 -0000      1.26
  @@ -673,6 +673,11 @@
           if (bufferCount > 0) {
               try {
                   output.write(buffer, 0, bufferCount);
  +            } catch(IOException ioe) {
  +                // An IOException on a write is almost always due to
  +                // the remote client aborting the request.  Wrap this
  +                // so that it can be handled better by the error dispatcher.
  +                throw new ClientAbortException(ioe);
               } finally {
                   bufferCount = 0;
               }
  
  
  
  1.1                  
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/ClientAbortException.java
  
  Index: ClientAbortException.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/ClientAbortException.java,v
 1.1 2003/02/19 14:42:40 glenn Exp $
   * $Revision: 1.1 $
   * $Date: 2003/02/19 14:42:40 $
   *
   * ====================================================================
   *
   * 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 [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 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.catalina.connector;
  
  import java.io.IOException;
  
  /**
   * Wrap an IOException identifying it as being caused by an abort
   * of a request by a remote client.
   *
   * @author Glenn L. Nielsen
   * @version $Revision: 1.1 $ $Date: 2003/02/19 14:42:40 $
   */
  
  public final class ClientAbortException extends IOException {
  
  
      //------------------------------------------------------------ Constructors
  
  
      /**
       * Construct a new ClientAbortException with no other information.
       */
      public ClientAbortException() {
  
          this(null, null);
  
      }
  
  
      /**
       * Construct a new ClientAbortException for the specified message.
       *
       * @param message Message describing this exception
       */
      public ClientAbortException(String message) {
  
          this(message, null);
  
      }
  
  
      /**
       * Construct a new ClientAbortException for the specified throwable.
       *
       * @param throwable Throwable that caused this exception
       */
      public ClientAbortException(Throwable throwable) {
  
          this(null, throwable);
  
      }
  
  
      /**
       * Construct a new ClientAbortException for the specified message
       * and throwable.
       *
       * @param message Message describing this exception
       * @param throwable Throwable that caused this exception
       */
      public ClientAbortException(String message, Throwable throwable) {
  
          super();
          this.message = message;
          this.throwable = throwable;
  
      }
  
  
      //------------------------------------------------------ Instance Variables
  
  
      /**
       * The error message passed to our constructor (if any)
       */
      protected String message = null;
  
  
      /**
       * The underlying exception or error passed to our constructor (if any)
       */
      protected Throwable throwable = null;
  
  
      //---------------------------------------------------------- Public Methods
  
  
      /**
       * Returns the message associated with this exception, if any.
       */
      public String getMessage() {
  
          return (message);
  
      }
  
  
      /**
       * Returns the throwable that caused this exception, if any.
       */
      public Throwable getThrowable() {
  
          return (throwable);
  
      }
  
  
      /**
       * Return a formatted string that describes this exception.
       */
      public String toString() {
  
          StringBuffer sb = new StringBuffer("ClientAbortException:  ");
          if (message != null) {
              sb.append(message);
              if (throwable != null) {
                  sb.append(":  ");
              }
          }
          if (throwable != null) {
              sb.append(throwable.toString());
          }
          return (sb.toString());
  
      }
  
  
  }
  
  
  
  1.11      +15 -7     
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/valves/ErrorDispatcherValve.java
  
  Index: ErrorDispatcherValve.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/valves/ErrorDispatcherValve.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ErrorDispatcherValve.java 13 Feb 2003 20:52:09 -0000      1.10
  +++ ErrorDispatcherValve.java 19 Feb 2003 14:42:40 -0000      1.11
  @@ -88,6 +88,7 @@
   import org.apache.catalina.Valve;
   import org.apache.catalina.ValveContext;
   import org.apache.catalina.Wrapper;
  +import org.apache.catalina.connector.ClientAbortException;
   import org.apache.catalina.deploy.ErrorPage;
   import org.apache.catalina.util.RequestUtil;
   import org.apache.catalina.util.StringManager;
  @@ -215,16 +216,23 @@
           Context context = request.getContext();
           if (context == null)
               return;
  -        
  +
           Throwable realError = throwable;
  -        
           if (realError instanceof ServletException) {
               realError = ((ServletException) realError).getRootCause();
               if (realError == null) {
                   realError = throwable;
               }
           } 
  -            
  +
  +        // If this is an aborted request from a client just log it and return
  +        if (realError instanceof ClientAbortException ) {
  +            log(sm.getString(
  +                "errorDispatcherValve.clientAbort",
  +                ((ClientAbortException)realError).getThrowable().getMessage()));
  +            return;
  +        }
  +
           ErrorPage errorPage = findErrorPage(context, realError);
   
           if (errorPage != null) {
  
  
  
  1.4       +3 -0      
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/valves/LocalStrings.properties
  
  Index: LocalStrings.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/valves/LocalStrings.properties,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LocalStrings.properties   26 Sep 2001 17:44:51 -0000      1.3
  +++ LocalStrings.properties   19 Feb 2003 14:42:40 -0000      1.4
  @@ -8,6 +8,9 @@
   requestFilterValve.syntax=Syntax error in request filter pattern {0}
   valveBase.noNext=Configuration error: No 'next' valve configured
   
  +# Error Dispatcher valve
  +errorDispatcherValve.clientAbort=Remote Client Aborted Request, IOException: {0}
  +
   # Error report valve
   errorReportValve.errorReport=Error report
   errorReportValve.statusHeader=HTTP Status {0} - {1}
  
  
  

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

Reply via email to