remm 01/10/04 12:26:57 Modified: catalina/src/share/org/apache/catalina/connector Tag: tomcat_40_branch HttpResponseBase.java HttpResponseFacade.java ResponseBase.java ResponseFacade.java ResponseStream.java Log: - Merge a variety of fixes and small feature additions which have been made and debugged in the HEAD branch, including: - Removal of Jasper loader (merged with the shared loader). - Fixes a lot of spec complaince issue regarding the commit state of the response when using forwards, sendError or sendRedirect. - Fixes cache consistency issues for static resource serving. - Adds content caching for static resources (that's linked to the bugfix mentioned just above). - Merge enhanced error reporting and error page dispatching (which will be able to display error pages for most errors returned from the pipeline - like the 401 and 403 returned by the authenticator). - Merge the fixes for all the other more recent bugfixes that have been fixed in the HEAD branch. - Passes all tester and Watchdog tests. - Merge a variety of small enhancements to the build scripts which have been made in the HEAD branch. Revision Changes Path No revision No revision 1.37.2.1 +4 -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.37 retrieving revision 1.37.2.1 diff -u -r1.37 -r1.37.2.1 --- HttpResponseBase.java 2001/08/24 23:06:08 1.37 +++ HttpResponseBase.java 2001/10/04 19:26:57 1.37.2.1 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/HttpResponseBase.java,v 1.37 2001/08/24 23:06:08 craigmcc Exp $ - * $Revision: 1.37 $ - * $Date: 2001/08/24 23:06:08 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/HttpResponseBase.java,v 1.37.2.1 2001/10/04 19:26:57 remm Exp $ + * $Revision: 1.37.2.1 $ + * $Date: 2001/10/04 19:26:57 $ * * ==================================================================== * @@ -101,7 +101,7 @@ * * @author Craig R. McClanahan * @author Remy Maucherat - * @version $Revision: 1.37 $ $Date: 2001/08/24 23:06:08 $ + * @version $Revision: 1.37.2.1 $ $Date: 2001/10/04 19:26:57 $ */ public class HttpResponseBase 1.2.2.1 +73 -4 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/HttpResponseFacade.java Index: HttpResponseFacade.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/HttpResponseFacade.java,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -u -r1.2 -r1.2.2.1 --- HttpResponseFacade.java 2001/07/22 20:25:06 1.2 +++ HttpResponseFacade.java 2001/10/04 19:26:57 1.2.2.1 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/HttpResponseFacade.java,v 1.2 2001/07/22 20:25:06 pier Exp $ - * $Revision: 1.2 $ - * $Date: 2001/07/22 20:25:06 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/HttpResponseFacade.java,v 1.2.2.1 2001/10/04 19:26:57 remm Exp $ + * $Revision: 1.2.2.1 $ + * $Date: 2001/10/04 19:26:57 $ * * ==================================================================== * @@ -79,7 +79,7 @@ * * @author Remy Maucherat * @author Craig R. McClanahan - * @version $Revision: 1.2 $ $Date: 2001/07/22 20:25:06 $ + * @version $Revision: 1.2.2.1 $ $Date: 2001/10/04 19:26:57 $ */ public final class HttpResponseFacade @@ -104,7 +104,12 @@ public void addCookie(Cookie cookie) { + + if (isCommitted()) + return; + ((HttpServletResponse) response).addCookie(cookie); + } @@ -135,59 +140,123 @@ public void sendError(int sc, String msg) throws IOException { + + if (isCommitted()) + throw new IllegalStateException + (/*sm.getString("responseBase.reset.ise")*/); + + resp.setAppCommitted(true); + ((HttpServletResponse) response).sendError(sc, msg); + } public void sendError(int sc) throws IOException { + + if (isCommitted()) + throw new IllegalStateException + (/*sm.getString("responseBase.reset.ise")*/); + + resp.setAppCommitted(true); + ((HttpServletResponse) response).sendError(sc); + } public void sendRedirect(String location) throws IOException { + + if (isCommitted()) + throw new IllegalStateException + (/*sm.getString("responseBase.reset.ise")*/); + + resp.setAppCommitted(true); + ((HttpServletResponse) response).sendRedirect(location); + } public void setDateHeader(String name, long date) { + + if (isCommitted()) + return; + ((HttpServletResponse) response).setDateHeader(name, date); + } public void addDateHeader(String name, long date) { + + if (isCommitted()) + return; + ((HttpServletResponse) response).addDateHeader(name, date); + } public void setHeader(String name, String value) { + + if (isCommitted()) + return; + ((HttpServletResponse) response).setHeader(name, value); + } public void addHeader(String name, String value) { + + if (isCommitted()) + return; + ((HttpServletResponse) response).addHeader(name, value); + } public void setIntHeader(String name, int value) { + + if (isCommitted()) + return; + ((HttpServletResponse) response).setIntHeader(name, value); + } public void addIntHeader(String name, int value) { + + if (isCommitted()) + return; + ((HttpServletResponse) response).addIntHeader(name, value); + } public void setStatus(int sc) { + + if (isCommitted()) + return; + ((HttpServletResponse) response).setStatus(sc); + } public void setStatus(int sc, String sm) { + + if (isCommitted()) + return; + ((HttpServletResponse) response).setStatus(sc, sm); + } 1.16.2.1 +73 -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.16 retrieving revision 1.16.2.1 diff -u -r1.16 -r1.16.2.1 --- ResponseBase.java 2001/08/02 01:43:58 1.16 +++ ResponseBase.java 2001/10/04 19:26:57 1.16.2.1 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/ResponseBase.java,v 1.16 2001/08/02 01:43:58 remm Exp $ - * $Revision: 1.16 $ - * $Date: 2001/08/02 01:43:58 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/ResponseBase.java,v 1.16.2.1 2001/10/04 19:26:57 remm Exp $ + * $Revision: 1.16.2.1 $ + * $Date: 2001/10/04 19:26:57 $ * * ==================================================================== * @@ -88,7 +88,8 @@ * the connector-specific methods need to be implemented. * * @author Craig R. McClanahan - * @version $Revision: 1.16 $ $Date: 2001/08/02 01:43:58 $ + * @author Remy Maucherat + * @version $Revision: 1.16.2.1 $ $Date: 2001/10/04 19:26:57 $ */ public abstract class ResponseBase @@ -99,6 +100,12 @@ /** + * Has this response been committed by the application yet? + */ + protected boolean appCommitted = false; + + + /** * The buffer through which all of our output bytes are passed. */ protected byte[] buffer = new byte[1024]; @@ -204,6 +211,12 @@ /** + * Has this response output been suspended? + */ + protected boolean suspended = false; + + + /** * The PrintWriter that has been returned by * <code>getWriter()</code>, if any. */ @@ -220,6 +233,26 @@ /** + * Set the application commit flag. + */ + public void setAppCommitted(boolean appCommitted) { + + this.appCommitted = appCommitted; + + } + + + /** + * Application commit flag accessor. + */ + public boolean isAppCommitted() { + + return (this.appCommitted || this.committed); + + } + + + /** * Return the Connector through which this Response will be transmitted. */ public Connector getConnector() { @@ -365,6 +398,28 @@ /** + * Set the suspended flag. + */ + public void setSuspended(boolean suspended) { + + this.suspended = suspended; + if (stream != null) + ((ResponseStream) stream).setSuspended(suspended); + + } + + + /** + * Suspended flag accessor. + */ + public boolean isSuspended() { + + return (this.suspended); + + } + + + /** * Set the error flag. */ public void setError() { @@ -504,6 +559,8 @@ // buffer is NOT reset when recycling bufferCount = 0; committed = false; + appCommitted = false; + suspended = false; // connector is NOT reset when recycling contentCount = 0; contentLength = -1; @@ -533,6 +590,10 @@ */ public void write(int b) throws IOException { + if (suspended) + throw new IOException + (sm.getString("responseBase.write.suspended")); + if (bufferCount >= buffer.length) flushBuffer(); buffer[bufferCount++] = (byte) b; @@ -551,6 +612,10 @@ */ public void write(byte b[]) throws IOException { + if (suspended) + throw new IOException + (sm.getString("responseBase.write.suspended")); + write(b, 0, b.length); } @@ -568,6 +633,10 @@ * @exception IOException if an input/output error occurs */ public void write(byte b[], int off, int len) throws IOException { + + if (suspended) + throw new IOException + (sm.getString("responseBase.write.suspended")); // If the whole thing fits in the buffer, just put it there if (len == 0) 1.2.2.1 +81 -5 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/ResponseFacade.java Index: ResponseFacade.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/ResponseFacade.java,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -u -r1.2 -r1.2.2.1 --- ResponseFacade.java 2001/07/22 20:25:06 1.2 +++ ResponseFacade.java 2001/10/04 19:26:57 1.2.2.1 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/ResponseFacade.java,v 1.2 2001/07/22 20:25:06 pier Exp $ - * $Revision: 1.2 $ - * $Date: 2001/07/22 20:25:06 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/ResponseFacade.java,v 1.2.2.1 2001/10/04 19:26:57 remm Exp $ + * $Revision: 1.2.2.1 $ + * $Date: 2001/10/04 19:26:57 $ * * ==================================================================== * @@ -80,7 +80,7 @@ * object. All methods are delegated to the wrapped response. * * @author Remy Maucherat - * @version $Revision: 1.2 $ $Date: 2001/07/22 20:25:06 $ + * @version $Revision: 1.2.2.1 $ $Date: 2001/10/04 19:26:57 $ */ public class ResponseFacade implements ServletResponse { @@ -95,6 +95,7 @@ * @param response The response to be wrapped */ public ResponseFacade(Response response) { + this.resp = response; this.response = (ServletResponse) response; } @@ -108,6 +109,29 @@ protected ServletResponse response = null; + /** + * The wrapped response. + */ + protected Response resp = null; + + + // --------------------------------------------------------- Public Methods + + + public void finish() { + + resp.setSuspended(true); + + } + + + public boolean isFinished() { + + return resp.isSuspended(); + + } + + // ------------------------------------------------ ServletResponse Methods @@ -118,28 +142,56 @@ public ServletOutputStream getOutputStream() throws IOException { + + if (isFinished()) + throw new IllegalStateException + (/*sm.getString("responseFacade.finished")*/); + return response.getOutputStream(); + } public PrintWriter getWriter() throws IOException { + + if (isFinished()) + throw new IllegalStateException + (/*sm.getString("responseFacade.finished")*/); + return response.getWriter(); + } public void setContentLength(int len) { + + if (isCommitted()) + return; + response.setContentLength(len); + } public void setContentType(String type) { + + if (isCommitted()) + return; + response.setContentType(type); + } public void setBufferSize(int size) { + + if (isCommitted()) + throw new IllegalStateException + (/*sm.getString("responseBase.reset.ise")*/); + response.setBufferSize(size); + } @@ -150,26 +202,50 @@ public void flushBuffer() throws IOException { + + if (isFinished()) + throw new IllegalStateException + (/*sm.getString("responseFacade.finished")*/); + + resp.setAppCommitted(true); + response.flushBuffer(); + } public void resetBuffer() { + + if (isCommitted()) + throw new IllegalStateException + (/*sm.getString("responseBase.reset.ise")*/); + response.resetBuffer(); + } public boolean isCommitted() { - return response.isCommitted(); + return (resp.isAppCommitted()); } public void reset() { + + if (isCommitted()) + throw new IllegalStateException + (/*sm.getString("responseBase.reset.ise")*/); + response.reset(); + } public void setLocale(Locale loc) { + + if (isCommitted()) + return; + response.setLocale(loc); } 1.4.2.1 +48 -4 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/ResponseStream.java Index: ResponseStream.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/ResponseStream.java,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -r1.4 -r1.4.2.1 --- ResponseStream.java 2001/07/22 20:25:06 1.4 +++ ResponseStream.java 2001/10/04 19:26:57 1.4.2.1 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/ResponseStream.java,v 1.4 2001/07/22 20:25:06 pier Exp $ - * $Revision: 1.4 $ - * $Date: 2001/07/22 20:25:06 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/ResponseStream.java,v 1.4.2.1 2001/10/04 19:26:57 remm Exp $ + * $Revision: 1.4.2.1 $ + * $Date: 2001/10/04 19:26:57 $ * * ==================================================================== * @@ -79,7 +79,7 @@ * enforce not writing more than that many bytes on the underlying stream. * * @author Craig R. McClanahan - * @version $Revision: 1.4 $ $Date: 2001/07/22 20:25:06 $ + * @version $Revision: 1.4.2.1 $ $Date: 2001/10/04 19:26:57 $ */ public class ResponseStream @@ -102,6 +102,7 @@ count = 0; this.response = response; this.stream = response.getStream(); + this.suspended = response.isSuspended(); } @@ -153,6 +154,12 @@ protected OutputStream stream = null; + /** + * Has this response output been suspended? + */ + protected boolean suspended = false; + + // ------------------------------------------------------------- Properties @@ -178,6 +185,26 @@ } + /** + * Set the suspended flag. + */ + void setSuspended(boolean suspended) { + + this.suspended = suspended; + + } + + + /** + * Suspended flag accessor. + */ + boolean isSuspended() { + + return (this.suspended); + + } + + // --------------------------------------------------------- Public Methods @@ -187,6 +214,10 @@ */ public void close() throws IOException { + if (suspended) + throw new IOException + (sm.getString("responseStream.suspended")); + if (closed) throw new IOException(sm.getString("responseStream.close.closed")); @@ -202,6 +233,10 @@ */ public void flush() throws IOException { + if (suspended) + throw new IOException + (sm.getString("responseStream.suspended")); + if (closed) throw new IOException(sm.getString("responseStream.flush.closed")); @@ -220,6 +255,9 @@ */ public void write(int b) throws IOException { + if (suspended) + return; + if (closed) throw new IOException(sm.getString("responseStream.write.closed")); @@ -242,6 +280,9 @@ */ public void write(byte b[]) throws IOException { + if (suspended) + return; + write(b, 0, b.length); } @@ -258,6 +299,9 @@ * @exception IOException if an input/output error occurs */ public void write(byte b[], int off, int len) throws IOException { + + if (suspended) + return; if (closed) throw new IOException(sm.getString("responseStream.write.closed"));