kinman 01/12/04 16:19:18
Modified: jasper/src/share/org/apache/jasper Constants.java
jasper/src/share/org/apache/jasper/compiler
IncludeGenerator.java
jasper/src/share/org/apache/jasper/runtime
BodyContentImpl.java JspRuntimeLibrary.java
JspWriterImpl.java PageContextImpl.java
Log:
-- Throw IOException when a write or flush is invoked after a JspWriter
or BodyConent has been closed.
-- Make sure that the codes after a <jsp:include> that contains a
<jsp:forwards> are not executed. An attribute is set in the request
object that record that a 'forward' has been made, which is then
checked after the <jsp:include>
-- Make sure that the response object sent to a 'forward'ed page is not
a wrapper, such as one over a BodyContent. This also ensure that
an error page is always displayed.
-- In JspRuntimeLibrary.include, don't flush a BodyContent. This patch
was supplied by [EMAIL PROTECTED]
Revision Changes Path
1.14 +1 -0
jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/Constants.java
Index: Constants.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/Constants.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- Constants.java 2001/07/23 19:57:32 1.13
+++ Constants.java 2001/12/05 00:19:18 1.14
@@ -149,6 +149,7 @@
public static final String INC_REQUEST_URI =
"javax.servlet.include.request_uri";
public static final String INC_SERVLET_PATH =
"javax.servlet.include.servlet_path";
public static final String TMP_DIR = "javax.servlet.context.tempdir";
+ public static final String FORWARD_SEEN = "javax.servlet.forward.seen";
/**
* Public Id and the Resource path (of the cached copy)
1.9 +10 -3
jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/IncludeGenerator.java
Index: IncludeGenerator.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/IncludeGenerator.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- IncludeGenerator.java 2001/08/14 23:28:55 1.8
+++ IncludeGenerator.java 2001/12/05 00:19:18 1.9
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/IncludeGenerator.java,v
1.8 2001/08/14 23:28:55 craigmcc Exp $
- * $Revision: 1.8 $
- * $Date: 2001/08/14 23:28:55 $
+ * $Header:
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/IncludeGenerator.java,v
1.9 2001/12/05 00:19:18 kinman Exp $
+ * $Revision: 1.9 $
+ * $Date: 2001/12/05 00:19:18 $
*
* ====================================================================
*
@@ -186,6 +186,13 @@
writer.println("JspRuntimeLibrary.include(request, response, " +
JspUtil.getExpr(page, isXml) + " + _jspx_qStr, " +
"out, " + flush + ");");
+
+ // If there is a forward in the include chain, quit.
+ writer.println("if (\"true\".equals(request.getAttribute(\"" +
+ Constants.FORWARD_SEEN + "\")))");
+ writer.pushIndent();
+ writer.println("return;");
+ writer.popIndent();
writer.popIndent();
writer.println("}");
1.4 +12 -7
jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/runtime/BodyContentImpl.java
Index: BodyContentImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/runtime/BodyContentImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- BodyContentImpl.java 2001/11/29 17:17:31 1.3
+++ BodyContentImpl.java 2001/12/05 00:19:18 1.4
@@ -82,19 +82,25 @@
protected int bufferSize = Constants.DEFAULT_BUFFER_SIZE;
private int nextChar;
static String lineSeparator = System.getProperty("line.separator");
+ private boolean closed = false;
-
public BodyContentImpl (JspWriter writer) {
super(writer);
cb = new char[bufferSize];
nextChar = 0;
}
+ private void ensureOpen() throws IOException {
+ if (closed)
+ throw new IOException("Stream closed");
+ }
+
/**
* Write a single character.
*
*/
public void write(int c) throws IOException {
+ ensureOpen();
synchronized (lock) {
if (nextChar >= bufferSize) {
reAllocBuff (0);
@@ -141,6 +147,7 @@
public void write(char cbuf[], int off, int len)
throws IOException
{
+ ensureOpen();
synchronized (lock) {
if ((off < 0) || (off > cbuf.length) || (len < 0) ||
@@ -175,6 +182,7 @@
*
*/
public void write(String s, int off, int len) throws IOException {
+ ensureOpen();
synchronized (lock) {
if (len >= bufferSize - nextChar)
reAllocBuff(len);
@@ -202,9 +210,7 @@
*/
public void newLine() throws IOException {
- synchronized (lock) {
- write(lineSeparator);
- }
+ write(lineSeparator);
}
/**
@@ -520,9 +526,8 @@
*/
public void close() throws IOException {
- synchronized (lock) {
- cb = null;
- }
+ cb = null;
+ closed = true;
}
/**
1.9 +6 -5
jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/runtime/JspRuntimeLibrary.java
Index: JspRuntimeLibrary.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/runtime/JspRuntimeLibrary.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- JspRuntimeLibrary.java 2001/08/14 23:28:55 1.8
+++ JspRuntimeLibrary.java 2001/12/05 00:19:18 1.9
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/runtime/JspRuntimeLibrary.java,v
1.8 2001/08/14 23:28:55 craigmcc Exp $
- * $Revision: 1.8 $
- * $Date: 2001/08/14 23:28:55 $
+ * $Header:
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/runtime/JspRuntimeLibrary.java,v
1.9 2001/12/05 00:19:18 kinman Exp $
+ * $Revision: 1.9 $
+ * $Date: 2001/12/05 00:19:18 $
*
* ====================================================================
*
@@ -89,6 +89,7 @@
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspWriter;
+import javax.servlet.jsp.tagext.BodyContent;
import org.apache.jasper.JasperException;
import org.apache.jasper.Constants;
@@ -803,7 +804,7 @@
boolean flush)
throws IOException, ServletException {
- if (flush)
+ if (flush && !(out instanceof BodyContent))
out.flush();
// FIXME - It is tempting to use request.getRequestDispatcher() to
@@ -815,10 +816,10 @@
String resourcePath = getContextRelativePath(request, relativePath);
RequestDispatcher rd = request.getRequestDispatcher(resourcePath);
+
rd.include(request,
new ServletResponseWrapperInclude(response, out));
}
-
}
1.3 +10 -8
jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/runtime/JspWriterImpl.java
Index: JspWriterImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/runtime/JspWriterImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JspWriterImpl.java 2001/11/29 17:17:31 1.2
+++ JspWriterImpl.java 2001/12/05 00:19:18 1.3
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/runtime/JspWriterImpl.java,v
1.2 2001/11/29 17:17:31 remm Exp $
- * $Revision: 1.2 $
- * $Date: 2001/11/29 17:17:31 $
+ * $Header:
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/runtime/JspWriterImpl.java,v
1.3 2001/12/05 00:19:18 kinman Exp $
+ * $Revision: 1.3 $
+ * $Date: 2001/12/05 00:19:18 $
*
* ====================================================================
*
@@ -88,7 +88,6 @@
*/
public class JspWriterImpl extends JspWriter {
-
protected Writer out;
protected ServletResponse response;
@@ -99,7 +98,8 @@
protected static int defaultCharBufferSize = Constants.DEFAULT_BUFFER_SIZE;
protected boolean flushed = false;
-
+ protected boolean closed = false;
+
public JspWriterImpl() {
super( defaultCharBufferSize, true );
}
@@ -155,7 +155,7 @@
ensureOpen();
if (nextChar == 0)
return;
- initOut();
+ initOut();
out.write(cb, 0, nextChar);
nextChar = 0;
}
@@ -217,12 +217,14 @@
*/
public void close() throws IOException {
synchronized (lock) {
- if (response == null)
+ if (response == null || closed)
+ // multiple calls to close is OK
return;
flush();
if (out != null)
out.close();
out = null;
+ closed = true;
// cb = null;
}
}
@@ -236,7 +238,7 @@
/** check to make sure that the stream has not been closed */
protected void ensureOpen() throws IOException {
- if (response == null)
+ if (response == null || closed)
throw new IOException("Stream closed");
}
1.14 +9 -4
jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/runtime/PageContextImpl.java
Index: PageContextImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/runtime/PageContextImpl.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- PageContextImpl.java 2001/08/14 23:28:55 1.13
+++ PageContextImpl.java 2001/12/05 00:19:18 1.14
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/runtime/PageContextImpl.java,v
1.13 2001/08/14 23:28:55 craigmcc Exp $
- * $Revision: 1.13 $
- * $Date: 2001/08/14 23:28:55 $
+ * $Header:
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/runtime/PageContextImpl.java,v
1.14 2001/12/05 00:19:18 kinman Exp $
+ * $Revision: 1.14 $
+ * $Date: 2001/12/05 00:19:18 $
*
* ====================================================================
*
@@ -79,8 +79,8 @@
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
-
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.JspFactory;
import javax.servlet.jsp.JspWriter;
@@ -400,6 +400,10 @@
public void forward(String relativeUrlPath)
throws ServletException, IOException
{
+ // Make sure that the response object is not the wrapper for include
+ while (response instanceof HttpServletResponseWrapper)
+ response = ((HttpServletResponseWrapper)response).getResponse();
+
String path = getAbsolutePathRelativeToContext(relativeUrlPath);
String includeUri
= (String) request.getAttribute(Constants.INC_SERVLET_PATH);
@@ -410,6 +414,7 @@
} finally {
if (includeUri != null)
request.setAttribute(Constants.INC_SERVLET_PATH, includeUri);
+ request.setAttribute(Constants.FORWARD_SEEN, "true");
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>