Author: thomas.heute(a)jboss.com
Date: 2009-04-01 11:10:34 -0400 (Wed, 01 Apr 2009)
New Revision: 13108
Added:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/aspects/portlet/HttpHeaderInterceptor.java
Modified:
branches/JBoss_Portal_Branch_2_7/build/build-thirdparty.xml
branches/JBoss_Portal_Branch_2_7/core/src/resources/portal-core-sar/META-INF/jboss-service.xml
Log:
JBPORTAL-2361: Using PortletResponse.addProperty(javax.servlet.http.Cookie) does not set
the cookie in the response
Modified: branches/JBoss_Portal_Branch_2_7/build/build-thirdparty.xml
===================================================================
--- branches/JBoss_Portal_Branch_2_7/build/build-thirdparty.xml 2009-04-01 14:37:38 UTC
(rev 13107)
+++ branches/JBoss_Portal_Branch_2_7/build/build-thirdparty.xml 2009-04-01 15:10:34 UTC
(rev 13108)
@@ -67,7 +67,7 @@
<componentref name="jboss-portal/modules/common"
version="1.2.4"/>
<componentref name="jboss-portal/modules/web"
version="1.2.3"/>
<componentref name="jboss-portal/modules/test"
version="1.0.4"/>
- <componentref name="jboss-portal/modules/portlet"
version="2.0.5"/>
+ <componentref name="jboss-portal/modules/portlet"
version="trunk-SNAPSHOT"/>
<componentref name="jboss-portal/modules/identity"
version="1.0.8"/>
<componentref name="jboss-portal/modules/cms"
version="1.2.4"/>
<componentref name="antlr" version="2.7.6-brew"/>
Added:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/aspects/portlet/HttpHeaderInterceptor.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/aspects/portlet/HttpHeaderInterceptor.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/aspects/portlet/HttpHeaderInterceptor.java 2009-04-01
15:10:34 UTC (rev 13108)
@@ -0,0 +1,107 @@
+/******************************************************************************
+ * 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.core.aspects.portlet;
+
+import java.util.List;
+
+import org.jboss.portal.common.util.MultiValuedPropertyMap;
+import org.jboss.portal.core.metadata.portlet.MarkupElement;
+import org.jboss.portal.core.portlet.info.MarkupHeaderInfo;
+import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.portlet.impl.spi.AbstractServerContext;
+import org.jboss.portal.portlet.info.PortletInfo;
+import org.jboss.portal.portlet.invocation.PortletInvocation;
+import org.jboss.portal.portlet.invocation.response.FragmentResponse;
+import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.portlet.invocation.response.ResponseProperties;
+import org.jboss.portal.portlet.invocation.response.UpdateNavigationalStateResponse;
+import org.w3c.dom.Element;
+
+import javax.portlet.MimeResponse;
+import javax.servlet.http.Cookie;
+
+/**
+ * @author <a href="mailto:mholzner@novell.com">Martin Holzner</a>
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 11068 $
+ */
+public class HttpHeaderInterceptor extends CorePortletInterceptor
+{
+
+ private String defaultCookiePath = null;
+
+ /**
+ * Cookie path to set when none has been defined
+ */
+ public String getDefaultCookiePath()
+ {
+ return defaultCookiePath;
+ }
+
+ public void setDefaultCookiePath(String defaultCookiePath)
+ {
+ this.defaultCookiePath = defaultCookiePath;
+ }
+
+ public PortletInvocationResponse invoke(PortletInvocation invocation) throws
IllegalArgumentException,
+ PortletInvokerException
+ {
+
+ PortletInvocationResponse response = super.invoke(invocation);
+
+ if (response instanceof UpdateNavigationalStateResponse)
+ {
+ UpdateNavigationalStateResponse unsr = (UpdateNavigationalStateResponse)
response;
+ for (Cookie cookie : unsr.getProperties().getCookies())
+ {
+ addCookie(invocation, cookie);
+ }
+ for (String key: unsr.getProperties().getTransportHeaders().keySet())
+ {
+ String value = unsr.getProperties().getTransportHeaders().getValue(key);
+ ((AbstractServerContext)
invocation.getServerContext()).getResponse().addHeader(key, value);
+ }
+ }
+ else if (response instanceof FragmentResponse)
+ {
+ FragmentResponse fr = (FragmentResponse) response;
+ for (Cookie cookie : fr.getProperties().getCookies())
+ {
+ addCookie(invocation, cookie);
+ }
+ }
+
+ //
+ return response;
+ }
+
+ private void addCookie(PortletInvocation invocation, Cookie cookie)
+ {
+ if ((cookie.getPath() == null || "".equals(cookie.getPath().trim()))
&& defaultCookiePath != null)
+ {
+ cookie.setPath(defaultCookiePath);
+ }
+ ((AbstractServerContext)
invocation.getServerContext()).getResponse().addCookie(cookie);
+ }
+}
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/resources/portal-core-sar/META-INF/jboss-service.xml
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/resources/portal-core-sar/META-INF/jboss-service.xml 2009-04-01
14:37:38 UTC (rev 13107)
+++
branches/JBoss_Portal_Branch_2_7/core/src/resources/portal-core-sar/META-INF/jboss-service.xml 2009-04-01
15:10:34 UTC (rev 13108)
@@ -345,6 +345,12 @@
xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
<xmbean/>
</mbean>
+ <mbean
code="org.jboss.portal.core.aspects.portlet.HttpHeaderInterceptor"
+ name="portal:service=Interceptor,type=Portlet,name=HttpHeader"
xmbean-dd=""
+
xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
+ <xmbean/>
+ <attribute name="DefaultCookiePath">/</attribute>
+ </mbean>
<mbean code="org.jboss.portal.core.aspects.portlet.HeaderInterceptor"
name="portal:service=Interceptor,type=Portlet,name=Header"
xmbean-dd=""
xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
@@ -380,6 +386,7 @@
<depends-list optional-attribute-name="InterceptorNames">
<depends-list-element>portal:service=Interceptor,type=Portlet,name=Valve</depends-list-element>
<depends-list-element>portal:service=Interceptor,type=Portlet,name=SecureTransport</depends-list-element>
+
<depends-list-element>portal:service=Interceptor,type=Portlet,name=HttpHeader</depends-list-element>
<depends-list-element>portal:service=Interceptor,type=Portlet,name=ContextDispatcher</depends-list-element>
<depends-list-element>portal:service=Interceptor,type=Portlet,name=ContextTracker</depends-list-element>
<depends-list-element>portal:service=Interceptor,type=Portlet,name=PortletSessionSynchronization</depends-list-element>