You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by cr...@locus.apache.org on 2000/06/23 03:38:31 UTC
cvs commit: jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core ApplicationDispatcher.java
craigmcc 00/06/22 18:38:31
Modified: proposals/catalina/src/share/org/apache/tomcat Response.java
proposals/catalina/src/share/org/apache/tomcat/connector
HttpResponseBase.java ResponseBase.java
proposals/catalina/src/share/org/apache/tomcat/core
ApplicationDispatcher.java
Log:
Explicitly implement the Servlet API 2.2 constraint in Section 8.3 that
disallows included servlets from modifying any headers in the response.
Also, removed a response.flushBuffer that we were doing inside the
include() method to enforce this constraint in a half-assed way.
Now we're down to one Watchdog test failure on Catalina ...
Revision Changes Path
1.9 +19 -4 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Response.java
Index: Response.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Response.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Response.java 2000/05/30 21:29:42 1.8
+++ Response.java 2000/06/23 01:38:28 1.9
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Response.java,v 1.8 2000/05/30 21:29:42 craigmcc Exp $
- * $Revision: 1.8 $
- * $Date: 2000/05/30 21:29:42 $
+ * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Response.java,v 1.9 2000/06/23 01:38:28 craigmcc Exp $
+ * $Revision: 1.9 $
+ * $Date: 2000/06/23 01:38:28 $
*
* ====================================================================
*
@@ -80,7 +80,7 @@
* based on the processing of a corresponding <code>Request</code>.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.8 $ $Date: 2000/05/30 21:29:42 $
+ * @version $Revision: 1.9 $ $Date: 2000/06/23 01:38:28 $
*/
public interface Response {
@@ -122,6 +122,21 @@
* @param context The associated Context
*/
public void setContext(Context context);
+
+
+ /**
+ * Return the "processing inside an include" flag.
+ */
+ public boolean getIncluded();
+
+
+ /**
+ * Set the "processing inside an include" flag.
+ *
+ * @param included <code>true</code> if we are currently inside a
+ * RequestDispatcher.include(), else <code>false</code>
+ */
+ public void setIncluded(boolean included);
/**
1.11 +56 -4 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/HttpResponseBase.java
Index: HttpResponseBase.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/HttpResponseBase.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- HttpResponseBase.java 2000/06/22 00:19:03 1.10
+++ HttpResponseBase.java 2000/06/23 01:38:29 1.11
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/HttpResponseBase.java,v 1.10 2000/06/22 00:19:03 craigmcc Exp $
- * $Revision: 1.10 $
- * $Date: 2000/06/22 00:19:03 $
+ * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/HttpResponseBase.java,v 1.11 2000/06/23 01:38:29 craigmcc Exp $
+ * $Revision: 1.11 $
+ * $Date: 2000/06/23 01:38:29 $
*
* ====================================================================
*
@@ -94,7 +94,7 @@
* methods need to be implemented.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.10 $ $Date: 2000/06/22 00:19:03 $
+ * @version $Revision: 1.11 $ $Date: 2000/06/23 01:38:29 $
*/
public class HttpResponseBase
@@ -578,6 +578,9 @@
*/
public void reset() {
+ if (included)
+ return; // Ignore any call from an included servlet
+
super.reset();
cookies.removeAllElements();
headers.clear();
@@ -596,6 +599,10 @@
if (isCommitted())
return;
+
+ if (included)
+ return; // Ignore any call from an included servlet
+
super.setContentLength(length);
}
@@ -611,6 +618,10 @@
if (isCommitted())
return;
+
+ if (included)
+ return; // Ignore any call from an included servlet
+
super.setContentType(type);
}
@@ -626,6 +637,10 @@
if (isCommitted())
return;
+
+ if (included)
+ return; // Ignore any call from an included servlet
+
super.setLocale(locale);
String language = locale.getLanguage();
if ((language != null) && (language.length() > 0))
@@ -649,6 +664,10 @@
if (isCommitted())
return;
+
+ if (included)
+ return; // Ignore any call from an included servlet
+
if (cookie != null)
cookies.addElement(cookie);
@@ -665,6 +684,10 @@
if (isCommitted())
return;
+
+ if (included)
+ return; // Ignore any call from an included servlet
+
addHeader(name, format.format(new Date(value)));
}
@@ -680,6 +703,10 @@
if (isCommitted())
return;
+
+ if (included)
+ return; // Ignore any call from an included servlet
+
Vector values = (Vector) headers.get(name);
if (values != null)
values.addElement(value);
@@ -699,6 +726,10 @@
if (isCommitted())
return;
+
+ if (included)
+ return; // Ignore any call from an included servlet
+
addHeader(name, "" + value);
}
@@ -817,6 +848,9 @@
throw new IllegalStateException
(sm.getString("httpResponseBase.sendError.ise"));
+ if (included)
+ return; // Ignore any call from an included servlet
+
// Record the status code and message.
this.status = status;
this.message = message;
@@ -854,6 +888,9 @@
throw new IllegalStateException
(sm.getString("httpResponseBase.sendRedirect.ise"));
+ if (included)
+ return; // Ignore any call from an included servlet
+
reset();
setStatus(SC_MOVED_TEMPORARILY, location);
setHeader("Location", location);
@@ -872,6 +909,10 @@
if (isCommitted())
return;
+
+ if (included)
+ return; // Ignore any call from an included servlet
+
setHeader(name, format.format(new Date(value)));
}
@@ -887,6 +928,10 @@
if (isCommitted())
return;
+
+ if (included)
+ return; // Ignore any call from an included servlet
+
Vector values = new Vector();
values.addElement(value);
String match = name.toLowerCase();
@@ -917,6 +962,10 @@
if (isCommitted())
return;
+
+ if (included)
+ return; // Ignore any call from an included servlet
+
setHeader(name, "" + value);
}
@@ -945,6 +994,9 @@
* parameter.
*/
public void setStatus(int status, String message) {
+
+ if (included)
+ return; // Ignore any call from an included servlet
this.status = status;
this.message = message;
1.14 +49 -4 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/ResponseBase.java
Index: ResponseBase.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/ResponseBase.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- ResponseBase.java 2000/06/22 06:15:42 1.13
+++ ResponseBase.java 2000/06/23 01:38:29 1.14
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/ResponseBase.java,v 1.13 2000/06/22 06:15:42 craigmcc Exp $
- * $Revision: 1.13 $
- * $Date: 2000/06/22 06:15:42 $
+ * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/ResponseBase.java,v 1.14 2000/06/23 01:38:29 craigmcc Exp $
+ * $Revision: 1.14 $
+ * $Date: 2000/06/23 01:38:29 $
*
* ====================================================================
*
@@ -87,7 +87,7 @@
* the connector-specific methods need to be implemented.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.13 $ $Date: 2000/06/22 06:15:42 $
+ * @version $Revision: 1.14 $ $Date: 2000/06/23 01:38:29 $
*/
public abstract class ResponseBase
@@ -152,6 +152,12 @@
/**
+ * Are we currently processing inside a RequestDispatcher.include()?
+ */
+ protected boolean included = false;
+
+
+ /**
* Descriptive information about this Response implementation.
*/
protected static final String info =
@@ -256,6 +262,29 @@
/**
+ * Return the "processing inside an include" flag.
+ */
+ public boolean getIncluded() {
+
+ return (this.included);
+
+ }
+
+
+ /**
+ * Set the "processing inside an include" flag.
+ *
+ * @param included <code>true</code> if we are currently inside a
+ * RequestDispatcher.include(), else <code>false</code>
+ */
+ public void setIncluded(boolean included) {
+
+ this.included = included;
+
+ }
+
+
+ /**
* Return descriptive information about this Response implementation and
* the corresponding version number, in the format
* <code><description>/<version></code>.
@@ -420,6 +449,7 @@
contentType = "text/plain";
context = null;
encoding = "ISO-8859-1";
+ included = false;
locale = Locale.getDefault();
output = null;
request = null;
@@ -609,6 +639,9 @@
throw new IllegalStateException
(sm.getString("responseBase.reset.ise"));
+ if (included)
+ return; // Ignore any call from an included servlet
+
if (stream != null)
((ResponseStream) stream).reset();
bufferCount = 0;
@@ -648,6 +681,10 @@
if (isCommitted())
return;
+
+ if (included)
+ return; // Ignore any call from an included servlet
+
this.contentLength = length;
}
@@ -662,6 +699,10 @@
if (isCommitted())
return;
+
+ if (included)
+ return; // Ignore any call from an included servlet
+
this.contentType = type;
if (type.indexOf(";") >= 0) {
encoding = RequestUtil.parseCharacterEncoding(type);
@@ -682,6 +723,10 @@
if (isCommitted())
return;
+
+ if (included)
+ return; // Ignore any call from an included servlet
+
this.locale = locale;
; // FIXME -- set encoding based on the locale!
1.8 +17 -4 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ApplicationDispatcher.java
Index: ApplicationDispatcher.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ApplicationDispatcher.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ApplicationDispatcher.java 2000/06/23 00:58:47 1.7
+++ ApplicationDispatcher.java 2000/06/23 01:38:30 1.8
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ApplicationDispatcher.java,v 1.7 2000/06/23 00:58:47 craigmcc Exp $
- * $Revision: 1.7 $
- * $Date: 2000/06/23 00:58:47 $
+ * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ApplicationDispatcher.java,v 1.8 2000/06/23 01:38:30 craigmcc Exp $
+ * $Revision: 1.8 $
+ * $Date: 2000/06/23 01:38:30 $
*
* ====================================================================
*
@@ -93,7 +93,7 @@
* from this resource.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.7 $ $Date: 2000/06/23 00:58:47 $
+ * @version $Revision: 1.8 $ $Date: 2000/06/23 01:38:30 $
*/
final class ApplicationDispatcher
@@ -337,6 +337,7 @@
HttpResponse hresponse = null;
if (response instanceof HttpResponse)
hresponse = (HttpResponse) response;
+ boolean oldIncluded = sresponse.getIncluded();
// Handle a non-HTTP include by passing on the existing request and response
if ((hrequest == null) || (hresponse == null)) {
@@ -344,11 +345,15 @@
log(" Non-HTTP Include");
try {
wrapper.invoke(srequest, sresponse);
+ sresponse.setIncluded(oldIncluded);
} catch (IOException e) {
+ sresponse.setIncluded(oldIncluded);
throw e;
} catch (ServletException e) {
+ sresponse.setIncluded(oldIncluded);
throw e;
} catch (Throwable t) {
+ sresponse.setIncluded(oldIncluded);
throw new ServletException
(sm.getString("applicationDispatcher.include.throw"), t);
}
@@ -361,11 +366,15 @@
log(" Named Dispatcher Include");
try {
wrapper.invoke(hrequest, hresponse);
+ sresponse.setIncluded(oldIncluded);
} catch (IOException e) {
+ sresponse.setIncluded(oldIncluded);
throw e;
} catch (ServletException e) {
+ sresponse.setIncluded(oldIncluded);
throw e;
} catch (Throwable t) {
+ sresponse.setIncluded(oldIncluded);
throw new ServletException
(sm.getString("applicationDispatcher.include.throw"), t);
}
@@ -414,11 +423,15 @@
try {
wrapper.invoke(wrequest, hresponse);
+ sresponse.setIncluded(oldIncluded);
} catch (IOException e) {
+ sresponse.setIncluded(oldIncluded);
throw e;
} catch (ServletException e) {
+ sresponse.setIncluded(oldIncluded);
throw e;
} catch (Throwable t) {
+ sresponse.setIncluded(oldIncluded);
throw new ServletException
(sm.getString("applicationDispatcher.include.throw"), t);
}