You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2009/12/20 18:52:37 UTC
svn commit: r892624 - in /tomcat/tc5.5.x/trunk: STATUS.txt
container/catalina/src/share/org/apache/catalina/core/ApplicationDispatcher.java
container/webapps/docs/changelog.xml
Author: markt
Date: Sun Dec 20 17:52:37 2009
New Revision: 892624
URL: http://svn.apache.org/viewvc?rev=892624&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=39844
Prevent NPE on non-HTTP forward
Modified:
tomcat/tc5.5.x/trunk/STATUS.txt
tomcat/tc5.5.x/trunk/container/catalina/src/share/org/apache/catalina/core/ApplicationDispatcher.java
tomcat/tc5.5.x/trunk/container/webapps/docs/changelog.xml
Modified: tomcat/tc5.5.x/trunk/STATUS.txt
URL: http://svn.apache.org/viewvc/tomcat/tc5.5.x/trunk/STATUS.txt?rev=892624&r1=892623&r2=892624&view=diff
==============================================================================
--- tomcat/tc5.5.x/trunk/STATUS.txt (original)
+++ tomcat/tc5.5.x/trunk/STATUS.txt Sun Dec 20 17:52:37 2009
@@ -33,12 +33,6 @@
0: fhanik - big step for an old branch, could be risky, I'd wait until after next release if we consider it
-1:
-* Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=39844
- Port r588477 (fix for #43668) by billbarker that corrected this for Tomcat 6
- http://people.apache.org/~markt/patches/2009-07-11-bug39844.patch
- +1: markt, kkolinko, rjung
- -1:
-
* Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=43327
Port from 6.0.x
Required to investigate 39997
Modified: tomcat/tc5.5.x/trunk/container/catalina/src/share/org/apache/catalina/core/ApplicationDispatcher.java
URL: http://svn.apache.org/viewvc/tomcat/tc5.5.x/trunk/container/catalina/src/share/org/apache/catalina/core/ApplicationDispatcher.java?rev=892624&r1=892623&r2=892624&view=diff
==============================================================================
--- tomcat/tc5.5.x/trunk/container/catalina/src/share/org/apache/catalina/core/ApplicationDispatcher.java (original)
+++ tomcat/tc5.5.x/trunk/container/catalina/src/share/org/apache/catalina/core/ApplicationDispatcher.java Sun Dec 20 17:52:37 2009
@@ -139,6 +139,16 @@
* Are we performing an include() instead of a forward()?
*/
boolean including = false;
+
+ /**
+ * Outer most HttpServletRequest in the chain
+ */
+ HttpServletRequest hrequest = null;
+
+ /**
+ * Outermost HttpServletResponse in the chain
+ */
+ HttpServletResponse hresponse = null;
}
// ----------------------------------------------------------- Constructors
@@ -329,32 +339,17 @@
checkSameObjects(request, response);
}
- // Identify the HTTP-specific request and response objects (if any)
- HttpServletRequest hrequest = null;
- if (request instanceof HttpServletRequest)
- hrequest = (HttpServletRequest) request;
- HttpServletResponse hresponse = null;
- if (response instanceof HttpServletResponse)
- hresponse = (HttpServletResponse) response;
-
- // Handle a non-HTTP forward by passing the existing request/response
- if ((hrequest == null) || (hresponse == null)) {
-
- if ( log.isDebugEnabled() )
- log.debug(" Non-HTTP Forward");
-
- processRequest(hrequest,hresponse,state);
-
- }
-
+ wrapResponse(state);
+
// Handle an HTTP named dispatcher forward
- else if ((servletPath == null) && (pathInfo == null)) {
+ if ((servletPath == null) && (pathInfo == null)) {
if ( log.isDebugEnabled() )
log.debug(" Named Dispatcher Forward");
ApplicationHttpRequest wrequest =
(ApplicationHttpRequest) wrapRequest(state);
+ HttpServletRequest hrequest = state.hrequest;
wrequest.setRequestURI(hrequest.getRequestURI());
wrequest.setContextPath(hrequest.getContextPath());
wrequest.setServletPath(hrequest.getServletPath());
@@ -374,6 +369,7 @@
(ApplicationHttpRequest) wrapRequest(state);
String contextPath = context.getPath();
+ HttpServletRequest hrequest = state.hrequest;
if (hrequest.getAttribute(Globals.FORWARD_REQUEST_URI_ATTR) == null) {
wrequest.setAttribute(Globals.FORWARD_REQUEST_URI_ATTR,
hrequest.getRequestURI());
@@ -422,12 +418,12 @@
ServletOutputStream stream = response.getOutputStream();
stream.close();
} catch (IllegalStateException f) {
- ;
+ // Ignore
} catch (IOException f) {
- ;
+ // Ignore
}
} catch (IOException e) {
- ;
+ // Ignore
}
}
@@ -513,23 +509,8 @@
// ServletResponse wresponse = null;
wrapResponse(state);
- // Handle a non-HTTP include
- if (!(request instanceof HttpServletRequest) ||
- !(response instanceof HttpServletResponse)) {
-
- if ( log.isDebugEnabled() )
- log.debug(" Non-HTTP Include");
- request.setAttribute(
- ApplicationFilterFactory.DISPATCHER_TYPE_ATTR,
- new Integer(ApplicationFilterFactory.INCLUDE));
- request.setAttribute(
- ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR,
- servletPath);
- invoke(request, state.outerResponse, state);
- }
-
// Handle an HTTP named dispatcher include
- else if (name != null) {
+ if (name != null) {
if ( log.isDebugEnabled() )
log.debug(" Named Dispatcher Include");
@@ -621,7 +602,7 @@
}
// Initialize local variables we may need
- HttpServletResponse hresponse = (HttpServletResponse) response;
+ HttpServletResponse hresponse = state.hresponse;
Servlet servlet = null;
IOException ioException = null;
ServletException servletException = null;
@@ -651,7 +632,6 @@
wrapper.getLogger().error(sm.getString("applicationDispatcher.allocateException",
wrapper.getName()), StandardWrapper.getRootCause(e));
servletException = e;
- servlet = null;
} catch (Throwable e) {
wrapper.getLogger().error(sm.getString("applicationDispatcher.allocateException",
wrapper.getName()), e);
@@ -854,6 +834,8 @@
ServletRequest previous = null;
ServletRequest current = state.outerRequest;
while (current != null) {
+ if(state.hrequest == null && (current instanceof HttpServletRequest))
+ state.hrequest = (HttpServletRequest)current;
if ("org.apache.catalina.servlets.InvokerHttpRequest".
equals(current.getClass().getName()))
break; // KLUDGE - Make nested RD.forward() using invoker work
@@ -915,6 +897,11 @@
ServletResponse previous = null;
ServletResponse current = state.outerResponse;
while (current != null) {
+ if(state.hresponse == null && (current instanceof HttpServletResponse)) {
+ state.hresponse = (HttpServletResponse)current;
+ if(!state.including) // Forward only needs hresponse
+ return null;
+ }
if (!(current instanceof ServletResponseWrapper))
break;
if (current instanceof ApplicationHttpResponse)
Modified: tomcat/tc5.5.x/trunk/container/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc5.5.x/trunk/container/webapps/docs/changelog.xml?rev=892624&r1=892623&r2=892624&view=diff
==============================================================================
--- tomcat/tc5.5.x/trunk/container/webapps/docs/changelog.xml (original)
+++ tomcat/tc5.5.x/trunk/container/webapps/docs/changelog.xml Sun Dec 20 17:52:37 2009
@@ -71,6 +71,10 @@
(markt/kkolinko)
</fix>
<fix>
+ <bug>39844</bug>: Fix NPE when performing a non-HTTP forward.
+ (billbarker)
+ </fix>
+ <fix>
<bug>41059</bug>: Reduce the chances of errors when using
ENABLE_CLEAR_REFERENCES. Patch by Curt Arnold. (markt)
</fix>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org