Author: markt
Date: Sun Dec 24 17:04:36 2006
New Revision: 490093

URL: http://svn.apache.org/viewvc?view=rev&rev=490093
Log:
Revert my thread safety patch - it was bad.
I do intend to commit a revised patch after some further testing.

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

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=490093&r1=490092&r2=490093
==============================================================================
--- 
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 Dec 24 17:04:36 2006
@@ -131,6 +131,7 @@
         this.context = (Context) wrapper.getParent();
         this.requestURI = requestURI;
         this.servletPath = servletPath;
+        this.origServletPath = servletPath;
         this.pathInfo = pathInfo;
         this.queryString = queryString;
         this.name = name;
@@ -152,12 +153,30 @@
     private static Log log = LogFactory.getLog(ApplicationDispatcher.class);
 
     /**
+     * The request specified by the dispatching application.
+     */
+    private ServletRequest appRequest = null;
+
+
+    /**
+     * The response specified by the dispatching application.
+     */
+    private ServletResponse appResponse = null;
+
+
+    /**
      * The Context this RequestDispatcher is associated with.
      */
     private Context context = null;
 
 
     /**
+     * Are we performing an include() instead of a forward()?
+     */
+    private boolean including = false;
+
+
+    /**
      * Descriptive information about this implementation.
      */
     private static final String info =
@@ -171,6 +190,18 @@
 
 
     /**
+     * The outermost request that will be passed on to the invoked servlet.
+     */
+    private ServletRequest outerRequest = null;
+
+
+    /**
+     * The outermost response that will be passed on to the invoked servlet.
+     */
+    private ServletResponse outerResponse = null;
+
+
+    /**
      * The extra path information for this RequestDispatcher.
      */
     private String pathInfo = null;
@@ -187,13 +218,13 @@
      */
     private String requestURI = null;
 
-
     /**
      * The servlet path for this RequestDispatcher.
      */
     private String servletPath = null;
 
-
+    private String origServletPath = null;
+    
     /**
      * The StringManager for this package.
      */
@@ -215,6 +246,18 @@
     private Wrapper wrapper = null;
 
 
+    /**
+     * The request wrapper we have created and installed (if any).
+     */
+    private ServletRequest wrapRequest = null;
+
+
+    /**
+     * The response wrapper we have created and installed (if any).
+     */
+    private ServletResponse wrapResponse = null;
+
+
     // ------------------------------------------------------------- Properties
 
 
@@ -280,12 +323,11 @@
         }
 
         // Set up to handle the specified request and response
-        ServletRequest outerRequest = request;
-        ServletResponse outerResponse = response;
-
+        setup(request, response, false);
+        
         if (Globals.STRICT_SERVLET_COMPLIANCE) {
             // Check SRV.8.2 / SRV.14.2.5.1 compliance
-            checkSameObjects(request, response);
+            checkSameObjects();
         }
 
         // Identify the HTTP-specific request and response objects (if any)
@@ -301,9 +343,8 @@
 
             if ( log.isDebugEnabled() )
                 log.debug(" Non-HTTP Forward");
-            // TODO - this doesn't appear to agree with the comments above
-            processRequest(hrequest,hresponse,outerRequest,outerResponse,null,
-                    null);
+            
+            processRequest(hrequest,hresponse);
 
         }
 
@@ -314,18 +355,17 @@
                 log.debug(" Named Dispatcher Forward");
             
             ApplicationHttpRequest wrequest =
-                (ApplicationHttpRequest) wrapRequest(outerRequest);
+                (ApplicationHttpRequest) wrapRequest();
             wrequest.setRequestURI(hrequest.getRequestURI());
             wrequest.setContextPath(hrequest.getContextPath());
             wrequest.setServletPath(hrequest.getServletPath());
             wrequest.setPathInfo(hrequest.getPathInfo());
             wrequest.setQueryString(hrequest.getQueryString());
 
-            processRequest(request,response,outerRequest,outerResponse,
-                    wrequest,null);
+            processRequest(request,response);
 
             wrequest.recycle();
-            unwrapRequest(outerRequest, wrequest);
+            unwrapRequest();
 
         }
 
@@ -336,7 +376,7 @@
                 log.debug(" Path Based Forward");
 
             ApplicationHttpRequest wrequest =
-                (ApplicationHttpRequest) wrapRequest(outerRequest);
+                (ApplicationHttpRequest) wrapRequest();
             String contextPath = context.getPath();
 
             if (hrequest.getAttribute(Globals.FORWARD_REQUEST_URI_ATTR) == 
null) {
@@ -361,11 +401,10 @@
                 wrequest.setQueryParams(queryString);
             }
 
-            
processRequest(request,response,outerRequest,outerResponse,wrequest,
-                    null);
+            processRequest(request,response);
 
             wrequest.recycle();
-            unwrapRequest(outerRequest, wrequest);
+            unwrapRequest();
 
         }
 
@@ -414,11 +453,7 @@
      * @exception ServletException if a servlet error occurs
      */
     private void processRequest(ServletRequest request, 
-                                ServletResponse response,
-                                ServletRequest outerRequest,
-                                ServletResponse outerResponse,
-                                ServletRequest wrapRequest,
-                                ServletResponse wrapResponse)
+                                ServletResponse response)
         throws IOException, ServletException {
                 
         Integer disInt = (Integer) request.getAttribute
@@ -427,15 +462,13 @@
             if (disInt.intValue() != ApplicationFilterFactory.ERROR) {
                 outerRequest.setAttribute
                     (ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR,
-                     servletPath);
+                     origServletPath);
                 outerRequest.setAttribute
                     (ApplicationFilterFactory.DISPATCHER_TYPE_ATTR,
                      new Integer(ApplicationFilterFactory.FORWARD));
-                invoke(outerRequest, response, outerRequest, outerResponse,
-                        wrapRequest, wrapResponse);
+                invoke(outerRequest, response);
             } else {
-                invoke(outerRequest, response, outerRequest, outerResponse,
-                        wrapRequest, wrapResponse);
+                invoke(outerRequest, response);
             }
         }
 
@@ -477,17 +510,16 @@
         throws ServletException, IOException
     {
         // Set up to handle the specified request and response
-        ServletRequest outerRequest = request;
-        ServletResponse outerResponse = response;
+        setup(request, response, true);
 
         if (Globals.STRICT_SERVLET_COMPLIANCE) {
             // Check SRV.8.2 / SRV.14.2.5.1 compliance
-            checkSameObjects(request, response);
+            checkSameObjects();
         }
         
         // Create a wrapped response to use for this request
         // ServletResponse wresponse = null;
-        ServletResponse wresponse = wrapResponse(outerResponse, true);
+        wrapResponse();
 
         // Handle a non-HTTP include
         if (!(request instanceof HttpServletRequest) ||
@@ -496,12 +528,9 @@
             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, outerResponse, outerRequest, outerResponse, null, 
-                    wresponse);
+                                             new 
Integer(ApplicationFilterFactory.INCLUDE));
+            
request.setAttribute(ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR, 
origServletPath);
+            invoke(request, outerResponse);
         }
 
         // Handle an HTTP named dispatcher include
@@ -511,18 +540,14 @@
                 log.debug(" Named Dispatcher Include");
 
             ApplicationHttpRequest wrequest =
-                (ApplicationHttpRequest) wrapRequest(outerRequest);
+                (ApplicationHttpRequest) wrapRequest();
             wrequest.setAttribute(Globals.NAMED_DISPATCHER_ATTR, name);
             if (servletPath != null)
                 wrequest.setServletPath(servletPath);
-            wrequest.setAttribute(
-                    ApplicationFilterFactory.DISPATCHER_TYPE_ATTR,
-                    new Integer(ApplicationFilterFactory.INCLUDE));
-            wrequest.setAttribute(
-                    ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR,
-                    servletPath);
-            invoke(outerRequest, outerResponse, outerRequest, outerResponse,
-                    wrequest, wresponse);
+            
wrequest.setAttribute(ApplicationFilterFactory.DISPATCHER_TYPE_ATTR,
+                                             new 
Integer(ApplicationFilterFactory.INCLUDE));
+            
wrequest.setAttribute(ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR, 
origServletPath);
+            invoke(outerRequest, outerResponse);
 
             wrequest.recycle();
         }
@@ -534,7 +559,7 @@
                 log.debug(" Path Based Include");
 
             ApplicationHttpRequest wrequest =
-                (ApplicationHttpRequest) wrapRequest(outerRequest);
+                (ApplicationHttpRequest) wrapRequest();
             String contextPath = context.getPath();
             if (requestURI != null)
                 wrequest.setAttribute(Globals.INCLUDE_REQUEST_URI_ATTR,
@@ -544,7 +569,7 @@
                                       contextPath);
             if (servletPath != null)
                 wrequest.setAttribute(Globals.INCLUDE_SERVLET_PATH_ATTR,
-                        servletPath);
+                                      servletPath);
             if (pathInfo != null)
                 wrequest.setAttribute(Globals.INCLUDE_PATH_INFO_ATTR,
                                       pathInfo);
@@ -554,14 +579,10 @@
                 wrequest.setQueryParams(queryString);
             }
             
-            wrequest.setAttribute(
-                    ApplicationFilterFactory.DISPATCHER_TYPE_ATTR,
-                    new Integer(ApplicationFilterFactory.INCLUDE));
-            wrequest.setAttribute(
-                    ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR,
-                    servletPath);
-            invoke(outerRequest, outerResponse, outerRequest, outerResponse,
-                    wrequest, wresponse);
+            
wrequest.setAttribute(ApplicationFilterFactory.DISPATCHER_TYPE_ATTR,
+                                             new 
Integer(ApplicationFilterFactory.INCLUDE));
+            
wrequest.setAttribute(ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR, 
origServletPath);
+            invoke(outerRequest, outerResponse);
 
             wrequest.recycle();
         }
@@ -587,9 +608,7 @@
      * @exception IOException if an input/output error occurs
      * @exception ServletException if a servlet error occurs
      */
-    private void invoke(ServletRequest request, ServletResponse response,
-            ServletRequest outerRequest, ServletResponse outerResponse,
-            ServletRequest wrapRequest, ServletResponse wrapResponse)
+    private void invoke(ServletRequest request, ServletResponse response)
             throws IOException, ServletException {
 
         // Checking to see if the context classloader is the current context
@@ -632,14 +651,12 @@
                 servlet = wrapper.allocate();
             }
         } catch (ServletException e) {
-            wrapper.getLogger().error(
-                    sm.getString("applicationDispatcher.allocateException",
+            
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.getLogger().error(sm.getString("applicationDispatcher.allocateException",
                              wrapper.getName()), e);
             servletException = new ServletException
                 (sm.getString("applicationDispatcher.allocateException",
@@ -649,8 +666,8 @@
                 
         // Get the FilterChain Here
         ApplicationFilterFactory factory = 
ApplicationFilterFactory.getInstance();
-        ApplicationFilterChain filterChain =
-            factory.createFilterChain(request,wrapper,servlet);
+        ApplicationFilterChain filterChain = factory.createFilterChain(request,
+                                                                
wrapper,servlet);
         // Call the service() method for the allocated servlet instance
         try {
             String jspFile = wrapper.getJspFile();
@@ -714,8 +731,7 @@
         } catch (Throwable e) {
             log.error(sm.getString("standardWrapper.releaseFilters",
                              wrapper.getName()), e);
-          //FIXME Exception handling needs to be simpiler to what is in the
-          //StandardWrapperValue
+          //FIXME Exception handling needs to be simpiler to what is in the 
StandardWrapperValue
         }
 
         // Deallocate the allocated servlet instance
@@ -724,13 +740,11 @@
                 wrapper.deallocate(servlet);
             }
         } catch (ServletException e) {
-            wrapper.getLogger().error(
-                    sm.getString("applicationDispatcher.deallocateException",
+            
wrapper.getLogger().error(sm.getString("applicationDispatcher.deallocateException",
                              wrapper.getName()), e);
             servletException = e;
         } catch (Throwable e) {
-            wrapper.getLogger().error(
-                    sm.getString("applicationDispatcher.deallocateException",
+            
wrapper.getLogger().error(sm.getString("applicationDispatcher.deallocateException",
                              wrapper.getName()), e);
             servletException = new ServletException
                 (sm.getString("applicationDispatcher.deallocateException",
@@ -743,8 +757,8 @@
         
         // Unwrap request/response if needed
         // See Bugzilla 30949
-        unwrapRequest(outerRequest, wrapRequest);
-        unwrapResponse(outerResponse, wrapResponse);
+        unwrapRequest();
+        unwrapResponse();
 
         // Rethrow an exception if one was thrown by the invoked servlet
         if (ioException != null)
@@ -758,10 +772,29 @@
 
 
     /**
+     * Set up to handle the specified request and response
+     *
+     * @param request The servlet request specified by the caller
+     * @param response The servlet response specified by the caller
+     * @param including Are we performing an include() as opposed to
+     *  a forward()?
+     */
+    private void setup(ServletRequest request, ServletResponse response,
+                       boolean including) {
+
+        this.appRequest = request;
+        this.appResponse = response;
+        this.outerRequest = request;
+        this.outerResponse = response;
+        this.including = including;
+
+    }
+
+
+    /**
      * Unwrap the request if we have wrapped it.
      */
-    private void unwrapRequest(ServletRequest outerRequest,
-            ServletRequest wrapRequest) {
+    private void unwrapRequest() {
 
         if (wrapRequest == null)
             return;
@@ -798,8 +831,7 @@
     /**
      * Unwrap the response if we have wrapped it.
      */
-    private void unwrapResponse(ServletResponse outerResponse,
-            ServletResponse wrapResponse) {
+    private void unwrapResponse() {
 
         if (wrapResponse == null)
             return;
@@ -837,7 +869,7 @@
      * Create and return a request wrapper that has been inserted in the
      * appropriate spot in the request chain.
      */
-    private ServletRequest wrapRequest(ServletRequest outerRequest) {
+    private ServletRequest wrapRequest() {
 
         // Locate the request we should insert in front of
         ServletRequest previous = null;
@@ -888,6 +920,7 @@
             outerRequest = wrapper;
         else
             ((ServletRequestWrapper) previous).setRequest(wrapper);
+        wrapRequest = wrapper;
         return (wrapper);
 
     }
@@ -897,8 +930,7 @@
      * Create and return a response wrapper that has been inserted in the
      * appropriate spot in the response chain.
      */
-    private ServletResponse wrapResponse(ServletResponse outerResponse,
-            boolean including) {
+    private ServletResponse wrapResponse() {
 
         // Locate the response we should insert in front of
         ServletResponse previous = null;
@@ -930,13 +962,13 @@
             outerResponse = wrapper;
         else
             ((ServletResponseWrapper) previous).setResponse(wrapper);
+        wrapResponse = wrapper;
         return (wrapper);
 
     }
 
 
-    private void checkSameObjects(ServletRequest appRequest,
-            ServletResponse appResponse) throws ServletException {
+    private void checkSameObjects() throws ServletException {
         ServletRequest originalRequest =
             ApplicationFilterChain.getLastServicedRequest();
         ServletResponse originalResponse =



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to