tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core StandardWrapperValve.java
Date Thu, 04 Jan 2001 19:49:25 GMT
remm        01/01/04 11:49:24

  Modified:    catalina/src/share/org/apache/catalina Response.java
               catalina/src/share/org/apache/catalina/connector
                        HttpResponseBase.java ResponseBase.java
               catalina/src/share/org/apache/catalina/connector/http
                        SocketInputStream.java
               catalina/src/share/org/apache/catalina/core
                        StandardWrapperValve.java
  Log:
  - Added an error flag to the Response. If the flag is set to true, then the
    response is an error report.
  - The error flag is set to true if :
    - An exception is thrown by the servlet
    - sendError is used by the servlet
  - The reporter can now not return a writer if :
    - The response is not an error report
    - The "client" servlet had used the output stream
    In that case, no status report is shown (and it's the responsability of the
    servlet to take care of that). Also, the getReporter actually sends the wrapped
    input stream, instead of directly using the socket output.
  
  Revision  Changes    Path
  1.2       +22 -4     jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Response.java
  
  Index: Response.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Response.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Response.java	2000/08/11 05:24:11	1.1
  +++ Response.java	2001/01/04 19:49:12	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Response.java,v
1.1 2000/08/11 05:24:11 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/08/11 05:24:11 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Response.java,v
1.2 2001/01/04 19:49:12 remm Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/01/04 19:49:12 $
    *
    * ====================================================================
    *
  @@ -79,7 +79,7 @@
    * based on the processing of a corresponding <code>Request</code>.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/08/11 05:24:11 $
  + * @version $Revision: 1.2 $ $Date: 2001/01/04 19:49:12 $
    */
   
   public interface Response {
  @@ -181,6 +181,18 @@
       public void setStream(OutputStream stream);
   
   
  +    /**
  +     * Set the error flag.
  +     */
  +    public void setError();
  +
  +
  +    /**
  +     * Error flag accessor.
  +     */
  +    public boolean isError();
  +
  +
       // --------------------------------------------------------- Public Methods
   
   
  @@ -218,6 +230,12 @@
       /**
        * Return a PrintWriter that can be used to render error messages,
        * regardless of whether a stream or writer has already been acquired.
  +     * 
  +     * @return Writer which can be used for error reports. If the response is
  +     * not an error report returned using sendError or triggered by an 
  +     * unexpected exception thrown during the servlet processing 
  +     * (and only in that case), null will be returned if the response stream 
  +     * has already been used.
        */
       public PrintWriter getReporter();
   
  
  
  
  1.23      +7 -4      jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/HttpResponseBase.java
  
  Index: HttpResponseBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/HttpResponseBase.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- HttpResponseBase.java	2000/12/17 01:05:39	1.22
  +++ HttpResponseBase.java	2001/01/04 19:49:16	1.23
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/HttpResponseBase.java,v
1.22 2000/12/17 01:05:39 craigmcc Exp $
  - * $Revision: 1.22 $
  - * $Date: 2000/12/17 01:05:39 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/HttpResponseBase.java,v
1.23 2001/01/04 19:49:16 remm Exp $
  + * $Revision: 1.23 $
  + * $Date: 2001/01/04 19:49:16 $
    *
    * ====================================================================
    *
  @@ -96,7 +96,8 @@
    * methods need to be implemented.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.22 $ $Date: 2000/12/17 01:05:39 $
  + * @author Remy Maucherat
  + * @version $Revision: 1.23 $ $Date: 2001/01/04 19:49:16 $
    */
   
   public class HttpResponseBase
  @@ -975,6 +976,8 @@
   
   	if (included)
   	    return;	// Ignore any call from an included servlet
  +
  +        setError();
   
   	// Record the status code and message.
   	this.status = status;
  
  
  
  1.9       +52 -9     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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ResponseBase.java	2000/12/13 23:45:37	1.8
  +++ ResponseBase.java	2001/01/04 19:49:16	1.9
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/ResponseBase.java,v
1.8 2000/12/13 23:45:37 craigmcc Exp $
  - * $Revision: 1.8 $
  - * $Date: 2000/12/13 23:45:37 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/ResponseBase.java,v
1.9 2001/01/04 19:49:16 remm Exp $
  + * $Revision: 1.9 $
  + * $Date: 2001/01/04 19:49:16 $
    *
    * ====================================================================
    *
  @@ -88,7 +88,7 @@
    * the connector-specific methods need to be implemented.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.8 $ $Date: 2000/12/13 23:45:37 $
  + * @version $Revision: 1.9 $ $Date: 2001/01/04 19:49:16 $
    */
   
   public abstract class ResponseBase
  @@ -204,6 +204,12 @@
       protected PrintWriter writer = null;
   
   
  +    /**
  +     * Error flag. True if the response is an error report.
  +     */
  +    protected boolean error = false;
  +
  +
       // ------------------------------------------------------------- Properties
   
   
  @@ -352,6 +358,26 @@
       }
   
   
  +    /**
  +     * Set the error flag.
  +     */
  +    public void setError() {
  +
  +        this.error = true;
  +
  +    }
  +
  +
  +    /**
  +     * Error flag accessor.
  +     */
  +    public boolean isError() {
  +
  +        return (this.error);
  +
  +    }
  +
  +
       // --------------------------------------------------------- Public Methods
   
   
  @@ -430,13 +456,29 @@
        * regardless of whether a stream or writer has already been acquired.
        */
       public PrintWriter getReporter() {
  +
  +        if (isError()) {
  +
  +            try {
  +                flushBuffer();
  +            } catch (IOException e) {
  +                ;
  +            }
  +            return (new PrintWriter(output));
  +
  +        } else {
  +
  +            if (this.stream != null) {
  +                return null;
  +            } else {
  +                try {
  +                    return (new PrintWriter(getOutputStream()));
  +                } catch (IOException e) {
  +                    return null;
  +                }
  +            }
   
  -        try {
  -            flushBuffer();
  -        } catch (IOException e) {
  -            ;
           }
  -	return (new PrintWriter(output));
   
       }
   
  @@ -462,6 +504,7 @@
   	request = null;
   	stream = null;
   	writer = null;
  +        error = false;
   
       }
   
  
  
  
  1.5       +8 -4      jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/http/SocketInputStream.java
  
  Index: SocketInputStream.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/http/SocketInputStream.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SocketInputStream.java	2000/12/02 03:51:31	1.4
  +++ SocketInputStream.java	2001/01/04 19:49:20	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/http/SocketInputStream.java,v
1.4 2000/12/02 03:51:31 remm Exp $
  - * $Revision: 1.4 $
  - * $Date: 2000/12/02 03:51:31 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/http/SocketInputStream.java,v
1.5 2001/01/04 19:49:20 remm Exp $
  + * $Revision: 1.5 $
  + * $Date: 2001/01/04 19:49:20 $
    *
    * ====================================================================
    * 
  @@ -165,7 +165,11 @@
           // Checking for a blank line
           int chr = 0;
           do { // Skipping CR or LF
  -            chr = read();
  +            try {
  +                chr = read();
  +            } catch (IOException e) {
  +                chr = -1;
  +            }
           } while ((chr == CR) || (chr == LF));
           if (chr == -1)
               throw new EOFException
  
  
  
  1.15      +29 -24    jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapperValve.java
  
  Index: StandardWrapperValve.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapperValve.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- StandardWrapperValve.java	2000/11/02 23:04:49	1.14
  +++ StandardWrapperValve.java	2001/01/04 19:49:22	1.15
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapperValve.java,v
1.14 2000/11/02 23:04:49 craigmcc Exp $
  - * $Revision: 1.14 $
  - * $Date: 2000/11/02 23:04:49 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapperValve.java,v
1.15 2001/01/04 19:49:22 remm Exp $
  + * $Revision: 1.15 $
  + * $Date: 2001/01/04 19:49:22 $
    *
    * ====================================================================
    *
  @@ -101,7 +101,7 @@
    * <code>StandardWrapper</code> container implementation.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.14 $ $Date: 2000/11/02 23:04:49 $
  + * @version $Revision: 1.15 $ $Date: 2001/01/04 19:49:22 $
    */
   
   final class StandardWrapperValve
  @@ -522,6 +522,9 @@
   		return;
   	}
   
  +        // The response is an error
  +        response.setError();
  +
   	// Reset the response (if possible)
           //        if (debug >= 1)
           //            log(" Resetting response");
  @@ -795,14 +798,14 @@
   	    return;
   
   	// Reset the response data buffer (if possible)
  -	try {
  -            //	    response.resetBuffer();
  -	    hresponse.reset(statusCode, message);
  +        try {
  +            if (hresponse.isError())
  +                hresponse.reset(statusCode, message);
   	} catch (Throwable e) {
               if (debug >= 1)
                   log("status.reset", e);
   	}
  -
  +        
   	// Render a default HTML status report page
   	try {
   	    try {
  @@ -812,22 +815,24 @@
                       log("status.setContentType", t);
   	    }
   	    PrintWriter writer = response.getReporter();
  -	    writer.println("<html>");
  -	    writer.println("<head>");
  -	    writer.println("<title>" +
  -			   sm.getString("standardWrapper.statusTitle") +
  -			   "</title>");
  -	    writer.println("</head>");
  -	    writer.println("<body bgcolor=\"white\">");
  -	    writer.println("<br><br>");
  -	    writer.println("<h1>" +
  -			   sm.getString("standardWrapper.statusHeader",
  -					"" + statusCode, message) +
  -			   "</h1>");
  -	    writer.println(report);
  -	    writer.println("</body>");
  -	    writer.println("</html>");
  -	    writer.flush();
  +            if (writer != null) {
  +                writer.println("<html>");
  +                writer.println("<head>");
  +                writer.println("<title>" +
  +                               sm.getString("standardWrapper.statusTitle") +
  +                               "</title>");
  +                writer.println("</head>");
  +                writer.println("<body bgcolor=\"white\">");
  +                writer.println("<br><br>");
  +                writer.println("<h1>" +
  +                               sm.getString("standardWrapper.statusHeader",
  +                                            "" + statusCode, message) +
  +                               "</h1>");
  +                writer.println(report);
  +                writer.println("</body>");
  +                writer.println("</html>");
  +                writer.flush();
  +            }
   	} catch (IllegalStateException e) {
               if (debug >= 1)
                   log("status.write", e);
  
  
  

Mime
View raw message