You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mf...@apache.org on 2011/02/17 23:33:39 UTC

svn commit: r1071817 - in /myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces: bridge/BridgeImpl.java context/PortletFacesContextImpl.java util/QueryString.java

Author: mfreedman
Date: Thu Feb 17 22:33:38 2011
New Revision: 1071817

URL: http://svn.apache.org/viewvc?rev=1071817&view=rev
Log:
PORTLETBRIDGE-183:  Potential NPE in FacesContxt.release
PORTLETBRIDGE-99:  Some session attributes not Serializable -- Exceptions thrown

Modified:
    myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/BridgeImpl.java
    myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletFacesContextImpl.java
    myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/util/QueryString.java

Modified: myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/BridgeImpl.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/BridgeImpl.java?rev=1071817&r1=1071816&r2=1071817&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/BridgeImpl.java (original)
+++ myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/BridgeImpl.java Thu Feb 17 22:33:38 2011
@@ -110,9 +110,12 @@ 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;
 import org.apache.myfaces.portlet.faces.context.PortletExternalContextImpl;
@@ -2497,6 +2500,46 @@ 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)
   {
@@ -2796,10 +2839,10 @@ public class BridgeImpl
     }
   }
 
-  private final class RequestScopeListener
-    implements HttpSessionBindingListener
+  private final class RequestScopeListener 
+    implements HttpSessionBindingListener, HttpSessionActivationListener, Serializable
   {
-    String mScopePrefix = null;
+    String mScopePrefix = null; 
 
     public RequestScopeListener(String scopePrefix)
     {
@@ -2813,8 +2856,46 @@ public class BridgeImpl
 
     public void valueUnbound(HttpSessionBindingEvent event)
     {
-      // Call is in the BridgeImpl class
+      // Call is in the BridgeImpl class -- note check for null 
+      // If we have passivated/reactivated
+      if (mScopePrefix != null)
+      {
+        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
+      /*
       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 (!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;
+      }
     }
   }
 }

Modified: myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletFacesContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletFacesContextImpl.java?rev=1071817&r1=1071816&r2=1071817&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletFacesContextImpl.java (original)
+++ myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletFacesContextImpl.java Thu Feb 17 22:33:38 2011
@@ -339,22 +339,25 @@ public class PortletFacesContextImpl ext
     // This is done because some (local) portals run/render all portlets in the same request
     PortletRequest request = (PortletRequest)mExternalContext.getRequest();
     List<String> preExistingAttrs = (List<String>) request.getAttribute(BridgeImpl.PREEXISTING_ATTRIBUTE_NAMES);
-    ArrayList<String> removeList = (ArrayList<String>) new ArrayList(preExistingAttrs.size());
-    Enumeration<String> e = request.getAttributeNames();
-    while (e.hasMoreElements())
+    if (preExistingAttrs != null)
     {
-      String name = e.nextElement();
-      if (!preExistingAttrs.contains(name))
+      ArrayList<String> removeList = (ArrayList<String>) new ArrayList(preExistingAttrs.size());
+      Enumeration<String> e = request.getAttributeNames();
+      while (e.hasMoreElements())
       {
-        // Postpone the remove until after the iteration as it causes a ConcurrentModificationException on some appServers (WebSphere)
-        removeList.add(name);
+        String name = e.nextElement();
+        if (!preExistingAttrs.contains(name))
+        {
+          // Postpone the remove until after the iteration as it causes a ConcurrentModificationException on some appServers (WebSphere)
+          removeList.add(name);
+        }
+      }
+      
+      // Postpone the remove until after the iteration as it causes a ConcurrentModificationException on some appServers (WebSphere)
+      for(Iterator<String> iter = removeList.iterator(); iter.hasNext();)
+      {
+        request.removeAttribute(iter.next());
       }
-    }
-    
-    // Postpone the remove until after the iteration as it causes a ConcurrentModificationException on some appServers (WebSphere)
-    for(Iterator<String> iter = removeList.iterator(); iter.hasNext();)
-    {
-      request.removeAttribute(iter.next());
     }
 
     if (mExternalContext != null && mExternalContext instanceof PortletExternalContextImpl)

Modified: myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/util/QueryString.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/util/QueryString.java?rev=1071817&r1=1071816&r2=1071817&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/util/QueryString.java (original)
+++ myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/util/QueryString.java Thu Feb 17 22:33:38 2011
@@ -19,6 +19,7 @@
 
 package org.apache.myfaces.portlet.faces.util;
 
+import java.io.Serializable;
 import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -31,7 +32,7 @@ import java.util.Map;
 /**
  * A class encapsulating an HTTP query string.
  */
-public final class QueryString
+public final class QueryString implements Serializable
 {
   private String mQueryString;
   private String mCharacterEncoding;
@@ -440,7 +441,7 @@ public final class QueryString
     }
   }
 
-  private class Parameter
+  private class Parameter implements Serializable
   {
     private String mName;
     private String mEncodedName;