You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2001/09/28 18:53:49 UTC
cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector HttpResponseFacade.java ResponseBase.java ResponseFacade.java
remm 01/09/28 09:53:49
Modified: catalina/src/share/org/apache/catalina/connector
HttpResponseFacade.java ResponseBase.java
ResponseFacade.java
Log:
- Instead of having a recycleFacade method, use two flags :
- application commit
- suspend
- The new suspend flag is used to simulate the closure of the response object
from the application standpoint.
Revision Changes Path
1.5 +7 -7 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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- HttpResponseFacade.java 2001/09/28 04:39:01 1.4
+++ HttpResponseFacade.java 2001/09/28 16:53:49 1.5
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/HttpResponseFacade.java,v 1.4 2001/09/28 04:39:01 remm Exp $
- * $Revision: 1.4 $
- * $Date: 2001/09/28 04:39:01 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/HttpResponseFacade.java,v 1.5 2001/09/28 16:53:49 remm Exp $
+ * $Revision: 1.5 $
+ * $Date: 2001/09/28 16:53:49 $
*
* ====================================================================
*
@@ -79,7 +79,7 @@
*
* @author Remy Maucherat
* @author Craig R. McClanahan
- * @version $Revision: 1.4 $ $Date: 2001/09/28 04:39:01 $
+ * @version $Revision: 1.5 $ $Date: 2001/09/28 16:53:49 $
*/
public final class HttpResponseFacade
@@ -145,7 +145,7 @@
throw new IllegalStateException
(/*sm.getString("responseBase.reset.ise")*/);
- committed = true;
+ resp.setAppCommitted(true);
((HttpServletResponse) response).sendError(sc, msg);
@@ -159,7 +159,7 @@
throw new IllegalStateException
(/*sm.getString("responseBase.reset.ise")*/);
- committed = true;
+ resp.setAppCommitted(true);
((HttpServletResponse) response).sendError(sc);
@@ -173,7 +173,7 @@
throw new IllegalStateException
(/*sm.getString("responseBase.reset.ise")*/);
- committed = true;
+ resp.setAppCommitted(true);
((HttpServletResponse) response).sendRedirect(location);
1.18 +71 -13 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.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- ResponseBase.java 2001/09/27 00:58:38 1.17
+++ ResponseBase.java 2001/09/28 16:53:49 1.18
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/ResponseBase.java,v 1.17 2001/09/27 00:58:38 remm Exp $
- * $Revision: 1.17 $
- * $Date: 2001/09/27 00:58:38 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/ResponseBase.java,v 1.18 2001/09/28 16:53:49 remm Exp $
+ * $Revision: 1.18 $
+ * $Date: 2001/09/28 16:53:49 $
*
* ====================================================================
*
@@ -88,7 +88,8 @@
* the connector-specific methods need to be implemented.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.17 $ $Date: 2001/09/27 00:58:38 $
+ * @author Remy Maucherat
+ * @version $Revision: 1.18 $ $Date: 2001/09/28 16:53:49 $
*/
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,26 @@
/**
+ * Set the suspended flag.
+ */
+ public void setSuspended(boolean suspended) {
+
+ this.suspended = suspended;
+
+ }
+
+
+ /**
+ * Suspended flag accessor.
+ */
+ public boolean isSuspended() {
+
+ return (this.suspended);
+
+ }
+
+
+ /**
* Set the error flag.
*/
public void setError() {
@@ -496,14 +549,6 @@
/**
- * Recycle the facade object.
- */
- public void recycleFacade() {
- facade = new ResponseFacade(this);
- }
-
-
- /**
* Release all object references, and initialize instance variables, in
* preparation for reuse of this object.
*/
@@ -512,6 +557,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;
@@ -525,7 +572,6 @@
stream = null;
writer = null;
error = false;
- recycleFacade();
}
@@ -542,6 +588,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;
@@ -560,6 +610,10 @@
*/
public void write(byte b[]) throws IOException {
+ if (suspended)
+ throw new IOException
+ (sm.getString("responseBase.write.suspended"));
+
write(b, 0, b.length);
}
@@ -577,6 +631,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.4 +42 -9 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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ResponseFacade.java 2001/09/27 00:58:14 1.3
+++ ResponseFacade.java 2001/09/28 16:53:49 1.4
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/ResponseFacade.java,v 1.3 2001/09/27 00:58:14 remm Exp $
- * $Revision: 1.3 $
- * $Date: 2001/09/27 00:58:14 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/ResponseFacade.java,v 1.4 2001/09/28 16:53:49 remm Exp $
+ * $Revision: 1.4 $
+ * $Date: 2001/09/28 16:53:49 $
*
* ====================================================================
*
@@ -80,7 +80,7 @@
* object. All methods are delegated to the wrapped response.
*
* @author Remy Maucherat
- * @version $Revision: 1.3 $ $Date: 2001/09/27 00:58:14 $
+ * @version $Revision: 1.4 $ $Date: 2001/09/28 16:53:49 $
*/
public class ResponseFacade implements ServletResponse {
@@ -95,8 +95,8 @@
* @param response The response to be wrapped
*/
public ResponseFacade(Response response) {
+ this.resp = response;
this.response = (ServletResponse) response;
- committed = false;
}
@@ -110,11 +110,28 @@
/**
- * Application level commit.
+ * The wrapped response.
*/
- protected boolean committed = false;
+ protected Response resp = null;
+
+
+ // --------------------------------------------------------- Public Methods
+
+
+ public void finish() {
+
+ resp.setSuspended(true);
+ }
+
+
+ public boolean isFinished() {
+
+ return resp.isSuspended();
+
+ }
+
// ------------------------------------------------ ServletResponse Methods
@@ -125,13 +142,25 @@
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();
+
}
@@ -173,8 +202,12 @@
public void flushBuffer()
throws IOException {
+
+ if (isFinished())
+ throw new IllegalStateException
+ (/*sm.getString("responseFacade.finished")*/);
- committed = true;
+ resp.setAppCommitted(true);
response.flushBuffer();
@@ -193,7 +226,7 @@
public boolean isCommitted() {
- return (committed || response.isCommitted());
+ return (resp.isAppCommitted());
}