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...@apache.org on 2001/07/19 20:37:02 UTC
cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets InvokerHttpRequest.java InvokerServlet.java
craigmcc 01/07/19 11:37:02
Modified: catalina/src/share/org/apache/catalina/core
ApplicationDispatcher.java
catalina/src/share/org/apache/catalina/servlets
InvokerHttpRequest.java InvokerServlet.java
Log:
Correct an bad interaction between request dispatching and the invoker
servlet that was introduced in recent changes. These changes were
required by Servlet 2.3 PFD3 updates that disallowed the previous
request dispatcher implementation technique of wrapping the outermost
application request before calling the dispatched-to servlet.
These changes also fix the JSP-Servlet-JSP example, which was broken by
the earlier changes.
PR: Bugzilla #2692
Submitted by: Remy Maucherat
Revision Changes Path
1.22 +19 -5 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationDispatcher.java
Index: ApplicationDispatcher.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationDispatcher.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- ApplicationDispatcher.java 2001/07/17 04:21:12 1.21
+++ ApplicationDispatcher.java 2001/07/19 18:37:02 1.22
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationDispatcher.java,v 1.21 2001/07/17 04:21:12 craigmcc Exp $
- * $Revision: 1.21 $
- * $Date: 2001/07/17 04:21:12 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationDispatcher.java,v 1.22 2001/07/19 18:37:02 craigmcc Exp $
+ * $Revision: 1.22 $
+ * $Date: 2001/07/19 18:37:02 $
*
* ====================================================================
*
@@ -105,7 +105,7 @@
* <code>javax.servlet.ServletResponseWrapper</code>.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.21 $ $Date: 2001/07/17 04:21:12 $
+ * @version $Revision: 1.22 $ $Date: 2001/07/19 18:37:02 $
*/
final class ApplicationDispatcher
@@ -420,6 +420,8 @@
}
// Commit and close the response before we return
+ if (debug >= 1)
+ log(" Committing and closing response");
response.flushBuffer();
try {
PrintWriter writer = response.getWriter();
@@ -609,7 +611,11 @@
// Allocate a servlet instance to process this request
try {
if (!unavailable) {
+ // if (debug >= 2)
+ // log(" Allocating servlet instance");
servlet = wrapper.allocate();
+ // if ((debug >= 2) && (servlet == null))
+ // log(" No servlet instance returned!");
}
} catch (ServletException e) {
log(sm.getString("applicationDispatcher.allocateException",
@@ -633,6 +639,8 @@
else
request.removeAttribute(Globals.JSP_FILE_ATTR);
if (servlet != null) {
+ // if (debug >= 2)
+ // log(" Calling service(), jspFile=" + jspFile);
if ((hrequest != null) && (hresponse != null)) {
servlet.service((HttpServletRequest) request,
(HttpServletResponse) response);
@@ -666,8 +674,11 @@
// Deallocate the allocated servlet instance
try {
- if (servlet != null)
+ if (servlet != null) {
+ // if (debug >= 2)
+ // log(" Deallocating servlet instance");
wrapper.deallocate(servlet);
+ }
} catch (ServletException e) {
log(sm.getString("applicationDispatcher.deallocateException",
wrapper.getName()), e);
@@ -832,6 +843,9 @@
ServletRequest previous = null;
ServletRequest current = outerRequest;
while (current != null) {
+ if ("org.apache.catalina.servlets.InvokerHttpRequest".
+ equals(current.getClass().getName()))
+ break; // KLUDGE - Make nested RD.forward() using invoker work
if (!(current instanceof ServletRequestWrapper))
break;
if (current instanceof ApplicationHttpRequest)
1.2 +7 -68 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/InvokerHttpRequest.java
Index: InvokerHttpRequest.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/InvokerHttpRequest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InvokerHttpRequest.java 2001/07/17 00:14:16 1.1
+++ InvokerHttpRequest.java 2001/07/19 18:37:02 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/InvokerHttpRequest.java,v 1.1 2001/07/17 00:14:16 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2001/07/17 00:14:16 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/InvokerHttpRequest.java,v 1.2 2001/07/19 18:37:02 craigmcc Exp $
+ * $Revision: 1.2 $
+ * $Date: 2001/07/19 18:37:02 $
*
* ====================================================================
*
@@ -88,7 +88,7 @@
* to the servlet, because a new servlet mapping will have been created.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2001/07/17 00:14:16 $
+ * @version $Revision: 1.2 $ $Date: 2001/07/19 18:37:02 $
*/
class InvokerHttpRequest extends HttpServletRequestWrapper {
@@ -105,9 +105,7 @@
public InvokerHttpRequest(HttpServletRequest request) {
super(request);
- this.contextPath = request.getContextPath();
this.pathInfo = request.getPathInfo();
- this.queryString = request.getQueryString();
this.requestURI = request.getRequestURI();
this.servletPath = request.getServletPath();
@@ -118,12 +116,6 @@
/**
- * The context path for this request.
- */
- protected String contextPath = null;
-
-
- /**
* Descriptive information about this implementation.
*/
protected static final String info =
@@ -137,12 +129,6 @@
/**
- * The query string for this request.
- */
- protected String queryString = null;
-
-
- /**
* The request URI for this request.
*/
protected String requestURI = null;
@@ -165,17 +151,6 @@
/**
- * Override the <code>getContextPath()</code> method of the wrapped
- * request.
- */
- public String getContextPath() {
-
- return (this.contextPath);
-
- }
-
-
- /**
* Override the <code>getPathInfo()</code> method of the wrapped request.
*/
public String getPathInfo() {
@@ -186,23 +161,11 @@
/**
- * Override the <code>getQueryString()</code> method of the wrapped
- * request.
+ * Override the <code>getRequestURI()</code> method of the wrapped request.
*/
- public String getQueryString() {
-
- return (this.queryString);
-
- }
-
-
- /**
- * Override the <code>getRequestURI()</code> method of the wrapped
- * request.
- */
public String getRequestURI() {
- return (this.requestURI);
+ return (this.requestURI);
}
@@ -233,18 +196,6 @@
/**
- * Set the context path for this request.
- *
- * @param contextPath The new context path
- */
- void setContextPath(String contextPath) {
-
- this.contextPath = contextPath;
-
- }
-
-
- /**
* Set the path information for this request.
*
* @param pathInfo The new path info
@@ -257,25 +208,13 @@
/**
- * Set the query string for this request.
- *
- * @param queryString The new query string
- */
- void setQueryString(String queryString) {
-
- this.queryString = queryString;
-
- }
-
-
- /**
* Set the request URI for this request.
*
* @param requestURI The new request URI
*/
void setRequestURI(String requestURI) {
- this.requestURI = requestURI;
+ this.requestURI = requestURI;
}
1.8 +41 -21 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/InvokerServlet.java
Index: InvokerServlet.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/InvokerServlet.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- InvokerServlet.java 2001/07/17 04:21:13 1.7
+++ InvokerServlet.java 2001/07/19 18:37:02 1.8
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/InvokerServlet.java,v 1.7 2001/07/17 04:21:13 craigmcc Exp $
- * $Revision: 1.7 $
- * $Date: 2001/07/17 04:21:13 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/InvokerServlet.java,v 1.8 2001/07/19 18:37:02 craigmcc Exp $
+ * $Revision: 1.8 $
+ * $Date: 2001/07/19 18:37:02 $
*
* ====================================================================
*
@@ -72,6 +72,7 @@
import javax.servlet.UnavailableException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import org.apache.catalina.ContainerServlet;
import org.apache.catalina.Context;
@@ -86,7 +87,7 @@
* in the web application deployment descriptor.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.7 $ $Date: 2001/07/17 04:21:13 $
+ * @version $Revision: 1.8 $ $Date: 2001/07/19 18:37:02 $
*/
public final class InvokerServlet
@@ -268,41 +269,33 @@
// Identify the input parameters and our "included" state
String inRequestURI = null;
- String inContextPath = null;
String inServletPath = null;
String inPathInfo = null;
- String inQueryString = null;
boolean included =
(request.getAttribute(Globals.REQUEST_URI_ATTR) != null);
if (included) {
inRequestURI =
(String) request.getAttribute(Globals.REQUEST_URI_ATTR);
- inContextPath =
- (String) request.getAttribute(Globals.CONTEXT_PATH_ATTR);
inServletPath =
(String) request.getAttribute(Globals.SERVLET_PATH_ATTR);
inPathInfo =
(String) request.getAttribute(Globals.PATH_INFO_ATTR);
- inQueryString =
- (String) request.getAttribute(Globals.QUERY_STRING_ATTR);
} else {
inRequestURI = request.getRequestURI();
- inContextPath = request.getContextPath();
inServletPath = request.getServletPath();
inPathInfo = request.getPathInfo();
- inQueryString = request.getQueryString();
}
if (debug >= 1) {
- log("serveRequest: included='" + included + "', requestURI='" +
- inRequestURI + "', contextPath='" + inContextPath + "'");
+ log("included='" + included + "', requestURI='" +
+ inRequestURI + "'");
log(" servletPath='" + inServletPath + "', pathInfo='" +
- inPathInfo + "', queryString='" + inQueryString + "'");
+ inPathInfo + "'");
}
// Make sure a servlet name or class name was specified
if (inPathInfo == null) {
if (debug >= 1)
- log("serveRequest: Invalid pathInfo '" + inPathInfo + "'");
+ log("Invalid pathInfo '" + inPathInfo + "'");
if (included)
throw new ServletException
(sm.getString("invokerServlet.invalidPath", inRequestURI));
@@ -317,6 +310,9 @@
String pathInfo = inPathInfo;
String servletClass = pathInfo.substring(1);
int slash = servletClass.indexOf('/');
+ // if (debug >= 2)
+ // log(" Calculating with servletClass='" + servletClass +
+ // "', pathInfo='" + pathInfo + "', slash=" + slash);
if (slash >= 0) {
pathInfo = servletClass.substring(slash);
servletClass = servletClass.substring(0, slash);
@@ -324,7 +320,7 @@
pathInfo = "";
}
if (debug >= 1)
- log("serveRequest: Processing servlet '" + servletClass +
+ log("Processing servlet '" + servletClass +
"' with path info '" + pathInfo + "'");
String name = "org.apache.catalina.INVOKER." + servletClass;
String pattern = inServletPath + "/" + servletClass + "/*";
@@ -334,7 +330,7 @@
wrapper = (Wrapper) context.findChild(servletClass);
if (wrapper != null) {
if (debug >= 1)
- log("serveRequest: Using wrapper for servlet '" +
+ log("Using wrapper for servlet '" +
wrapper.getName() + "' with mapping '" + pattern + "'");
context.addServletMapping(pattern, wrapper.getName());
}
@@ -343,7 +339,7 @@
else {
if (debug >= 1)
- log("serveRequest: Creating wrapper for '" + servletClass +
+ log("Creating wrapper for '" + servletClass +
"' with mapping '" + pattern + "'");
// Create and install a new wrapper
@@ -355,12 +351,13 @@
context.addChild(wrapper);
context.addServletMapping(pattern, name);
} catch (Throwable t) {
+ log(sm.getString("invokerServlet.cannotCreate",
+ inRequestURI), t);
if (included)
throw new ServletException
(sm.getString("invokerServlet.cannotCreate",
inRequestURI), t);
else {
- log("serveRequest.create", t);
response.sendError(HttpServletResponse.SC_NOT_FOUND,
inRequestURI);
return;
@@ -372,6 +369,7 @@
// Create a request wrapper to pass on to the invoked servlet
InvokerHttpRequest wrequest =
new InvokerHttpRequest(request);
+ wrequest.setRequestURI(inRequestURI);
StringBuffer sb = new StringBuffer(inServletPath);
sb.append("/");
sb.append(servletClass);
@@ -380,11 +378,12 @@
wrequest.setPathInfo(null);
else
wrequest.setPathInfo(pathInfo);
- wrequest.setQueryString(request.getQueryString());
// Allocate a servlet instance to perform this request
Servlet instance = null;
try {
+ // if (debug >= 2)
+ // log(" Allocating servlet instance");
instance = wrapper.allocate();
} catch (ServletException e) {
log(sm.getString("invokerServlet.allocate", inRequestURI), e);
@@ -423,9 +422,14 @@
request.setAttribute(Globals.JSP_FILE_ATTR, jspFile);
else
request.removeAttribute(Globals.JSP_FILE_ATTR);
+ // if (debug >= 2)
+ // log(" Calling service() method, jspFile=" +
+ // jspFile);
instance.service(wrequest, response);
request.removeAttribute(Globals.JSP_FILE_ATTR);
} catch (IOException e) {
+ // if (debug >= 2)
+ // log(" service() method IOException", e);
request.removeAttribute(Globals.JSP_FILE_ATTR);
try {
wrapper.deallocate(instance);
@@ -434,6 +438,8 @@
}
throw e;
} catch (ServletException e) {
+ // if (debug >= 2)
+ // log(" service() method ServletException", e);
request.removeAttribute(Globals.JSP_FILE_ATTR);
try {
wrapper.deallocate(instance);
@@ -442,6 +448,8 @@
}
throw e;
} catch (RuntimeException e) {
+ // if (debug >= 2)
+ // log(" service() method RuntimeException", e);
request.removeAttribute(Globals.JSP_FILE_ATTR);
try {
wrapper.deallocate(instance);
@@ -449,10 +457,22 @@
;
}
throw e;
+ } catch (Throwable e) {
+ // if (debug >= 2)
+ // log(" service() method Throwable", e);
+ request.removeAttribute(Globals.JSP_FILE_ATTR);
+ try {
+ wrapper.deallocate(instance);
+ } catch (Throwable f) {
+ ;
+ }
+ throw new ServletException("Invoker service() exception", e);
}
// Deallocate the allocated servlet instance
try {
+ // if (debug >= 2)
+ // log(" deallocate servlet instance");
wrapper.deallocate(instance);
} catch (ServletException e) {
log(sm.getString("invokerServlet.deallocate", inRequestURI), e);