01: /******************************************************************************
02: * JBoss, a division of Red Hat *
03: * Copyright 2006, Red Hat Middleware, LLC, and individual *
04: * contributors as indicated by the @authors tag. See the *
05: * copyright.txt in the distribution for a full listing of *
06: * individual contributors. *
07: * *
08: * This is free software; you can redistribute it and/or modify it *
09: * under the terms of the GNU Lesser General Public License as *
10: * published by the Free Software Foundation; either version 2.1 of *
11: * the License, or (at your option) any later version. *
12: * *
13: * This software is distributed in the hope that it will be useful, *
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16: * Lesser General Public License for more details. *
17: * *
18: * You should have received a copy of the GNU Lesser General Public *
19: * License along with this software; if not, write to the Free *
20: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
21: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
22: ******************************************************************************/package org.jboss.portal.portlet.aspects.portlet;
23:
24: import org.jboss.portal.common.invocation.InvocationException;
25: import org.jboss.portal.portlet.container.PortletContainer;
26: import org.jboss.portal.portlet.container.PortletContainerInvoker;
27: import org.jboss.portal.portlet.info.PortletInfo;
28: import org.jboss.portal.portlet.info.SessionInfo;
29: import org.jboss.portal.portlet.invocation.PortletInterceptor;
30: import org.jboss.portal.portlet.invocation.PortletInvocation;
31: import org.jboss.portal.portlet.session.SessionListener;
32: import org.jboss.portal.portlet.session.SubSession;
33:
34: import java.util.List;
35:
36: /**
37: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
38: * @version $Revision: 8784 $
39: */
40: public class PortletSessionSynchronizationInterceptor extends
41: PortletInterceptor {
42: protected Object invoke(PortletInvocation invocation)
43: throws Exception, InvocationException {
44: PortletContainer container = (PortletContainer) invocation
45: .getAttribute(PortletInvocation.INVOCATION_SCOPE,
46: PortletContainerInvoker.PORTLET_CONTAINER);
47: PortletInfo portletInfo = container.getInfo();
48: SessionInfo sessionInfo = portletInfo.getSession();
49:
50: if (sessionInfo != null
51: && Boolean.TRUE.equals(sessionInfo.getDistributed())) {
52: SubSession ss = (SubSession) invocation.getAttribute(
53: PortletInvocation.INVOCATION_SCOPE, "subsession");
54:
55: // If we detect an activation then we copy the content in the dispatched session
56: if (ss != null) {
57: ss.synchronizeWithDispatchedSession(invocation
58: .getDispatchedRequest());
59: }
60:
61: try {
62:
63: // Associate with thread after than the synchronization has been done
64: // because we don't want to have the http session listener modify the sub session
65: SessionListener.activate();
66:
67: //
68: return invocation.invokeNext();
69: } finally {
70: // Clear association with thread
71: List modifications = SessionListener.desactivate();
72:
73: // Set modifications for portal session synchronization
74: invocation.setAttribute(
75: PortletInvocation.INVOCATION_SCOPE,
76: "subsession", modifications);
77: }
78: } else {
79: return invocation.invokeNext();
80: }
81: }
82: }
|