Revision: 555
          http://svn.sourceforge.net/stripes/?rev=555&view=rev
Author:   bengunter
Date:     2007-05-26 08:45:50 -0700 (Sat, 26 May 2007)

Log Message:
-----------
Resolved STS-370: StripesFilter cleans up too early on forwarded request. A 
ThreadLocal<Boolean> indicates if the current invocation of doFilter(...) is 
the initial invocation in the filter chain. Cleanup is only done after the 
initial invocation completes.

Modified Paths:
--------------
    trunk/stripes/src/net/sourceforge/stripes/controller/StripesFilter.java

Modified: 
trunk/stripes/src/net/sourceforge/stripes/controller/StripesFilter.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/controller/StripesFilter.java     
2007-05-26 02:30:26 UTC (rev 554)
+++ trunk/stripes/src/net/sourceforge/stripes/controller/StripesFilter.java     
2007-05-26 15:45:50 UTC (rev 555)
@@ -60,9 +60,22 @@
      * Configuration.  Doing this allows multiple Stripes Configurations to 
exist in a single
      * Classloader since the Configuration is not located statically.
      */
-    private static ThreadLocal<Configuration> configurationStash = new 
ThreadLocal<Configuration>();
+    private static final ThreadLocal<Configuration> configurationStash = new 
ThreadLocal<Configuration>();
 
     /**
+     * Some operations should only be done if the current invocation of
+     * [EMAIL PROTECTED] #doFilter(ServletRequest, ServletResponse, 
FilterChain)} is the
+     * first in the filter chain. This [EMAIL PROTECTED] ThreadLocal} keeps 
track of
+     * whether such operations should be done or not.
+     */
+    private static final ThreadLocal<Boolean> initialInvocation = new 
ThreadLocal<Boolean>() {
+        @Override
+        protected Boolean initialValue() {
+            return true;
+        }
+    };
+
+    /**
      * Performs the necessary initialization for the StripesFilter.  Mainly 
this involves deciding
      * what configuration class to use, and then instantiating and 
initializing the chosen
      * Configuration.
@@ -143,6 +156,12 @@
         HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
         HttpServletResponse httpResponse = (HttpServletResponse) 
servletResponse;
 
+        // check the flag that indicates if this is the initial invocation
+        boolean initial = initialInvocation.get();
+        if (initial) {
+            initialInvocation.set(false);
+        }
+
         // Wrap pretty much everything in a try/catch so that we can funnel 
even the most
         // bizarre or unexpected exceptions into the exception handler
         try {
@@ -183,8 +202,13 @@
             this.configuration.getExceptionHandler().handle(t, httpRequest, 
httpResponse);
         }
         finally {
+            // reset the flag that indicates if this is the initial invocation
+            if (initial) {
+                initialInvocation.set(true);
+                flashOutbound(httpRequest);
+            }
+
             // Once the request is processed, take the Configuration back out 
of thread local
-            flashOutbound(httpRequest);
             StripesFilter.configurationStash.set(null);
         }
     }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to