Return-Path: Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list tomcat-dev@jakarta.apache.org Received: (qmail 87312 invoked by uid 500); 7 Nov 2000 03:16:54 -0000 Delivered-To: apmail-jakarta-tomcat-cvs@apache.org Received: (qmail 87289 invoked by uid 1059); 7 Nov 2000 03:16:54 -0000 Date: 7 Nov 2000 03:16:53 -0000 Message-ID: <20001107031653.87284.qmail@locus.apache.org> From: craigmcc@locus.apache.org To: jakarta-tomcat-cvs@apache.org Subject: cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/service/http HttpResponseAdapter.java craigmcc 00/11/06 19:16:52 Modified: src/share/org/apache/tomcat/core Tag: tomcat_32 ResponseImpl.java src/share/org/apache/tomcat/facade Tag: tomcat_32 RequestDispatcherImpl.java src/share/org/apache/tomcat/service/http Tag: tomcat_32 HttpResponseAdapter.java Log: Work around a nasty problem that is caused by the way SessionInterceptor is implemented in Tomcat 3.2. The problem report (BugRat Bug Report #316) indicates that session cookies were not being set if a servlet did a RequestDispatcher.include() of a JSP page. The actual problem would occur anytime that the first flush of the response buffer occurred inside the included servlet. It happens because the session interceptor (that sets the session cookie) uses the same method used by servlets (response.addHeader()) to add the session ID cookie -- but attempts to add headers inside an included servlet are ignored. A JSP page as the included target triggers this because it includes a flush someplace; you can easily duplicate it with regular servlets as well. The workaround is to call response.flushBuffer() before actually calling the included servlet. This causes the session ID cookie (and the Servlet-Engine header) to be correctly set. It should not cause any compatibility problems, because included servlets are not able to do anything but write to the output stream or writer (or flush) anyway. PR: 316 Revision Changes Path No revision No revision 1.33.2.2 +14 -13 jakarta-tomcat/src/share/org/apache/tomcat/core/Attic/ResponseImpl.java Index: ResponseImpl.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Attic/ResponseImpl.java,v retrieving revision 1.33.2.1 retrieving revision 1.33.2.2 diff -u -r1.33.2.1 -r1.33.2.2 --- ResponseImpl.java 2000/11/05 03:12:03 1.33.2.1 +++ ResponseImpl.java 2000/11/07 03:16:45 1.33.2.2 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Attic/ResponseImpl.java,v 1.33.2.1 2000/11/05 03:12:03 craigmcc Exp $ - * $Revision: 1.33.2.1 $ - * $Date: 2000/11/05 03:12:03 $ + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Attic/ResponseImpl.java,v 1.33.2.2 2000/11/07 03:16:45 craigmcc Exp $ + * $Revision: 1.33.2.2 $ + * $Date: 2000/11/07 03:16:45 $ * * ==================================================================== * @@ -364,17 +364,18 @@ } public void reset() throws IllegalStateException { + + if( isIncluded() ) return; // We are in an included sub-request + // Force the PrintWriter to flush its data to the output // stream before resetting the output stream // - if( ! isIncluded() ) { - userCookies.removeAllElements(); // keep system (session) cookies - contentType = Constants.DEFAULT_CONTENT_TYPE; - locale = DEFAULT_LOCALE; - characterEncoding = Constants.DEFAULT_CHAR_ENCODING; - contentLength = -1; - status = 200; - } + userCookies.removeAllElements(); // keep system (session) cookies + contentType = Constants.DEFAULT_CONTENT_TYPE; + locale = DEFAULT_LOCALE; + characterEncoding = Constants.DEFAULT_CHAR_ENCODING; + contentLength = -1; + status = 200; if (usingWriter == true && writer != null) writer.flush(); @@ -386,7 +387,7 @@ // Clear the cookies and such // Clear the headers - if( ! isIncluded() ) headers.clear(); + headers.clear(); } // Reset the response buffer but not headers and cookies @@ -427,7 +428,7 @@ // let CM notify interceptors and give a chance to fix // the headers - if(request.getContext() != null && notIncluded ) + if(request.getContext() != null) request.getContext().getContextManager().doBeforeBody(request, this); // No action.. No revision No revision 1.8.2.3 +13 -0 jakarta-tomcat/src/share/org/apache/tomcat/facade/Attic/RequestDispatcherImpl.java Index: RequestDispatcherImpl.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/facade/Attic/RequestDispatcherImpl.java,v retrieving revision 1.8.2.2 retrieving revision 1.8.2.3 diff -u -r1.8.2.2 -r1.8.2.3 --- RequestDispatcherImpl.java 2000/08/25 21:48:52 1.8.2.2 +++ RequestDispatcherImpl.java 2000/11/07 03:16:48 1.8.2.3 @@ -208,6 +208,19 @@ return; } + // Add an unspecified response.flushBuffer() call to work around + // a fundamental problem in the way that the session interceptor + // works. If we do not do this, the session cookie gets dropped (!) + // if the first flush of the buffer happens inside an included + // servlet. This occurs because the session interceptor uses the + // normal response.addHeader() method to add the cookie -- but such + // header changes are suppressed inside an included servlet. + // (Reference: BugRat bug report #316) + // + // NOTE: This *must* be done before the include flag is set for + // this request! + response.flushBuffer(); + // Implement the spec that "no changes in response, only write" // can also be done by setting the response to 0.9 mode // IncludedResponse iResponse = new IncludedResponse(realResponse); No revision No revision 1.11.2.1 +5 -3 jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpResponseAdapter.java Index: HttpResponseAdapter.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpResponseAdapter.java,v retrieving revision 1.11 retrieving revision 1.11.2.1 diff -u -r1.11 -r1.11.2.1 --- HttpResponseAdapter.java 2000/05/24 16:34:15 1.11 +++ HttpResponseAdapter.java 2000/11/07 03:16:50 1.11.2.1 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpResponseAdapter.java,v 1.11 2000/05/24 16:34:15 costin Exp $ - * $Revision: 1.11 $ - * $Date: 2000/05/24 16:34:15 $ + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpResponseAdapter.java,v 1.11.2.1 2000/11/07 03:16:50 craigmcc Exp $ + * $Revision: 1.11.2.1 $ + * $Date: 2000/11/07 03:16:50 $ * * ==================================================================== * @@ -102,6 +102,7 @@ static final byte CRLF[]= { (byte)'\r', (byte)'\n' }; public void endHeaders() throws IOException { + super.endHeaders(); sendStatus( status, ResponseImpl.getMessage( status )); @@ -128,6 +129,7 @@ HTTP response is the status line */ protected void sendStatus( int status, String message ) throws IOException { + printHead("HTTP/1.0 "); printHead(String.valueOf(status)); if(message!=null) {