Author: chris.laprun(a)jboss.com
Date: 2007-04-05 13:41:53 -0400 (Thu, 05 Apr 2007)
New Revision: 6927
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/MockWSRPConsumer.java
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/ProducerSessionInformationTestCase.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPConsumer.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistryService.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/InvocationHandler.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerSessionInformation.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RenderHandler.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/SessionHandler.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java
Log:
- Work on releaseSessions (needs more testing).
- Moved releaseSessions code to SessionHandler.
- Removed releaseSessions(String[]) from WSRPConsumer.
- ConsumerRegistryService.destroyConsumer now calls releaseSessions without failing.
- Make logger static where appropriate.
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/MockWSRPConsumer.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/MockWSRPConsumer.java 2007-04-05
15:09:59 UTC (rev 6926)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/MockWSRPConsumer.java 2007-04-05
17:41:53 UTC (rev 6927)
@@ -91,10 +91,6 @@
{
}
- public void releaseSessions(String[] sessionIds) throws PortletInvokerException
- {
- }
-
public void releaseSessions()
{
}
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/ProducerSessionInformationTestCase.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/ProducerSessionInformationTestCase.java 2007-04-05
15:09:59 UTC (rev 6926)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/ProducerSessionInformationTestCase.java 2007-04-05
17:41:53 UTC (rev 6927)
@@ -25,7 +25,6 @@
import junit.framework.TestCase;
import org.apache.commons.httpclient.Cookie;
-import org.jboss.portal.test.wsrp.framework.support.MockWSRPConsumer;
import org.jboss.portal.wsrp.WSRPConstants;
import org.jboss.portal.wsrp.WSRPTypeFactory;
import org.jboss.portal.wsrp.consumer.ProducerSessionInformation;
@@ -43,7 +42,6 @@
protected void setUp() throws Exception
{
info = new ProducerSessionInformation();
- info.setAssociatedConsumer(new MockWSRPConsumer("id"));
}
public void testUserCookie() throws Exception
@@ -127,7 +125,7 @@
assertEquals(sid2, info.getSessionIdForPortlet(handle2));
assertEquals(1, info.getNumberOfSessions());
- info.releaseSessionForPortlet(handle2);
+ info.removeSessionForPortlet(handle2);
assertEquals(0, info.getNumberOfSessions());
}
@@ -160,27 +158,27 @@
assertEquals(3, info.getNumberOfSessions());
- info.releaseSessions();
+ info.removeSessions();
assertEquals(0, info.getNumberOfSessions());
addSession("handle", "id", 1);
addSession("handle2", "id2", 2);
- info.releaseSession("id2");
+ info.removeSession("id2");
assertEquals(1, info.getNumberOfSessions());
assertNull(info.getSessionIdForPortlet("handle2"));
assertEquals("id", info.getSessionIdForPortlet("handle"));
- info.releaseSessionForPortlet("handle");
+ info.removeSessionForPortlet("handle");
assertEquals(0, info.getNumberOfSessions());
assertNull(info.getSessionIdForPortlet("handle"));
try
{
- info.releaseSessionForPortlet("handle");
+ info.removeSessionForPortlet("handle");
fail("Session for portlet 'handle' should have already been
released!");
}
catch (IllegalArgumentException expected)
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPConsumer.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPConsumer.java 2007-04-05 15:09:59 UTC
(rev 6926)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPConsumer.java 2007-04-05 17:41:53 UTC
(rev 6927)
@@ -99,19 +99,11 @@
void refreshProducerInfo() throws PortletInvokerException;
/**
- * Instructs the associated producer to release the specified sessions.
- *
- * @param sessionIds
- * @since 2.6
- */
- void releaseSessions(String[] sessionIds) throws PortletInvokerException;
-
- /**
* Releases all the sessions held by this Consumer
*
* @since 2.6
*/
- void releaseSessions();
+ void releaseSessions() throws PortletInvokerException;
/**
* Prepares this Consumer to be used: service is started, endpoints are ready.
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistryService.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistryService.java 2007-04-05
15:09:59 UTC (rev 6926)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistryService.java 2007-04-05
17:41:53 UTC (rev 6927)
@@ -103,7 +103,14 @@
{
ProducerInfo info = consumer.getProducerInfo();
-// consumer.releaseSessions(); // todo: fix, this is called from a different
thread than the one that sets the req in ServletAccess
+ try
+ {
+ consumer.releaseSessions();
+ }
+ catch (PortletInvokerException e)
+ {
+ log.debug("releaseSessions failed when attempting to destroy " +
CONSUMER_WITH_ID + id + "'");
+ }
registerOrDeregisterConsumerWith(id, false);
deactivateConsumerWith(id);
consumers.remove(id);
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/InvocationHandler.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/InvocationHandler.java 2007-04-05
15:09:59 UTC (rev 6926)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/InvocationHandler.java 2007-04-05
17:41:53 UTC (rev 6927)
@@ -51,7 +51,8 @@
{
protected WSRPConsumerImpl consumer;
- protected Logger log = Logger.getLogger(getClass());
+ protected static Logger log = Logger.getLogger(InvocationHandler.class);
+
/**
* Value indicating that we should not try further (unrecoverable error) for getMarkup
and
* processBlockingInteraction
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerSessionInformation.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerSessionInformation.java 2007-04-05
15:09:59 UTC (rev 6926)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerSessionInformation.java 2007-04-05
17:41:53 UTC (rev 6927)
@@ -28,10 +28,10 @@
import org.jboss.portal.common.util.ParameterValidation;
import org.jboss.portal.common.util.Tools;
import org.jboss.portal.wsrp.WSRPConstants;
-import org.jboss.portal.wsrp.WSRPConsumer;
import org.jboss.portal.wsrp.core.SessionContext;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -61,20 +61,8 @@
private Map sessionId2PortletHandle;
private Cookie[] userCookie;
+ private SessionHandler parent;
- private WSRPConsumer associatedConsumer;
-
- public void setAssociatedConsumer(WSRPConsumer associatedConsumer)
- {
- ParameterValidation.throwIllegalArgExceptionIfNull(associatedConsumer,
"Consumer");
- this.associatedConsumer = associatedConsumer;
- /*if (associatedConsumer instanceof WSRPConsumerImpl)
- {
- WSRPConsumerImpl consumer = (WSRPConsumerImpl)associatedConsumer;
- consumer.add
- }*/
- }
-
public String getUserCookie()
{
if (userCookie == null)
@@ -185,6 +173,11 @@
portletSessions.put(portletHandle, info);
sessionId2PortletHandle.put(sessionContext.getSessionID(), portletHandle);
+
+ if (parent != null)
+ {
+ parent.addSessionMapping(sessionContext.getSessionID(), this);
+ }
}
/**
@@ -218,7 +211,11 @@
}
}
- public void releaseSession(String sessionId)
+ /**
+ * @param sessionId
+ * @return the id of the removed session or <code>null</code> if the
session had already expired
+ */
+ public String removeSession(String sessionId)
{
ParameterValidation.throwIllegalArgExceptionIfNull(sessionId, "session
id");
@@ -228,10 +225,14 @@
throw new IllegalArgumentException("No such session id: '" +
sessionId + "'");
}
- releaseSessionForPortlet(portletHandle);
+ return removeSessionForPortlet(portletHandle);
}
- public void releaseSessions()
+ /**
+ * @return a list containing the session ids that were still valid when they were
removed and would need to be
+ * released
+ */
+ public List removeSessions()
{
List idsToRelease = new ArrayList(getNumberOfSessions());
@@ -250,52 +251,20 @@
}
}
- if (!idsToRelease.isEmpty())
- {
- releaseSessions((String[])idsToRelease.toArray(new String[0]));
- }
+ return idsToRelease;
}
- public void releaseSessionForPortlet(String portletHandle)
+ /**
+ * @param portletHandle
+ * @return the id of the removed session or <code>null</code> if the
session had already expired
+ */
+ public String removeSessionForPortlet(String portletHandle)
{
SessionIdResult result = removeSessionIdForPortlet(portletHandle);
- // if the session is still valid, release it and remove the associated mappings
- final String[] sessionIds;
- if (!result.expired)
- {
- sessionIds = new String[]{result.id};
- }
- else
- {
- sessionIds = null;
- }
-
- releaseSessions(sessionIds);
+ return result.expired ? null : result.id;
}
- private void releaseSessions(final String[] sessionIds)
- {
- if (sessionIds != null && sessionIds.length > 0)
- {
- Runnable releaseSession = new Runnable()
- {
- public void run()
- {
- try
- {
- associatedConsumer.releaseSessions(sessionIds);
- }
- catch (Exception e)
- {
- log.debug(e);
- }
- }
- };
- new Thread(releaseSession).start();
- }
- }
-
private SessionIdResult removeSessionIdForPortlet(String portletHandle)
{
ProducerSessionInformation.SessionIdResult result =
internalGetSessionIdForPortlet(portletHandle);
@@ -311,6 +280,10 @@
{
portletSessions.remove(portletHandle);
sessionId2PortletHandle.remove(id);
+ if (parent != null)
+ {
+ parent.removeSessionId(id);
+ }
}
return result;
@@ -379,6 +352,10 @@
{
portletSessions.remove(session.getPortletHandle());
sessionId2PortletHandle.remove(session.getSessionId());
+ if (parent != null)
+ {
+ parent.removeSessionId(session.getSessionId());
+ }
return new SessionIdResult(id, true);
}
else
@@ -401,6 +378,24 @@
return (SessionInfo)portletSessions.get(portletHandle);
}
+ /**
+ * @return
+ * @since 2.6
+ */
+ Collection getSessionIds()
+ {
+ return sessionId2PortletHandle.keySet();
+ }
+
+ /**
+ * @param sessionHandler
+ * @since 2.6
+ */
+ void setParent(SessionHandler sessionHandler)
+ {
+ parent = sessionHandler;
+ }
+
private class SessionInfo
{
private SessionContext sessionContext;
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RenderHandler.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RenderHandler.java 2007-04-05
15:09:59 UTC (rev 6926)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RenderHandler.java 2007-04-05
17:41:53 UTC (rev 6927)
@@ -23,7 +23,6 @@
package org.jboss.portal.wsrp.consumer;
-import org.jboss.logging.Logger;
import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.util.URLTools;
import org.jboss.portal.portlet.invocation.PortletInvocation;
@@ -196,7 +195,6 @@
private static class WSRPURLRewriter extends URLTools.URLReplacementGenerator
{
- protected Logger log = Logger.getLogger(getClass());
private PortletInvocationContext context;
private Boolean secure;
private Boolean authenticated;
@@ -237,8 +235,6 @@
private static class ResourceURLRewriter extends URLTools.URLReplacementGenerator
{
- protected Logger log = Logger.getLogger(getClass());
-
public String getReplacementFor(int currentIndex, URLTools.URLMatch currentMatch)
{
String urlAsString = currentMatch.getURLAsString();
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/SessionHandler.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/SessionHandler.java 2007-04-05
15:09:59 UTC (rev 6926)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/SessionHandler.java 2007-04-05
17:41:53 UTC (rev 6927)
@@ -33,13 +33,19 @@
import org.jboss.portal.wsrp.core.CookieProtocol;
import org.jboss.portal.wsrp.core.InitCookie;
import org.jboss.portal.wsrp.core.InvalidRegistrationFault;
+import org.jboss.portal.wsrp.core.ReleaseSessions;
import org.jboss.portal.wsrp.core.RuntimeContext;
import org.jboss.portal.wsrp.core.SessionContext;
import org.jboss.portal.wsrp.handler.RequestHeaderClientHandler;
import javax.servlet.http.HttpSession;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* Manages session informations on behalf of a consumer.
@@ -51,7 +57,7 @@
public class SessionHandler
{
protected WSRPConsumerImpl consumer;
- protected Logger log = Logger.getLogger(getClass());
+ private static Logger log = Logger.getLogger(SessionHandler.class);
/** Cookie protocol required by the producer with the consumer */
private CookieProtocol requiresInitCookie;
@@ -59,6 +65,8 @@
/** The prefix used to isolate WSRP-related session information in the actual session
object. */
private static final String SESSION_ID_PREFIX =
"org.jboss.portal.wsrp.session.";
+ private Map sessionInfos = new HashMap(); // todo: thread-safe?
+
/**
* Constructs a new SessionHandler.
*
@@ -237,7 +245,7 @@
if (sessionInformation != null)
{
- sessionInformation.setAssociatedConsumer(consumer);
+ sessionInformation.setParent(this);
}
else
{
@@ -245,7 +253,7 @@
{
sessionInformation = new ProducerSessionInformation();
session.setAttribute(producerSessionKey, sessionInformation);
- sessionInformation.setAssociatedConsumer(consumer);
+ sessionInformation.setParent(this);
}
}
@@ -270,7 +278,113 @@
private void invalidateSession(PortletInvocation invocation)
{
HttpSession session = WSRPConsumerImpl.getHttpSession(invocation);
+
+ // remove the associated info from the known producer session informations
+
+ ProducerSessionInformation info = getProducerSessionInformation(session, false);
+ if (info != null)
+ {
+ try
+ {
+ internalReleaseSessions(info.removeSessions());
+ }
+ catch (PortletInvokerException e)
+ {
+ // ignore since it's logged by internalReleaseSessions already
+ }
+ }
+
+
session.removeAttribute(getProducerSessionInformationKey());
RequestHeaderClientHandler.resetCurrentInfo();
}
+
+ /** @since 2.6 */
+ void releaseSessions() throws PortletInvokerException
+ {
+ List idsToRelease = new ArrayList(sessionInfos.size());
+
+ Set uniqueInfos = new HashSet(sessionInfos.values());
+
+ for (Iterator infos = uniqueInfos.iterator(); infos.hasNext();)
+ {
+ ProducerSessionInformation info = (ProducerSessionInformation)infos.next();
+ idsToRelease.add(info.removeSessions());
+ }
+
+ internalReleaseSessions(idsToRelease);
+ }
+
+ /**
+ * @param sessionIds
+ * @throws PortletInvokerException
+ * @since 2.6
+ */
+ void releaseSessions(String[] sessionIds) throws PortletInvokerException
+ {
+ if (sessionIds != null)
+ {
+ List idsToRelease = new ArrayList();
+
+ for (int i = 0; i < sessionIds.length; i++)
+ {
+ String sessionId = sessionIds[i];
+ ProducerSessionInformation info =
(ProducerSessionInformation)sessionInfos.get(sessionId);
+ sessionId = info.removeSession(sessionId);
+ if (sessionId != null)
+ {
+ idsToRelease.add(sessionId);
+ }
+ }
+
+ internalReleaseSessions(idsToRelease);
+ }
+ }
+
+ private void internalReleaseSessions(List idsToRelease) throws
PortletInvokerException
+ {
+ if (idsToRelease != null && !idsToRelease.isEmpty())
+ {
+ ReleaseSessions releaseSessions =
WSRPTypeFactory.createReleaseSessions(consumer.getRegistrationContext(),
+ (String[])idsToRelease.toArray(new String[0]));
+
+ try
+ {
+ consumer.getMarkupService().releaseSessions(releaseSessions);
+ }
+ catch (InvalidRegistrationFault invalidRegistrationFault)
+ {
+ log.debug("Invalid Registration");
+ consumer.handleInvalidRegistrationFault();
+ }
+ catch (Exception e)
+ {
+ log.debug(e);
+ throw new PortletInvokerException("Couldn't release sessions "
+ idsToRelease, e);
+ }
+ }
+ }
+
+ /**
+ * Update session mappings when a session has expired
+ *
+ * @param id
+ * @since 2.6
+ */
+ void removeSessionId(String id)
+ {
+ sessionInfos.remove(id);
+ }
+
+ /**
+ * Update session mappings when a new session id is added to the specified
ProducerSessionInformation
+ *
+ * @param sessionID
+ * @param producerSessionInformation
+ * @since 2.6
+ */
+ void addSessionMapping(String sessionID, ProducerSessionInformation
producerSessionInformation)
+ {
+ sessionInfos.put(sessionID, producerSessionInformation);
+ }
}
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java 2007-04-05
15:09:59 UTC (rev 6926)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java 2007-04-05
17:41:53 UTC (rev 6927)
@@ -54,12 +54,10 @@
import org.jboss.portal.wsrp.core.DestroyPortlets;
import org.jboss.portal.wsrp.core.DestroyPortletsResponse;
import org.jboss.portal.wsrp.core.GetPortletProperties;
-import org.jboss.portal.wsrp.core.InvalidRegistrationFault;
import org.jboss.portal.wsrp.core.Property;
import org.jboss.portal.wsrp.core.PropertyList;
import org.jboss.portal.wsrp.core.RegistrationContext;
import org.jboss.portal.wsrp.core.RegistrationData;
-import org.jboss.portal.wsrp.core.ReleaseSessions;
import org.jboss.portal.wsrp.core.ResetProperty;
import org.jboss.portal.wsrp.core.RuntimeContext;
import org.jboss.portal.wsrp.core.SetPortletProperties;
@@ -68,7 +66,6 @@
import org.jboss.portal.wsrp.core.WSRP_v1_Registration_PortType;
import org.jboss.portal.wsrp.core.WSRP_v1_ServiceDescription_PortType;
import org.jboss.portal.wsrp.services.ServiceFactory;
-import org.jboss.portal.wsrp.servlet.ServletAccess;
import org.jboss.portal.wsrp.servlet.UserAccess;
import javax.servlet.http.HttpServletRequest;
@@ -539,41 +536,11 @@
sessionHandler.setRequiresInitCookie(producerInfo.getRequiresInitCookie());
}
- public void releaseSessions(String[] sessionIds) throws PortletInvokerException
+ public void releaseSessions() throws PortletInvokerException
{
- //todo: move to SessionHandler?
- ReleaseSessions releaseSessions =
WSRPTypeFactory.createReleaseSessions(getRegistrationContext(), sessionIds);
-
- try
- {
- getMarkupService().releaseSessions(releaseSessions);
- }
- catch (InvalidRegistrationFault invalidRegistrationFault)
- {
- log.debug("Invalid Registration");
- handleInvalidRegistrationFault();
- }
- catch (Exception e)
- {
- log.debug(e);
- throw new PortletInvokerException("Couldn't release session '"
+ sessionIds + "'.", e);
- }
+ sessionHandler.releaseSessions();
}
- public void releaseSessions()
- {
- // todo: move to SessionHandler?
- HttpSession session = ServletAccess.getRequest().getSession(false);
- if (session != null)
- {
- ProducerSessionInformation info = getProducerSessionInformationFrom(session);
- if (info != null)
- {
- info.releaseSessions();
- }
- }
- }
-
// Support methods
**************************************************************************************************
private String getUserContextKeyFor(UserContext userContext)