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/03/08 00:57:14 UTC
svn commit: r1079037 - in
/myfaces/portlet-bridge/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces:
bridge/BridgeImpl.java context/PortletFacesContextImpl.java
util/QueryString.java
Author: mfreedman
Date: Mon Mar 7 23:57:14 2011
New Revision: 1079037
URL: http://svn.apache.org/viewvc?rev=1079037&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/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/BridgeImpl.java
myfaces/portlet-bridge/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletFacesContextImpl.java
myfaces/portlet-bridge/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/QueryString.java
Modified: myfaces/portlet-bridge/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/BridgeImpl.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/BridgeImpl.java?rev=1079037&r1=1079036&r2=1079037&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/BridgeImpl.java (original)
+++ myfaces/portlet-bridge/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/BridgeImpl.java Mon Mar 7 23:57:14 2011
@@ -90,9 +90,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.BridgeRenderRequestWrapper;
import org.apache.myfaces.portlet.faces.context.PortletExternalContextImpl;
import org.apache.myfaces.portlet.faces.el.PortletELContextImpl;
@@ -1584,6 +1587,45 @@ 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)
{
@@ -1837,7 +1879,7 @@ public class BridgeImpl
}
private final class RequestScopeListener
- implements HttpSessionBindingListener
+ implements HttpSessionBindingListener, HttpSessionActivationListener, Serializable
{
String mScopePrefix = null;
@@ -1856,5 +1898,39 @@ public class BridgeImpl
// Call is in the BridgeImpl class
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/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletFacesContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletFacesContextImpl.java?rev=1079037&r1=1079036&r2=1079037&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletFacesContextImpl.java (original)
+++ myfaces/portlet-bridge/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletFacesContextImpl.java Mon Mar 7 23:57:14 2011
@@ -334,22 +334,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());
}
Modified: myfaces/portlet-bridge/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/QueryString.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/QueryString.java?rev=1079037&r1=1079036&r2=1079037&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/QueryString.java (original)
+++ myfaces/portlet-bridge/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/QueryString.java Mon Mar 7 23:57:14 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;