tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r451831 - in /tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/core: ApplicationDispatcher.java ApplicationFilterChain.java LocalStrings.properties
Date Sun, 01 Oct 2006 22:43:12 GMT
Author: markt
Date: Sun Oct  1 15:43:11 2006
New Revision: 451831

URL: http://svn.apache.org/viewvc?view=rev&rev=451831
Log:
Fix bug 34956. Ensure requestDispatchers are called with original or wrapped original request/response
objects as per SRV.8.2 and SRV.14.2.5.1

Modified:
    tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/core/ApplicationDispatcher.java
    tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/core/ApplicationFilterChain.java
    tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/core/LocalStrings.properties

Modified: tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/core/ApplicationDispatcher.java
URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/core/ApplicationDispatcher.java?view=diff&rev=451831&r1=451830&r2=451831
==============================================================================
--- tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/core/ApplicationDispatcher.java
(original)
+++ tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/core/ApplicationDispatcher.java
Sun Oct  1 15:43:11 2006
@@ -323,6 +323,9 @@
 
         // Set up to handle the specified request and response
         setup(request, response, false);
+        
+        // Check SRV.8.2 / SRV.14.2.5.1 compliance
+        checkSameObjects();
 
         // Identify the HTTP-specific request and response objects (if any)
         HttpServletRequest hrequest = null;
@@ -506,6 +509,9 @@
         // Set up to handle the specified request and response
         setup(request, response, true);
 
+        // Check SRV.8.2 / SRV.14.2.5.1 compliance
+        checkSameObjects();
+        
         // Create a wrapped response to use for this request
         // ServletResponse wresponse = null;
         ServletResponse wresponse = wrapResponse();
@@ -958,4 +964,50 @@
     }
 
 
+    private void checkSameObjects() throws ServletException {
+        ServletRequest originalRequest =
+            ApplicationFilterChain.getLastServicedRequest();
+        ServletResponse originalResponse =
+            ApplicationFilterChain.getLastServicedResponse();
+        
+        boolean same = false;
+        ServletRequest dispatchedRequest = appRequest;
+        
+        while (!same) {
+            if (originalRequest.equals(dispatchedRequest)) {
+                same = true;
+            }
+            if (!same && dispatchedRequest instanceof ServletRequestWrapper) {
+                dispatchedRequest =
+                    ((ServletRequestWrapper) dispatchedRequest).getRequest();
+            } else {
+                break;
+            }
+        }
+        if (!same) {
+            throw new ServletException(sm.getString(
+                    "applicationDispatcher.specViolation.request"));
+        }
+        
+        same = false;
+        ServletResponse dispatchedResponse = appResponse;
+        
+        while (!same) {
+            if (originalResponse.equals(dispatchedResponse)) {
+                same = true;
+            }
+            
+            if (!same && dispatchedResponse instanceof ServletResponseWrapper) {
+                dispatchedResponse =
+                    ((ServletResponseWrapper) dispatchedResponse).getResponse();
+            } else {
+                break;
+            }
+        }
+
+        if (!same) {
+            throw new ServletException(sm.getString(
+                    "applicationDispatcher.specViolation.response"));
+        }
+    }
 }

Modified: tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/core/ApplicationFilterChain.java
URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/core/ApplicationFilterChain.java?view=diff&rev=451831&r1=451830&r2=451831
==============================================================================
--- tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/core/ApplicationFilterChain.java
(original)
+++ tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/core/ApplicationFilterChain.java
Sun Oct  1 15:43:11 2006
@@ -49,7 +49,10 @@
 
 final class ApplicationFilterChain implements FilterChain {
 
-
+    // Used to enforce requirements of SRV.8.2 / SRV.14.2.5.1
+    private static ThreadLocal lastServicedRequest = new ThreadLocal();
+    private static ThreadLocal lastServicedResponse = new ThreadLocal();
+    
     // -------------------------------------------------------------- Constants
 
 
@@ -231,6 +234,8 @@
 
         // We fell off the end of the chain -- call the servlet instance
         try {
+            lastServicedRequest.set(request);
+            lastServicedResponse.set(response);
             support.fireInstanceEvent(InstanceEvent.BEFORE_SERVICE_EVENT,
                                       servlet, request, response);
             if ((request instanceof HttpServletRequest) &&
@@ -274,6 +279,9 @@
                                       servlet, request, response, e);
             throw new ServletException
               (sm.getString("filterChain.servlet"), e);
+        } finally {
+            lastServicedRequest.set(null);
+            lastServicedResponse.set(null);
         }
 
     }
@@ -338,5 +346,26 @@
 
     }
 
+    
+    /**
+     * The last request passed to a servlet for servicing from the current
+     * thread.
+     * 
+     * @return The last request to be serviced. 
+     */
+    public static ServletRequest getLastServicedRequest() {
+        return (ServletRequest) lastServicedRequest.get();
+    }
+
+    
+    /**
+     * The last response passed to a servlet for servicing from the current
+     * thread.
+     * 
+     * @return The last response to be serviced. 
+     */
+    public static ServletResponse getLastServicedResponse() {
+        return (ServletResponse) lastServicedResponse.get();
+    }
 
 }

Modified: tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/core/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/core/LocalStrings.properties?view=diff&rev=451831&r1=451830&r2=451831
==============================================================================
--- tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/core/LocalStrings.properties
(original)
+++ tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/core/LocalStrings.properties
Sun Oct  1 15:43:11 2006
@@ -10,6 +10,8 @@
 applicationDispatcher.include.throw=Included resource threw an exception
 applicationDispatcher.isUnavailable=Servlet {0} is currently unavailable
 applicationDispatcher.serviceException=Servlet.service() for servlet {0} threw exception
+applicationDispatcher.specViolation.request=Original SevletRequest or wrapped original ServletRequest
not passed to RequestDispatcher in violation of SRV.8.2 and SRV.14.2.5.1
+applicationDispatcher.specViolation.response=Original SevletResponse or wrapped original
ServletResponse not passed to RequestDispatcher in violation of SRV.8.2 and SRV.14.2.5.1
 applicationRequest.badParent=Cannot locate parent Request implementation
 applicationRequest.badRequest=Request is not a javax.servlet.ServletRequestWrapper
 applicationResponse.badParent=Cannot locate parent Response implementation



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message