tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r471281 - in /tomcat/tc6.0.x/trunk/java/org/apache/catalina/core: ApplicationDispatcher.java ApplicationFilterChain.java LocalStrings.properties
Date Sat, 04 Nov 2006 22:35:16 GMT
Author: markt
Date: Sat Nov  4 14:35:15 2006
New Revision: 471281

URL: http://svn.apache.org/viewvc?view=rev&rev=471281
Log:
Port fix for bug 34956. Enforce requirements of SRV.8.2 / SRV.14.2.5.1

Modified:
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationDispatcher.java
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationFilterChain.java
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationDispatcher.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationDispatcher.java?view=diff&rev=471281&r1=471280&r2=471281
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationDispatcher.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationDispatcher.java Sat Nov
 4 14:35:15 2006
@@ -325,6 +325,11 @@
         // Set up to handle the specified request and response
         setup(request, response, false);
 
+        if (Globals.STRICT_SERVLET_COMPLIANCE) {
+            // Check SRV.8.2 / SRV.14.2.5.1 compliance
+            checkSameObjects();
+        }
+
         // Identify the HTTP-specific request and response objects (if any)
         HttpServletRequest hrequest = null;
         if (request instanceof HttpServletRequest)
@@ -507,6 +512,11 @@
         // Set up to handle the specified request and response
         setup(request, response, true);
 
+        if (Globals.STRICT_SERVLET_COMPLIANCE) {
+            // 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,5 +968,55 @@
 
     }
 
+    private void checkSameObjects() throws ServletException {
+        ServletRequest originalRequest =
+            ApplicationFilterChain.getLastServicedRequest();
+        ServletResponse originalResponse =
+            ApplicationFilterChain.getLastServicedResponse();
+        
+        // Some forwards, eg from valves will not set original values 
+        if (originalRequest == null || originalResponse == null) {
+            return;
+        }
+        
+        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/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationFilterChain.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationFilterChain.java?view=diff&rev=471281&r1=471280&r2=471281
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationFilterChain.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationFilterChain.java Sat Nov
 4 14:35:15 2006
@@ -36,6 +36,7 @@
 import org.apache.catalina.CometFilter;
 import org.apache.catalina.CometFilterChain;
 import org.apache.catalina.CometProcessor;
+import org.apache.catalina.Globals;
 import org.apache.catalina.InstanceEvent;
 import org.apache.catalina.security.SecurityUtil;
 import org.apache.catalina.util.InstanceSupport;
@@ -54,6 +55,19 @@
 
 final class ApplicationFilterChain implements FilterChain, CometFilterChain {
 
+    // Used to enforce requirements of SRV.8.2 / SRV.14.2.5.1
+    private final static ThreadLocal lastServicedRequest;
+    private final static ThreadLocal lastServicedResponse;
+
+    static {
+        if (Globals.STRICT_SERVLET_COMPLIANCE) {
+            lastServicedRequest = new ThreadLocal();
+            lastServicedResponse = new ThreadLocal();
+        } else {
+            lastServicedRequest = null;
+            lastServicedResponse = null;
+        }
+    }
 
     // -------------------------------------------------------------- Constants
 
@@ -250,6 +264,11 @@
 
         // We fell off the end of the chain -- call the servlet instance
         try {
+            if (Globals.STRICT_SERVLET_COMPLIANCE) {
+                lastServicedRequest.set(request);
+                lastServicedResponse.set(response);
+            }
+
             support.fireInstanceEvent(InstanceEvent.BEFORE_SERVICE_EVENT,
                                       servlet, request, response);
             if ((request instanceof HttpServletRequest) &&
@@ -293,6 +312,11 @@
                                       servlet, request, response, e);
             throw new ServletException
               (sm.getString("filterChain.servlet"), e);
+        } finally {
+            if (Globals.STRICT_SERVLET_COMPLIANCE) {
+                lastServicedRequest.set(null);
+                lastServicedResponse.set(null);
+            }
         }
 
     }
@@ -340,6 +364,29 @@
         }
     }
 
+    
+    /**
+     * 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();
+    }
+    
+    
     private void internalDoFilterEvent(CometEvent event)
         throws IOException, ServletException {
 

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties?view=diff&rev=471281&r1=471280&r2=471281
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties Sat Nov  4
14:35:15 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