Author: julien(a)jboss.com
Date: 2007-08-17 10:04:29 -0400 (Fri, 17 Aug 2007)
New Revision: 7974
Added:
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/aspects/portlet/PortalSessionSynchronizationInterceptor.java
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/aspects/portlet/PortletSessionSynchronizationInterceptor.java
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/session/
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/session/AttributeModification.java
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/session/Modification.java
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/session/SessionListener.java
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/session/SessionModification.java
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/session/SubSession.java
Removed:
branches/JBoss_Portal_Branch_2_6/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/PortalSessionSynchronizationInterceptor.java
branches/JBoss_Portal_Branch_2_6/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/PortletSessionSynchronizationInterceptor.java
branches/JBoss_Portal_Branch_2_6/portlet/src/main/org/jboss/portal/portlet/session/
Modified:
branches/JBoss_Portal_Branch_2_6/build/ide/intellij/idea60/modules/portlet-server/portlet-server.iml
Log:
moved the portlet session replication stuff from portlet to portlet-server as for now it
uses jboss related stuff
Modified:
branches/JBoss_Portal_Branch_2_6/build/ide/intellij/idea60/modules/portlet-server/portlet-server.iml
===================================================================
---
branches/JBoss_Portal_Branch_2_6/build/ide/intellij/idea60/modules/portlet-server/portlet-server.iml 2007-08-17
12:57:44 UTC (rev 7973)
+++
branches/JBoss_Portal_Branch_2_6/build/ide/intellij/idea60/modules/portlet-server/portlet-server.iml 2007-08-17
14:04:29 UTC (rev 7974)
@@ -76,6 +76,33 @@
<SOURCES />
</library>
</orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root
url="jar://$MODULE_DIR$/../../../../../../thirdparty/jboss-portal/modules/common/lib/portal-common-portal-lib.jar!/"
/>
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root
url="jar://$MODULE_DIR$/../../../../../../thirdparty/jboss-portal/modules/common/lib/portal-common-lib.jar!/"
/>
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root
url="jar://$MODULE_DIR$/../../../../../../thirdparty/apache-log4j/lib/log4j.jar!/"
/>
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
<orderEntryProperties />
</component>
<component name="VcsManagerConfiguration">
Deleted:
branches/JBoss_Portal_Branch_2_6/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/PortalSessionSynchronizationInterceptor.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/PortalSessionSynchronizationInterceptor.java 2007-08-17
12:57:44 UTC (rev 7973)
+++
branches/JBoss_Portal_Branch_2_6/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/PortalSessionSynchronizationInterceptor.java 2007-08-17
14:04:29 UTC (rev 7974)
@@ -1,119 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.portlet.aspects.portlet;
-
-import org.apache.log4j.Logger;
-import org.jboss.portal.common.invocation.InvocationException;
-import org.jboss.portal.portlet.invocation.PortletInterceptor;
-import org.jboss.portal.portlet.invocation.PortletInvocation;
-import org.jboss.portal.portlet.session.SubSession;
-import org.jboss.portal.portlet.spi.PortletInvocationContext;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-import java.lang.reflect.Method;
-import java.util.List;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public class PortalSessionSynchronizationInterceptor extends PortletInterceptor
-{
-
- /** . */
- private final Logger log =
Logger.getLogger(PortalSessionSynchronizationInterceptor.class);
-
- protected Object invoke(PortletInvocation invocation) throws Exception,
InvocationException
- {
- HttpServletRequest req = null;
-
- // We try to access the client request whenever this is possible
- // This should be better implemented and the task of using the portal session
- // Should be left up to the caller whenever it is possible
- try
- {
- PortletInvocationContext ctx = invocation.getPortletContext();
- Method getClientRequestMethod =
ctx.getClass().getMethod("getClientRequest", new Class[0]);
- req = (HttpServletRequest)getClientRequestMethod.invoke(ctx, new Object[0]);
- }
- catch (Exception ignore)
- {
- if (log.isDebugEnabled())
- {
- log.debug("Was not able to access the client request from request
context");
- }
- }
-
- if (req != null)
- {
- String id = invocation.getInstanceContext().getId();
- String key = "jboss.portlet.session." + id;
-
- // Try to get a sub session from the portal session
- SubSession ss = null;
- HttpSession session = req.getSession(false);
- if (session != null)
- {
- ss = (SubSession)session.getAttribute(key);
- }
-
- //
- try
- {
- // Set the sub session for the portlet synchronization
- if (ss != null && ss.isActivated())
- {
- invocation.setAttribute(PortletInvocation.INVOCATION_SCOPE,
"subsession", ss);
- }
-
- //
- return invocation.invokeNext();
- }
- finally
- {
- List modifications =
(List)invocation.getAttribute(PortletInvocation.INVOCATION_SCOPE,
"subsession");
-
- // If we have any modifications propagate them
- if (modifications != null)
- {
- //
- invocation.removeAttribute(PortletInvocation.INVOCATION_SCOPE,
"subsession");
-
- //
- if (ss == null)
- {
- ss = new SubSession(key);
- }
-
- //
- ss.synchronizeWithPortalSession(req, modifications, key);
- }
- }
- }
- else
- {
- return invocation.invokeNext();
- }
- }
-}
Deleted:
branches/JBoss_Portal_Branch_2_6/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/PortletSessionSynchronizationInterceptor.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/PortletSessionSynchronizationInterceptor.java 2007-08-17
12:57:44 UTC (rev 7973)
+++
branches/JBoss_Portal_Branch_2_6/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/PortletSessionSynchronizationInterceptor.java 2007-08-17
14:04:29 UTC (rev 7974)
@@ -1,83 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.portlet.aspects.portlet;
-
-import org.jboss.portal.common.invocation.InvocationException;
-import org.jboss.portal.portlet.info.PortletInfo;
-import org.jboss.portal.portlet.info.SessionInfo;
-import org.jboss.portal.portlet.invocation.PortletInterceptor;
-import org.jboss.portal.portlet.invocation.PortletInvocation;
-import org.jboss.portal.portlet.session.SessionListener;
-import org.jboss.portal.portlet.session.SubSession;
-import org.jboss.portal.portlet.container.PortletContainerInvoker;
-import org.jboss.portal.portlet.container.PortletContainer;
-
-import java.util.List;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public class PortletSessionSynchronizationInterceptor extends PortletInterceptor
-{
- protected Object invoke(PortletInvocation invocation) throws Exception,
InvocationException
- {
- PortletContainer container =
(PortletContainer)invocation.getAttribute(PortletInvocation.INVOCATION_SCOPE,
PortletContainerInvoker.PORTLET_CONTAINER);
- PortletInfo portletInfo = container.getInfo();
- SessionInfo sessionInfo = portletInfo.getSession();
-
- if (sessionInfo != null &&
Boolean.TRUE.equals(sessionInfo.getDistributed()))
- {
- SubSession ss =
(SubSession)invocation.getAttribute(PortletInvocation.INVOCATION_SCOPE,
"subsession");
-
- // If we detect an activation then we copy the content in the dispatched
session
- if (ss != null)
- {
- ss.synchronizeWithDispatchedSession(invocation.getDispatchedRequest());
- }
-
- try
- {
-
- // Associate with thread after than the synchronization has been done
- // because we don't want to have the http session listener modify the sub
session
- SessionListener.activate();
-
- //
- return invocation.invokeNext();
- }
- finally
- {
- // Clear association with thread
- List modifications = SessionListener.desactivate();
-
- // Set modifications for portal session synchronization
- invocation.setAttribute(PortletInvocation.INVOCATION_SCOPE,
"subsession", modifications);
- }
- }
- else
- {
- return invocation.invokeNext();
- }
- }
-}
Copied:
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/aspects/portlet/PortalSessionSynchronizationInterceptor.java
(from rev 7967,
branches/JBoss_Portal_Branch_2_6/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/PortalSessionSynchronizationInterceptor.java)
===================================================================
---
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/aspects/portlet/PortalSessionSynchronizationInterceptor.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/aspects/portlet/PortalSessionSynchronizationInterceptor.java 2007-08-17
14:04:29 UTC (rev 7974)
@@ -0,0 +1,119 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.aspects.portlet;
+
+import org.apache.log4j.Logger;
+import org.jboss.portal.common.invocation.InvocationException;
+import org.jboss.portal.portlet.invocation.PortletInterceptor;
+import org.jboss.portal.portlet.invocation.PortletInvocation;
+import org.jboss.portal.portlet.session.SubSession;
+import org.jboss.portal.portlet.spi.PortletInvocationContext;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import java.lang.reflect.Method;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision$
+ */
+public class PortalSessionSynchronizationInterceptor extends PortletInterceptor
+{
+
+ /** . */
+ private final Logger log =
Logger.getLogger(PortalSessionSynchronizationInterceptor.class);
+
+ protected Object invoke(PortletInvocation invocation) throws Exception,
InvocationException
+ {
+ HttpServletRequest req = null;
+
+ // We try to access the client request whenever this is possible
+ // This should be better implemented and the task of using the portal session
+ // Should be left up to the caller whenever it is possible
+ try
+ {
+ PortletInvocationContext ctx = invocation.getPortletContext();
+ Method getClientRequestMethod =
ctx.getClass().getMethod("getClientRequest", new Class[0]);
+ req = (HttpServletRequest)getClientRequestMethod.invoke(ctx, new Object[0]);
+ }
+ catch (Exception ignore)
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Was not able to access the client request from request
context");
+ }
+ }
+
+ if (req != null)
+ {
+ String id = invocation.getInstanceContext().getId();
+ String key = "jboss.portlet.session." + id;
+
+ // Try to get a sub session from the portal session
+ SubSession ss = null;
+ HttpSession session = req.getSession(false);
+ if (session != null)
+ {
+ ss = (SubSession)session.getAttribute(key);
+ }
+
+ //
+ try
+ {
+ // Set the sub session for the portlet synchronization
+ if (ss != null && ss.isActivated())
+ {
+ invocation.setAttribute(PortletInvocation.INVOCATION_SCOPE,
"subsession", ss);
+ }
+
+ //
+ return invocation.invokeNext();
+ }
+ finally
+ {
+ List modifications =
(List)invocation.getAttribute(PortletInvocation.INVOCATION_SCOPE,
"subsession");
+
+ // If we have any modifications propagate them
+ if (modifications != null)
+ {
+ //
+ invocation.removeAttribute(PortletInvocation.INVOCATION_SCOPE,
"subsession");
+
+ //
+ if (ss == null)
+ {
+ ss = new SubSession(key);
+ }
+
+ //
+ ss.synchronizeWithPortalSession(req, modifications, key);
+ }
+ }
+ }
+ else
+ {
+ return invocation.invokeNext();
+ }
+ }
+}
Property changes on:
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/aspects/portlet/PortalSessionSynchronizationInterceptor.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied:
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/aspects/portlet/PortletSessionSynchronizationInterceptor.java
(from rev 7967,
branches/JBoss_Portal_Branch_2_6/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/PortletSessionSynchronizationInterceptor.java)
===================================================================
---
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/aspects/portlet/PortletSessionSynchronizationInterceptor.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/aspects/portlet/PortletSessionSynchronizationInterceptor.java 2007-08-17
14:04:29 UTC (rev 7974)
@@ -0,0 +1,83 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.aspects.portlet;
+
+import org.jboss.portal.common.invocation.InvocationException;
+import org.jboss.portal.portlet.info.PortletInfo;
+import org.jboss.portal.portlet.info.SessionInfo;
+import org.jboss.portal.portlet.invocation.PortletInterceptor;
+import org.jboss.portal.portlet.invocation.PortletInvocation;
+import org.jboss.portal.portlet.session.SessionListener;
+import org.jboss.portal.portlet.session.SubSession;
+import org.jboss.portal.portlet.container.PortletContainerInvoker;
+import org.jboss.portal.portlet.container.PortletContainer;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision$
+ */
+public class PortletSessionSynchronizationInterceptor extends PortletInterceptor
+{
+ protected Object invoke(PortletInvocation invocation) throws Exception,
InvocationException
+ {
+ PortletContainer container =
(PortletContainer)invocation.getAttribute(PortletInvocation.INVOCATION_SCOPE,
PortletContainerInvoker.PORTLET_CONTAINER);
+ PortletInfo portletInfo = container.getInfo();
+ SessionInfo sessionInfo = portletInfo.getSession();
+
+ if (sessionInfo != null &&
Boolean.TRUE.equals(sessionInfo.getDistributed()))
+ {
+ SubSession ss =
(SubSession)invocation.getAttribute(PortletInvocation.INVOCATION_SCOPE,
"subsession");
+
+ // If we detect an activation then we copy the content in the dispatched
session
+ if (ss != null)
+ {
+ ss.synchronizeWithDispatchedSession(invocation.getDispatchedRequest());
+ }
+
+ try
+ {
+
+ // Associate with thread after than the synchronization has been done
+ // because we don't want to have the http session listener modify the sub
session
+ SessionListener.activate();
+
+ //
+ return invocation.invokeNext();
+ }
+ finally
+ {
+ // Clear association with thread
+ List modifications = SessionListener.desactivate();
+
+ // Set modifications for portal session synchronization
+ invocation.setAttribute(PortletInvocation.INVOCATION_SCOPE,
"subsession", modifications);
+ }
+ }
+ else
+ {
+ return invocation.invokeNext();
+ }
+ }
+}
Property changes on:
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/aspects/portlet/PortletSessionSynchronizationInterceptor.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added:
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/session/AttributeModification.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/session/AttributeModification.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/session/AttributeModification.java 2007-08-17
14:04:29 UTC (rev 7974)
@@ -0,0 +1,55 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.session;
+
+/**
+ * A modification made to an attribute within the scope of a request.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 5448 $
+ */
+public class AttributeModification extends Modification
+{
+
+ /** The name. */
+ private String name;
+
+ /** The value. */
+ private Object value;
+
+ public AttributeModification(String name, Object value)
+ {
+ this.name = name;
+ this.value = value;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public Object getValue()
+ {
+ return value;
+ }
+}
Property changes on:
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/session/AttributeModification.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/session/Modification.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/session/Modification.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/session/Modification.java 2007-08-17
14:04:29 UTC (rev 7974)
@@ -0,0 +1,31 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.session;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 5448 $
+ */
+public class Modification
+{
+}
Property changes on:
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/session/Modification.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/session/SessionListener.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/session/SessionListener.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/session/SessionListener.java 2007-08-17
14:04:29 UTC (rev 7974)
@@ -0,0 +1,172 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.session;
+
+import org.jboss.logging.Logger;
+
+import javax.portlet.PortletSession;
+import javax.portlet.PortletSessionUtil;
+import javax.servlet.http.HttpSessionAttributeListener;
+import javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Listener for various session events that modifies the subsession associated with the
current thread of execution.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 5448 $
+ */
+public class SessionListener implements HttpSessionAttributeListener,
HttpSessionListener
+{
+
+ /** . */
+ private Logger log = Logger.getLogger(SessionListener.class);
+
+ /** . */
+ private boolean trace = log.isTraceEnabled();
+
+ /** . */
+ private static ThreadLocal local = new ThreadLocal();
+
+ public void attributeAdded(HttpSessionBindingEvent event)
+ {
+ List modifications = (List)local.get();
+ if (modifications != null)
+ {
+ String name = event.getName();
+ // Only PortletScope attributes are synchronized
+ if (PortletSessionUtil.decodeScope(name) == PortletSession.PORTLET_SCOPE)
+ {
+ if (trace)
+ {
+ String id = event.getSession().getId();
+ log.trace("Adding attribute " + name + " to session "
+ id);
+ }
+ Object value = event.getValue();
+ // ss.setAttribute(name, value);
+ AttributeModification mod = new AttributeModification(name, value);
+ modifications.add(mod);
+ }
+ }
+ }
+
+ public void attributeRemoved(HttpSessionBindingEvent event)
+ {
+ List modifications = (List)local.get();
+ if (modifications != null)
+ {
+ String name = event.getName();
+ // Only PortletScope attributes are synchronized
+ if (PortletSessionUtil.decodeScope(name) == PortletSession.PORTLET_SCOPE)
+ {
+ if (trace)
+ {
+ String id = event.getSession().getId();
+ log.trace("Removing attribute " + name + " to session
" + id);
+ }
+// ss.setAttribute(name, null);
+ AttributeModification mod = new AttributeModification(name, null);
+ modifications.add(mod);
+ }
+ }
+ }
+
+ public void attributeReplaced(HttpSessionBindingEvent event)
+ {
+ List modifications = (List)local.get();
+ if (modifications != null)
+ {
+ String name = event.getName();
+ // Only PortletScope attributes are synchronized
+ if (PortletSessionUtil.decodeScope(name) == PortletSession.PORTLET_SCOPE)
+ {
+ if (trace)
+ {
+ String id = event.getSession().getId();
+ log.trace("Replacing attribute " + name + " to session
" + id);
+ }
+ // Get the value from the session as the event payload is the previous value
+ Object value = event.getSession().getAttribute(name);
+// ss.setAttribute(name, value);
+ AttributeModification mod = new AttributeModification(name, value);
+ modifications.add(mod);
+ }
+ }
+ }
+
+ //
+
+ public void sessionCreated(HttpSessionEvent event)
+ {
+ List modifications = (List)local.get();
+ if (modifications != null)
+ {
+ if (trace)
+ {
+ String id = event.getSession().getId();
+ log.trace("Creating session " + id);
+ }
+// ss.create();
+ modifications.add(SessionModification.SESSION_CREATED);
+ }
+ }
+
+ public void sessionDestroyed(HttpSessionEvent event)
+ {
+ List modifications = (List)local.get();
+ if (modifications != null)
+ {
+ if (trace)
+ {
+ String id = event.getSession().getId();
+ log.trace("Destroying session " + id);
+ }
+// ss.destroy();
+ modifications.add(SessionModification.SESSION_DESTROYED);
+ }
+ }
+
+ /** @throws IllegalStateException */
+ public static void activate() throws IllegalStateException
+ {
+ if (local.get() != null)
+ {
+ throw new IllegalStateException("Already active");
+ }
+ local.set(new ArrayList());
+ }
+
+ public static List desactivate() throws IllegalStateException
+ {
+ List modifications = (List)SessionListener.local.get();
+ if (modifications == null)
+ {
+ throw new IllegalStateException("No active");
+ }
+ SessionListener.local.set(null);
+ return modifications;
+ }
+}
Property changes on:
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/session/SessionListener.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/session/SessionModification.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/session/SessionModification.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/session/SessionModification.java 2007-08-17
14:04:29 UTC (rev 7974)
@@ -0,0 +1,56 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.session;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 5448 $
+ */
+public class SessionModification extends Modification
+{
+
+ /** . */
+ public static final int CREATED = 0;
+
+ /** . */
+ public static final int DESTROYED = 1;
+
+ /** . */
+ public static final SessionModification SESSION_CREATED = new
SessionModification(CREATED);
+
+ /** . */
+ public static final SessionModification SESSION_DESTROYED = new
SessionModification(DESTROYED);
+
+ /** . */
+ private int type;
+
+ private SessionModification(int type)
+ {
+ this.type = type;
+ }
+
+ public int getType()
+ {
+ return type;
+ }
+}
Property changes on:
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/session/SessionModification.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/session/SubSession.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/session/SubSession.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/session/SubSession.java 2007-08-17
14:04:29 UTC (rev 7974)
@@ -0,0 +1,353 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.session;
+
+import org.jboss.invocation.MarshalledValue;
+import org.jboss.logging.Logger;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A subsession keep tracks of the content of a given portlet session.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 5448 $
+ */
+public class SubSession implements Externalizable
+{
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -3584568048652090636L;
+
+ /** . */
+ private static final Logger log = Logger.getLogger(SubSession.class);
+
+ /** . */
+ private boolean trace = log.isTraceEnabled();
+
+ /** Signals that the session has been activated. */
+ private boolean activated;
+
+ /** The session content. */
+ private Map map;
+
+ /** The id. */
+ private String id;
+
+ public SubSession(String id)
+ {
+ if (id == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ this.id = id;
+ this.activated = false;
+ }
+
+ public SubSession()
+ {
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public boolean isActivated()
+ {
+ return activated;
+ }
+
+ public void setActivated(boolean activated)
+ {
+ this.activated = activated;
+ }
+
+ public Set getAttributeNames()
+ {
+ if (map != null)
+ {
+ return map.keySet();
+ }
+ else
+ {
+ return Collections.EMPTY_SET;
+ }
+ }
+
+ public Object getAttribute(String name)
+ {
+ trace("getAttribute: trying to get attribute named: '" + name +
"'");
+ if (map != null)
+ {
+ return map.get(name);
+ }
+ else
+ {
+ trace("getAttribute: no existing attributes.");
+ return null;
+ }
+ }
+
+ public void setAttribute(String name, Object value)
+ {
+ if (map == null)
+ {
+ map = new HashMap();
+ trace("setAttribute: no existing attributes, creating attribute
map.");
+ }
+ if (name == null || name.length() == 0)
+ {
+ throw new IllegalArgumentException("Must pass a valid, non-null attribute
to set the attribute value.");
+ }
+ if (value == null)
+ {
+ trace("setAttribute: removing attribute named: '" + name +
"'");
+ map.remove(name);
+ }
+ else
+ {
+ trace("setAttribute: set attribute named: '" + name + "'
to value: '" + value + "'");
+ map.put(name, value);
+ }
+ }
+
+ public void create()
+ {
+ trace("create");
+ if (map != null)
+ {
+ trace("create: was expecting no map, had to clear it");
+ map.clear();
+ }
+ else
+ {
+ trace("create: attribute map created");
+ map = new HashMap();
+ }
+ }
+
+ public void destroy()
+ {
+ trace("destroy");
+ if (map == null)
+ {
+ trace("destroy: was expecting an attribute map");
+ }
+ else
+ {
+ trace("destroy: attribute map destroyed");
+ map = null;
+ }
+ }
+
+ /**
+ * @param portalRequest
+ * @param key
+ */
+ public void synchronizeWithPortalSession(HttpServletRequest portalRequest, List
modifications, String key)
+ {
+ // Apply changes
+ for (Iterator i = modifications.iterator(); i.hasNext();)
+ {
+ Modification mod = (Modification)i.next();
+ if (mod instanceof AttributeModification)
+ {
+ try
+ {
+ AttributeModification attrMod = (AttributeModification)mod;
+ setAttribute(attrMod.getName(), new MarshalledValue(attrMod.getValue()));
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace(); //To change body of catch statement use File |
Settings | File Templates.
+ }
+ }
+ else if (mod == SessionModification.SESSION_CREATED)
+ {
+ create();
+ }
+ else
+ {
+ destroy();
+ }
+ }
+
+ //
+ if (modifications.isEmpty() == false)
+ {
+ // Performs an explicit set
+ HttpSession session = portalRequest.getSession();
+ session.setAttribute(key, this);
+ }
+ }
+
+ /**
+ * Synchronize the content with the session held by the dispatched request. This
method will use the thread context
+ * classloader to unserialize the content of the session.
+ *
+ * @param dispatchedRequest
+ */
+ public void synchronizeWithDispatchedSession(HttpServletRequest dispatchedRequest)
+ {
+ if (activated)
+ {
+ trace("synchronizeWithDispatchedSession: session was activated,
synchronizing...");
+ activated = false;
+
+ //
+ HttpSession session = dispatchedRequest.getSession();
+
+ //
+ trace("synchronizeWithDispatchedSession: removing existing
attributes");
+ ArrayList names = new ArrayList();
+ for (Enumeration e = session.getAttributeNames(); e.hasMoreElements();)
+ {
+ String name = (String)e.nextElement();
+ names.add(name);
+ }
+ for (int i = 0; i < names.size(); i++)
+ {
+ String name = (String)names.get(i);
+ trace("synchronizeWithDispatchedSession: removing attribute named:
'" + name + "' with value: '"
+ + session.getAttribute(name) + "' from existing session");
+ session.removeAttribute(name);
+ }
+
+ //
+ for (Iterator i = map.entrySet().iterator(); i.hasNext();)
+ {
+ Map.Entry entry = (Map.Entry)i.next();
+ String name = (String)entry.getKey();
+
+ //
+ try
+ {
+ MarshalledValue marshalledValue = (MarshalledValue)entry.getValue();
+ Object value = marshalledValue.get();
+
+ //
+ session.setAttribute(name, value);
+ trace("synchronizeWithDispatchedSession: setting attribute name:
'" + name + "' to value: '" + value
+ + "'");
+ }
+ catch (Exception e)
+ {
+ log.error("synchronizeWithDispatchedSession: couldn't unmarshall
value for attribute named: '" + name
+ + "'. Session won't be properly replicated!", e);
+ }
+ }
+ }
+ else
+ {
+ trace("synchronizeWithDispatchedSession: session was not activated, did
nothing");
+ }
+ }
+
+// private void marshallAttributesAndUpdateSessionIfNeeded(HttpSession session)
+// {
+// if (map != null)
+// {
+// for (Iterator i = map.entrySet().iterator(); i.hasNext();)
+// {
+// Map.Entry entry = (Map.Entry)i.next();
+// String name = (String)entry.getKey();
+// MarshalledValue marshalledValue = (MarshalledValue)entry.getValue();
+//
+// //
+// try
+// {
+// Object value = marshalledValue.get();
+// entry.setValue(value); // replace marshalled value by original one
+// trace("synchronizeWithDispatchedSession: setting attribute name:
'" + name + "' to value: '" + value
+// + "'");
+//
+// // update session if requested
+// if (session != null)
+// {
+// session.setAttribute(name, value);
+// }
+// }
+// catch (Exception e)
+// {
+// log.error("synchronizeWithDispatchedSession: couldn't
unmarshall value for attribute named: '" + name
+// + "'. Session won't be properly replicated!", e);
+// }
+// }
+// }
+// }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ id = in.readUTF();
+ map = (Map)in.readObject();
+ activated = true;
+ if (trace)
+ {
+ log("SubSession deserialized");
+ }
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ out.writeUTF(id);
+ out.writeObject(map);
+ if (trace)
+ {
+ log("SubSession serialized");
+ }
+ }
+
+ private void log(String prefix)
+ {
+ StringBuffer tmp = new StringBuffer(prefix).append(" [");
+ for (Iterator i = map.keySet().iterator(); i.hasNext();)
+ {
+ String key = (String)i.next();
+
tmp.append(key).append("(").append(map.get(key)).append(")").append(i.hasNext()
? "," : "");
+ }
+ tmp.append("]");
+ trace(tmp.toString());
+ }
+
+ private void trace(String message)
+ {
+ if (trace)
+ {
+ log.trace(message);
+ }
+ }
+}
Property changes on:
branches/JBoss_Portal_Branch_2_6/portlet-server/src/main/org/jboss/portal/portlet/session/SubSession.java
___________________________________________________________________
Name: svn:executable
+ *