myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfreed...@apache.org
Subject svn commit: r1456999 - /myfaces/portlet-bridge/core/branches/WLP_10.3.5/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/BridgeImpl.java
Date Fri, 15 Mar 2013 16:17:03 GMT
Author: mfreedman
Date: Fri Mar 15 16:17:02 2013
New Revision: 1456999

URL: http://svn.apache.org/r1456999
Log:
Updated WLP 10.3.5 (and prior) version with fix for PORTLETBRIDGE-99:  RequestScopeListener
not serializable

Modified:
    myfaces/portlet-bridge/core/branches/WLP_10.3.5/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/BridgeImpl.java

Modified: myfaces/portlet-bridge/core/branches/WLP_10.3.5/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/BridgeImpl.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/branches/WLP_10.3.5/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/BridgeImpl.java?rev=1456999&r1=1456998&r2=1456999&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/branches/WLP_10.3.5/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/BridgeImpl.java
(original)
+++ myfaces/portlet-bridge/core/branches/WLP_10.3.5/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/BridgeImpl.java
Fri Mar 15 16:17:02 2013
@@ -99,8 +99,10 @@ import javax.servlet.ServletRequestAttri
 import javax.servlet.ServletRequestAttributeListener;
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionActivationListener;
 import javax.servlet.http.HttpSessionBindingEvent;
 import javax.servlet.http.HttpSessionBindingListener;
+import javax.servlet.http.HttpSessionEvent;
 
 import org.apache.myfaces.portlet.faces.bridge.wrapper.BridgePortletRequestWrapper;
 import org.apache.myfaces.portlet.faces.bridge.wrapper.BridgeRenderRequestWrapper;
@@ -1951,9 +1953,12 @@ public class BridgeImpl
         // if invalidated we walk the entire REQUEST_SCOPE Map and
         // remove
         // every scope that starts with this prefix.
-        session.setAttribute(REQUEST_SCOPE_LISTENER,
-                             new RequestScopeListener(qualifyScopeId(mPortletConfig.getPortletName(),

-                                                                     session.getId(), null,
null)));
+        session.setAttribute(REQUEST_SCOPE_LISTENER, 
+                             new RequestScopeListener(this, 
+                                                      qualifyScopeId(mPortletConfig.getPortletName(),

+                                                                     session.getId(), 
+                                                                     null, 
+                                                                     null)));
       }
     }
   }
@@ -2153,6 +2158,47 @@ public class BridgeImpl
     }
   }
 
+  // tests to see if any scopes exist that start with the given prefix
+  // used during session reactivation to test/remove session attr (listener) that is no longer
needed
+
+  private boolean hasRequestScopes(String scopePrefix)
+  {
+
+    if (scopePrefix == null || mPortletConfig == null)
+      return false; // Nothing to do -- later case is the session is destroyed after the
context
+
+    // Get the RequestScope Map and remove all entries/scopes with this prefix
+    PortletContext portletContext = mPortletConfig.getPortletContext();
+
+    // Get the request scope lock -- because its added during init it should
+    // always be there.
+    Object lock = portletContext.getAttribute(REQUEST_SCOPE_LOCK);
+    if (lock == null)
+      return false;
+
+    synchronized (lock)
+    {
+      // get the managedScopeMap
+      LRUMap requestScopeMap = 
+        (LRUMap) portletContext.getAttribute(REQUEST_SCOPE_MAP);
+
+      if (requestScopeMap != null)
+      {
+        Iterator<String> iterator = requestScopeMap.keySet().iterator();
+        while (iterator.hasNext())
+        {
+          String scopeId = iterator.next();
+          if (scopeId != null && scopeId.startsWith(scopePrefix))
+          {
+            // found one
+            return true;
+          }
+        }
+      }
+    }
+    return false;
+  }
+
   private void removeRequestScopes(String scopePrefix)
   {
 
@@ -2344,13 +2390,15 @@ public class BridgeImpl
     }
   }
 
-  private final class RequestScopeListener
-    implements HttpSessionBindingListener
+  private final static class RequestScopeListener 
+    implements HttpSessionBindingListener, HttpSessionActivationListener, Serializable
   {
-    String mScopePrefix = null;
+    private transient BridgeImpl mBridgeImpl = null;
+    String mScopePrefix = null; 
 
-    public RequestScopeListener(String scopePrefix)
+    public RequestScopeListener(BridgeImpl bridgeImpl, String scopePrefix)
     {
+      mBridgeImpl = bridgeImpl;
       mScopePrefix = scopePrefix;
     }
 
@@ -2361,8 +2409,48 @@ public class BridgeImpl
 
     public void valueUnbound(HttpSessionBindingEvent event)
     {
-      // Call is in the BridgeImpl class
-      removeRequestScopes(mScopePrefix);
+      // Call is in the BridgeImpl class -- note check for null 
+      // If we have passivated/reactivated
+      if (mBridgeImpl != null && mScopePrefix != null)
+      {
+        mBridgeImpl.removeRequestScopes(mScopePrefix);
+      }
+    }
+    
+    public void sessionWillPassivate(HttpSessionEvent se)
+    {  
+      // TODO: is passivate only called when the session is migrated or just saved?
+      //     -- i.e. is this a safe time to remove the scopes from the AppContext in the
"old" context?
+      //     Until we get confirmation that it is -- do not remove
+      /*
+      if (mBridgeImpl != null)
+      {
+        mBridgeImpl.removeRequestScopes(mScopePrefix);
+      } 
+      RequestScopeListener rl = (RequestScopeListener) se.getSession().getAttribute(REQUEST_SCOPE_LISTENER);
+      if (rl != null && rl.equals(this))
+      {
+        se.getSession().removeAttribute(REQUEST_SCOPE_LISTENER);
+      }
+      
+      mScopePrefix = null;
+      */
+
+    }
+
+    public void sessionDidActivate(HttpSessionEvent se)
+    {
+      // If we migrsated to a new Context or otherwise can't reach these scopes anymore then

+      // drop the listener.
+      if (mBridgeImpl == null || !mBridgeImpl.hasRequestScopes(mScopePrefix))
+      {
+        RequestScopeListener rl = (RequestScopeListener) se.getSession().getAttribute(REQUEST_SCOPE_LISTENER);
+        if (rl != null && rl.equals(this))
+        {
+          se.getSession().removeAttribute(REQUEST_SCOPE_LISTENER);
+        }
+        mScopePrefix = null;
+      }
     }
   }
 }



Mime
View raw message