Enable for async requests
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 7 Jun 2011 23:12:18 +0000 (23:12 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 7 Jun 2011 23:12:18 +0000 (23:12 +0000)
Don't persist the session if processing an async request. Note: There may be some async states where the session could be safely persisted.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1133193 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/valves/PersistentValve.java

index 3bf1fe5..5f0d0e2 100644 (file)
@@ -50,7 +50,7 @@ public class PersistentValve extends ValveBase {
 
     //------------------------------------------------------ Constructor
     public PersistentValve() {
-        super(false);
+        super(true);
     }
 
     // ----------------------------------------------------- Instance Variables
@@ -146,45 +146,52 @@ public class PersistentValve extends ValveBase {
         // Ask the next valve to process the request.
         getNext().invoke(request, response);
 
-        // Read the sessionid after the response.
-        // HttpSession hsess = hreq.getSession(false);
-        Session hsess;
-        try {
-            hsess = request.getSessionInternal();
-        } catch (Exception ex) {
-            hsess = null;
-        }
-        String newsessionId = null;
-        if (hsess!=null)
-            newsessionId = hsess.getIdInternal();
-
-        if (container.getLogger().isDebugEnabled())
-            container.getLogger().debug("newsessionId: " + newsessionId);
-        if (newsessionId!=null) {
-            /* store the session in the store and remove it from the manager */
-            if (manager instanceof PersistentManager) {
-                Session session = manager.findSession(newsessionId);
-                Store store = ((PersistentManager) manager).getStore();
-                if (store != null && session!=null &&
-                    session.isValid() &&
-                    !isSessionStale(session, System.currentTimeMillis())) {
-                    // ((StandardSession)session).passivate();
-                    store.save(session);
-                    ((PersistentManager) manager).removeSuper(session);
-                    session.recycle();
+        // If still processing async, don't try to store the session
+        // TODO: Are there some async states where it is would be safe to store
+        // the session?
+        if (!request.isAsync()) {
+            // Read the sessionid after the response.
+            // HttpSession hsess = hreq.getSession(false);
+            Session hsess;
+            try {
+                hsess = request.getSessionInternal();
+            } catch (Exception ex) {
+                hsess = null;
+            }
+            String newsessionId = null;
+            if (hsess!=null)
+                newsessionId = hsess.getIdInternal();
+    
+            if (container.getLogger().isDebugEnabled())
+                container.getLogger().debug("newsessionId: " + newsessionId);
+            if (newsessionId!=null) {
+                /* store the session and remove it from the manager */
+                if (manager instanceof PersistentManager) {
+                    Session session = manager.findSession(newsessionId);
+                    Store store = ((PersistentManager) manager).getStore();
+                    if (store != null && session!=null &&
+                        session.isValid() &&
+                        !isSessionStale(session, System.currentTimeMillis())) {
+                        // ((StandardSession)session).passivate();
+                        store.save(session);
+                        ((PersistentManager) manager).removeSuper(session);
+                        session.recycle();
+                    } else {
+                        if (container.getLogger().isDebugEnabled())
+                            container.getLogger().debug("newsessionId store: " +
+                                    store + " session: " + session +
+                                    " valid: " +
+                                    (session == null ? "N/A" : Boolean.toString(
+                                            session.isValid())) +
+                                    " stale: " + isSessionStale(session,
+                                            System.currentTimeMillis()));
+    
+                    }
                 } else {
                     if (container.getLogger().isDebugEnabled())
-                        container.getLogger().debug("newsessionId store: " +
-                                store + " session: " + session + " valid: " +
-                                (session == null ? "N/A" : Boolean.toString(
-                                        session.isValid())) +
-                                " stale: " + isSessionStale(session,
-                                        System.currentTimeMillis()));
-
+                        container.getLogger().debug("newsessionId Manager: " +
+                                manager);
                 }
-            } else {
-                if (container.getLogger().isDebugEnabled())
-                    container.getLogger().debug("newsessionId Manager: " + manager);
             }
         }
     }