You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2011/06/08 01:12:18 UTC

svn commit: r1133193 - /tomcat/trunk/java/org/apache/catalina/valves/PersistentValve.java

Author: markt
Date: Tue Jun  7 23:12:18 2011
New Revision: 1133193

URL: http://svn.apache.org/viewvc?rev=1133193&view=rev
Log:
Enable for async requests
Don't persist the session if processing an async request. Note: There may be some async states where the session could be safely persisted.

Modified:
    tomcat/trunk/java/org/apache/catalina/valves/PersistentValve.java

Modified: tomcat/trunk/java/org/apache/catalina/valves/PersistentValve.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/valves/PersistentValve.java?rev=1133193&r1=1133192&r2=1133193&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/valves/PersistentValve.java (original)
+++ tomcat/trunk/java/org/apache/catalina/valves/PersistentValve.java Tue Jun  7 23:12:18 2011
@@ -50,7 +50,7 @@ public class PersistentValve extends Val
 
     //------------------------------------------------------ Constructor
     public PersistentValve() {
-        super(false);
+        super(true);
     }
 
     // ----------------------------------------------------- Instance Variables
@@ -146,45 +146,52 @@ public class PersistentValve extends Val
         // 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);
             }
         }
     }



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