Author: julien(a)jboss.com
Date: 2008-01-24 16:33:17 -0500 (Thu, 24 Jan 2008)
New Revision: 9600
Added:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/ResponseProperties.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/ext/portletresponses/
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/ext/portletresponses/WriteCookiesTestCase.java
modules/portlet/trunk/test/src/test/resources/jsr286/ext/portletresponses-war/
modules/portlet/trunk/test/src/test/resources/jsr286/ext/portletresponses-war/WEB-INF/
modules/portlet/trunk/test/src/test/resources/jsr286/ext/portletresponses-war/WEB-INF/portlet.xml
modules/portlet/trunk/test/src/test/resources/jsr286/ext/portletresponses-war/WEB-INF/web.xml
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/MimeResponseImpl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletResponseImpl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/StateAwareResponseImpl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/spi/AbstractClientContext.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/FragmentResponse.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/UpdateNavigationalStateResponse.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortalServlet.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletController.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletControllerContextImpl.java
modules/portlet/trunk/test/src/test/build.xml
modules/portlet/trunk/test/src/test/resources/test/remote-jboss-unit.xml
Log:
- implemented response cookies handling
- added test cases for response cookies
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/MimeResponseImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/MimeResponseImpl.java 2008-01-24
21:27:57 UTC (rev 9599)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/MimeResponseImpl.java 2008-01-24
21:33:17 UTC (rev 9600)
@@ -63,6 +63,9 @@
public PortletInvocationResponse getResponse()
{
+ result.setProperties(getProperties(false));
+
+ //
return result;
}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletResponseImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletResponseImpl.java 2008-01-24
21:27:57 UTC (rev 9599)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletResponseImpl.java 2008-01-24
21:33:17 UTC (rev 9600)
@@ -24,16 +24,16 @@
import org.jboss.portal.portlet.invocation.PortletInvocation;
import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.portlet.invocation.response.ResponseProperties;
import org.jboss.portal.portlet.impl.jsr168.PortletUtils;
-import org.jboss.portal.common.invocation.AttributeResolver;
-import org.jboss.portal.common.NotYetImplemented;
import org.w3c.dom.Element;
import org.w3c.dom.DOMException;
+import org.w3c.dom.Document;
import javax.portlet.PortletResponse;
import javax.servlet.http.Cookie;
-import java.util.Collection;
-import java.util.ArrayList;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -49,8 +49,14 @@
protected final PortletRequestImpl preq;
/** The namespace. */
- protected String namespace;
+ private String namespace;
+ /** . */
+ private Document doc;
+
+ /** . */
+ private ResponseProperties properties;
+
protected PortletResponseImpl(PortletInvocation invocation, PortletRequestImpl preq)
{
this.invocation = invocation;
@@ -80,23 +86,7 @@
}
//
- AttributeResolver resolver =
invocation.getContext().getAttributeResolver(PortletInvocation.RESPONSE_PROPERTIES_SCOPE);
- Object prop = resolver.getAttribute(key);
- if (prop == null)
- {
- resolver.setAttribute(key, prop);
- }
- else if (prop instanceof Collection)
- {
- ((Collection<String>)prop).add(value);
- }
- else
- {
- Collection<String> c = new ArrayList<String>();
- c.add((String)prop);
- c.add(value);
- resolver.setAttribute(key, c);
- }
+ getProperties().getTransportHeaders().addProperty(key, value);
}
public void setProperty(String key, String value) throws IllegalArgumentException
@@ -111,9 +101,38 @@
}
//
- invocation.setAttribute(PortletInvocation.RESPONSE_PROPERTIES_SCOPE, key, value);
+ getProperties().getTransportHeaders().setProperty(key, value);
}
+ public void addProperty(Cookie cookie)
+ {
+ getProperties().getCookies().add(cookie);
+ }
+
+ public void addProperty(String key, Element element)
+ {
+ getProperties().getMarkupHeaders().addProperty(key, element);
+ }
+
+ public Element createElement(String tagName) throws DOMException
+ {
+ if (doc == null)
+ {
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ doc = factory.newDocumentBuilder().newDocument();
+ }
+ catch (ParserConfigurationException e)
+ {
+ throw new IllegalStateException("Could not create a document builder
factory", e);
+ }
+ }
+
+ //
+ return doc.createElement(tagName);
+ }
+
public String getNamespace()
{
if (namespace == null)
@@ -124,20 +143,17 @@
return namespace;
}
- public void addProperty(Cookie cookie)
+ protected final ResponseProperties getProperties()
{
- throw new NotYetImplemented();
+ return getProperties(true);
}
- public void addProperty(String s, Element element)
+ protected final ResponseProperties getProperties(boolean create)
{
- throw new NotYetImplemented();
+ if (properties == null && create)
+ {
+ properties = new ResponseProperties();
+ }
+ return properties;
}
-
- public Element createElement(String s) throws DOMException
- {
-
-
- throw new NotYetImplemented();
- }
}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/StateAwareResponseImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/StateAwareResponseImpl.java 2008-01-24
21:27:57 UTC (rev 9599)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/StateAwareResponseImpl.java 2008-01-24
21:33:17 UTC (rev 9600)
@@ -400,6 +400,9 @@
UpdateNavigationalStateResponse response = new
UpdateNavigationalStateResponse();
//
+ response.setProperties(getProperties(false));
+
+ //
response.setMode(mode);
response.setWindowState(windowState);
response.setPublicNavigationalStateUpdates(navigationalState.getPublicMapSnapshot());
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/spi/AbstractClientContext.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/spi/AbstractClientContext.java 2008-01-24
21:27:57 UTC (rev 9599)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/spi/AbstractClientContext.java 2008-01-24
21:33:17 UTC (rev 9600)
@@ -43,6 +43,9 @@
{
/** . */
+ private static final List<Cookie> NO_COOKIES = Collections.emptyList();
+
+ /** . */
private final String method;
/** . */
@@ -53,6 +56,11 @@
public AbstractClientContext(HttpServletRequest request)
{
+ this(request, NO_COOKIES);
+ }
+
+ public AbstractClientContext(HttpServletRequest request, List<Cookie>
additionalCookies)
+ {
Map<String, List<String>> headers = new HashMap<String,
List<String>>();
for (Enumeration e = request.getHeaderNames();e.hasMoreElements();)
{
@@ -80,7 +88,9 @@
headers.put(headerName, headerValues);
}
}
- List<Cookie> cookies = null;
+
+ //
+ List<Cookie> cookies;
Cookie[] tmp = request.getCookies();
if (tmp == null || tmp.length == 0)
{
@@ -88,9 +98,20 @@
}
else
{
- cookies = Arrays.asList(tmp);
+ cookies = new ArrayList<Cookie>(tmp.length);
+ for (Cookie cookie : tmp)
+ {
+ Cookie copy = (Cookie)cookie.clone();
+ cookies.add(copy);
+ }
}
+ for (Cookie cookie : additionalCookies)
+ {
+ Cookie copy = (Cookie)cookie.clone();
+ cookies.add(copy);
+ }
+
//
this.headers = headers;
this.method = request.getMethod();
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/FragmentResponse.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/FragmentResponse.java 2008-01-24
21:27:57 UTC (rev 9599)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/FragmentResponse.java 2008-01-24
21:33:17 UTC (rev 9600)
@@ -35,7 +35,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 5602 $
*/
-public class FragmentResponse extends StateResponse
+public class FragmentResponse extends PortletInvocationResponse
{
/** . */
@@ -47,8 +47,8 @@
/** . */
public static final int TYPE_BYTES = 2;
- /** Any content that should appear in the header. */
- private String header;
+ /** . */
+ private ResponseProperties properties;
/** The output as a bytes if any. */
private ClosableOutputStream bytes;
@@ -70,23 +70,23 @@
public FragmentResponse()
{
- this.header = null;
this.bytes = null;
this.chars = null;
this.writer = null;
this.contentType = null;
this.title = null;
this.expirationSecs = 0;
+ this.properties = null;
}
- public String getHeader()
+ public ResponseProperties getProperties()
{
- return header;
+ return properties;
}
- public void setHeader(String header)
+ public void setProperties(ResponseProperties properties)
{
- this.header = header;
+ this.properties = properties;
}
public int getType()
Added:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/ResponseProperties.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/ResponseProperties.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/ResponseProperties.java 2008-01-24
21:33:17 UTC (rev 9600)
@@ -0,0 +1,117 @@
+/******************************************************************************
+ * 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.invocation.response;
+
+import org.jboss.portal.common.util.MultiValuedPropertyMap;
+import org.w3c.dom.Element;
+
+import javax.servlet.http.Cookie;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 5448 $
+ */
+public class ResponseProperties
+{
+
+ /** . */
+ private MultiValuedPropertyMap<String> transportHeaders;
+
+ /** . */
+ private MultiValuedPropertyMap<Element> markupHeaders;
+
+ /** . */
+ private List<Cookie> cookies;
+
+ public ResponseProperties()
+ {
+ }
+
+ public MultiValuedPropertyMap<String> getTransportHeaders()
+ {
+ return getTransportHeaders(true);
+ }
+
+ public MultiValuedPropertyMap<String> getTransportHeaders(boolean create)
+ {
+ if (transportHeaders == null && create)
+ {
+ transportHeaders = new MultiValuedPropertyMap<String>();
+ }
+ return transportHeaders;
+ }
+
+ public MultiValuedPropertyMap<Element> getMarkupHeaders()
+ {
+ return getMarkupHeaders(true);
+ }
+
+ public MultiValuedPropertyMap<Element> getMarkupHeaders(boolean create)
+ {
+ if (markupHeaders == null && create)
+ {
+ markupHeaders = new MultiValuedPropertyMap<Element>();
+ }
+ return markupHeaders;
+ }
+
+ public List<Cookie> getCookies()
+ {
+ return getCookies(true);
+ }
+
+ public List<Cookie> getCookies(boolean create)
+ {
+ if (cookies == null && create)
+ {
+ cookies = new ArrayList<Cookie>();
+ }
+ return cookies;
+ }
+
+ public void append(ResponseProperties appended)
+ {
+ if (appended == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (appended.transportHeaders != null)
+ {
+ getTransportHeaders().append(appended.transportHeaders);
+ }
+ if (appended.markupHeaders != null)
+ {
+ getMarkupHeaders().append(appended.markupHeaders);
+ }
+ if (appended.cookies != null)
+ {
+ getCookies().addAll(appended.cookies);
+ }
+ }
+}
\ No newline at end of file
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/UpdateNavigationalStateResponse.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/UpdateNavigationalStateResponse.java 2008-01-24
21:27:57 UTC (rev 9599)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/UpdateNavigationalStateResponse.java 2008-01-24
21:33:17 UTC (rev 9600)
@@ -38,6 +38,9 @@
public class UpdateNavigationalStateResponse extends StateResponse
{
+ /** . */
+ private ResponseProperties properties;
+
/** The navigational state returned. */
protected StateString navigationalState;
@@ -61,6 +64,16 @@
publicNavigationalStateUpdates = null;
}
+ public ResponseProperties getProperties()
+ {
+ return properties;
+ }
+
+ public void setProperties(ResponseProperties properties)
+ {
+ this.properties = properties;
+ }
+
public Mode getMode()
{
return mode;
Added:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/ext/portletresponses/WriteCookiesTestCase.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/ext/portletresponses/WriteCookiesTestCase.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/ext/portletresponses/WriteCookiesTestCase.java 2008-01-24
21:33:17 UTC (rev 9600)
@@ -0,0 +1,187 @@
+/******************************************************************************
+ * 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.test.portlet.jsr286.ext.portletresponses;
+
+import org.jboss.portal.unit.PortletTestCase;
+import org.jboss.portal.unit.PortletTestContext;
+import org.jboss.portal.unit.annotations.TestCase;
+import org.jboss.portal.unit.actions.PortletRenderTestAction;
+import org.jboss.portal.unit.actions.PortletActionTestAction;
+import org.jboss.portal.unit.actions.PortletEventTestAction;
+import org.jboss.portal.test.portlet.framework.UTP1;
+import org.jboss.unit.driver.DriverResponse;
+import org.jboss.unit.driver.response.EndTestResponse;
+import org.jboss.unit.remote.driver.handler.http.response.InvokeGetResponse;
+import static org.jboss.unit.api.Assert.*;
+
+import javax.portlet.Portlet;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.PortletException;
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.EventRequest;
+import javax.portlet.EventResponse;
+import javax.servlet.http.Cookie;
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+@TestCase
+public class WriteCookiesTestCase
+{
+ public WriteCookiesTestCase(PortletTestCase seq)
+ {
+ seq.bindAction(0, UTP1.RENDER_JOIN_POINT, new PortletRenderTestAction()
+ {
+ protected DriverResponse run(Portlet portlet, RenderRequest request,
RenderResponse response, PortletTestContext context) throws PortletException, IOException
+ {
+ Map<String, String> cookieMap = createCookieMap(request);
+ assertNull(cookieMap.get("render_cookie"));
+
+ //
+ Cookie cookie = new Cookie("render_cookie",
"render_cookie_value");
+ response.addProperty(cookie);
+
+ //
+ return new InvokeGetResponse(response.createActionURL().toString());
+ }
+ });
+ seq.bindAction(1, UTP1.ACTION_JOIN_POINT, new PortletActionTestAction()
+ {
+ protected void run(Portlet portlet, ActionRequest request, ActionResponse
response, PortletTestContext context) throws PortletException, IOException
+ {
+ Map<String, String> cookieMap = createCookieMap(request);
+ assertEquals("render_cookie_value",
cookieMap.get("render_cookie"));
+ assertNull(cookieMap.get("action_cookie"));
+
+ //
+ Cookie cookie = new Cookie("action_cookie",
"action_cookie_value");
+ response.addProperty(cookie);
+
+ //
+ response.setEvent("Event", null);
+ }
+ });
+ seq.bindAction(1, UTP1.EVENT_JOIN_POINT, new PortletEventTestAction()
+ {
+ protected void run(Portlet portlet, EventRequest request, EventResponse
response, PortletTestContext context) throws PortletException, IOException
+ {
+ Map<String, String> cookieMap = createCookieMap(request);
+ assertEquals("render_cookie_value",
cookieMap.get("render_cookie"));
+ assertEquals("action_cookie_value",
cookieMap.get("action_cookie"));
+ }
+ });
+ seq.bindAction(1, UTP1.RENDER_JOIN_POINT, new PortletRenderTestAction()
+ {
+ protected DriverResponse run(Portlet portlet, RenderRequest request,
RenderResponse response, PortletTestContext context) throws PortletException, IOException
+ {
+ Map<String, String> cookieMap = createCookieMap(request);
+ assertEquals("render_cookie_value",
cookieMap.get("render_cookie"));
+ assertEquals("action_cookie_value",
cookieMap.get("action_cookie"));
+
+ //
+ return new InvokeGetResponse(response.createActionURL().toString());
+ }
+ });
+ seq.bindAction(2, UTP1.ACTION_JOIN_POINT, new PortletActionTestAction()
+ {
+ protected void run(Portlet portlet, ActionRequest request, ActionResponse
response, PortletTestContext context) throws PortletException, IOException
+ {
+ Map<String, String> cookieMap = createCookieMap(request);
+ assertEquals("render_cookie_value",
cookieMap.get("render_cookie"));
+ assertEquals("action_cookie_value",
cookieMap.get("action_cookie"));
+
+ //
+ response.setEvent("Event", null);
+ }
+ });
+ seq.bindAction(2, UTP1.EVENT_JOIN_POINT, new PortletEventTestAction()
+ {
+ protected void run(Portlet portlet, EventRequest request, EventResponse
response, PortletTestContext context) throws PortletException, IOException
+ {
+ Map<String, String> cookieMap = createCookieMap(request);
+ assertEquals("render_cookie_value",
cookieMap.get("render_cookie"));
+ assertEquals("action_cookie_value",
cookieMap.get("action_cookie"));
+ assertNull(cookieMap.get("event_cookie"));
+
+ //
+ //
+ Cookie cookie = new Cookie("event_cookie",
"event_cookie_value");
+ response.addProperty(cookie);
+ }
+ });
+ seq.bindAction(2, UTP1.RENDER_JOIN_POINT, new PortletRenderTestAction()
+ {
+ protected DriverResponse run(Portlet portlet, RenderRequest request,
RenderResponse response, PortletTestContext context) throws PortletException, IOException
+ {
+ Map<String, String> cookieMap = createCookieMap(request);
+ assertEquals("render_cookie_value",
cookieMap.get("render_cookie"));
+ assertEquals("action_cookie_value",
cookieMap.get("action_cookie"));
+ assertEquals("event_cookie_value",
cookieMap.get("event_cookie"));
+
+ //
+ return new InvokeGetResponse(response.createActionURL().toString());
+ }
+ });
+ seq.bindAction(3, UTP1.ACTION_JOIN_POINT, new PortletActionTestAction()
+ {
+ protected void run(Portlet portlet, ActionRequest request, ActionResponse
response, PortletTestContext context) throws PortletException, IOException
+ {
+ Map<String, String> cookieMap = createCookieMap(request);
+ assertEquals("render_cookie_value",
cookieMap.get("render_cookie"));
+ assertEquals("action_cookie_value",
cookieMap.get("action_cookie"));
+ assertEquals("event_cookie_value",
cookieMap.get("event_cookie"));
+
+ //
+ response.setEvent("Event", null);
+ }
+ });
+ seq.bindAction(3, UTP1.EVENT_JOIN_POINT, new PortletEventTestAction()
+ {
+ protected void run(Portlet portlet, EventRequest request, EventResponse
response, PortletTestContext context) throws PortletException, IOException
+ {
+ Map<String, String> cookieMap = createCookieMap(request);
+ assertEquals("render_cookie_value",
cookieMap.get("render_cookie"));
+ assertEquals("action_cookie_value",
cookieMap.get("action_cookie"));
+ assertEquals("event_cookie_value",
cookieMap.get("event_cookie"));
+ }
+ });
+ seq.bindAction(3, UTP1.RENDER_JOIN_POINT, new PortletRenderTestAction()
+ {
+ protected DriverResponse run(Portlet portlet, RenderRequest request,
RenderResponse response, PortletTestContext context) throws PortletException, IOException
+ {
+ Map<String, String> cookieMap = createCookieMap(request);
+ assertEquals("render_cookie_value",
cookieMap.get("render_cookie"));
+ assertEquals("action_cookie_value",
cookieMap.get("action_cookie"));
+ assertEquals("event_cookie_value",
cookieMap.get("event_cookie"));
+
+ //
+ return new EndTestResponse();
+ }
+ });
+ }
+}
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortalServlet.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortalServlet.java 2008-01-24
21:27:57 UTC (rev 9599)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortalServlet.java 2008-01-24
21:33:17 UTC (rev 9600)
@@ -67,6 +67,6 @@
PortletController controller = new PortletController();
//
- controller.process(context, context.getRequest());
+ controller.process(context.getRequest());
}
}
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletController.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletController.java 2008-01-24
21:27:57 UTC (rev 9599)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletController.java 2008-01-24
21:33:17 UTC (rev 9600)
@@ -44,6 +44,7 @@
import org.jboss.portal.portlet.invocation.response.ErrorResponse;
import org.jboss.portal.portlet.invocation.response.StateResponse;
import org.jboss.portal.portlet.invocation.response.FragmentResponse;
+import org.jboss.portal.portlet.invocation.response.ResponseProperties;
import org.jboss.portal.portlet.invocation.ActionInvocation;
import org.jboss.portal.portlet.invocation.RenderInvocation;
import org.jboss.portal.portlet.invocation.EventInvocation;
@@ -52,13 +53,17 @@
import org.jboss.portal.common.util.ParameterMap;
import org.jboss.portal.common.util.MarkupInfo;
import org.jboss.portal.common.util.MediaType;
+import org.jboss.portal.common.util.MultiValuedPropertyMap;
import org.jboss.portal.common.io.IOTools;
+import org.jboss.portal.common.xml.XMLTools;
import org.jboss.portal.Mode;
import org.jboss.portal.WindowState;
import org.apache.log4j.Logger;
+import org.w3c.dom.Element;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.Cookie;
import javax.servlet.ServletOutputStream;
import javax.xml.namespace.QName;
import java.io.UnsupportedEncodingException;
@@ -101,8 +106,9 @@
this.portalContext = portalContext;
}
- private PortletInvocationResponse handle(PortletControllerContext context,
ContainerRequest containerRequest) throws PortletInvokerException, IOException
+ private PortletInvocationResponse invoke(ContainerRequest containerRequest) throws
PortletInvokerException, IOException
{
+ PortletControllerContext context = containerRequest.controllerContext;
Portlet portlet = context.getPortlet(containerRequest.portletId);
HttpServletRequest req = context.getClientRequest();
HttpServletResponse resp = context.getClientResponse();
@@ -287,7 +293,8 @@
PortletControllerContext context,
Portlet portlet,
StateResponse.Event event,
- PageNavigationalState pageNS)
+ PageNavigationalState pageNS,
+ List<Cookie> requestCookies)
{
HttpServletRequest req = context.getClientRequest();
HttpServletResponse resp = context.getClientResponse();
@@ -317,7 +324,7 @@
EventInvocation eventInvocation = new EventInvocation(actionContext);
//
- eventInvocation.setClientContext(new AbstractClientContext(req));
+ eventInvocation.setClientContext(new AbstractClientContext(req, requestCookies));
eventInvocation.setServerContext(new AbstractServerContext(req, resp));
eventInvocation.setInstanceContext(instanceContext);
eventInvocation.setUserContext(new AbstractUserContext(req));
@@ -340,21 +347,21 @@
}
}
- public void process(PortletControllerContext context, ControllerRequest
controllerRequest) throws PortletInvokerException, IOException
+ public void process(ControllerRequest controllerRequest) throws
PortletInvokerException, IOException
{
- if (controllerRequest == null)
+ if (controllerRequest instanceof ViewRequest)
{
- render(context, new PageNavigationalState());
+ render(controllerRequest.controllerContext, new ResponseProperties(), new
PageNavigationalState());
}
else if (controllerRequest instanceof ContainerRequest)
{
- process(context, (ContainerRequest)controllerRequest);
+ process((ContainerRequest)controllerRequest);
}
}
- public void process(PortletControllerContext context, ContainerRequest
containerRequest) throws PortletInvokerException, IOException
+ public void process(ContainerRequest containerRequest) throws PortletInvokerException,
IOException
{
- HttpServletRequest req = context.getClientRequest();
+ PortletControllerContext context = containerRequest.controllerContext;
HttpServletResponse resp = context.getClientResponse();
//
@@ -363,9 +370,12 @@
PortletRequest portletRequest = (PortletRequest)containerRequest;
//
- PortletInvocationResponse response = handle(context, containerRequest);
+ PortletInvocationResponse response = invoke(containerRequest);
//
+ ResponseProperties requestProperties = new ResponseProperties();
+
+ //
if (response instanceof ErrorResponse)
{
ErrorResponse error = (ErrorResponse)response;
@@ -387,14 +397,23 @@
{
StateResponse stateResponse = (StateResponse)response;
+
// Update portlet NS
if (response instanceof UpdateNavigationalStateResponse)
{
+ UpdateNavigationalStateResponse updateResponse =
(UpdateNavigationalStateResponse)response;
updateNavigationalState(
context,
containerRequest.portletId,
- (UpdateNavigationalStateResponse)response,
+ updateResponse,
portletRequest.pageState);
+
+ //
+ ResponseProperties update = updateResponse.getProperties();
+ if (update != null)
+ {
+ requestProperties.append(updateResponse.getProperties());
+ }
}
// Create event list and feed it with the events that may have been produced
@@ -425,7 +444,12 @@
//
for (Portlet consumer : consumers)
{
- PortletInvocationResponse eventResponse = deliverEvent(context,
consumer, event, portletRequest.pageState);
+ PortletInvocationResponse eventResponse = deliverEvent(
+ context,
+ consumer,
+ event,
+ portletRequest.pageState,
+ requestProperties.getCookies());
//
if (eventResponse instanceof UpdateNavigationalStateResponse)
@@ -437,6 +461,13 @@
// Add events if any
queue.addAll(update.getEvents());
+
+ //
+ ResponseProperties updateProperties = update.getProperties();
+ if (updateProperties != null)
+ {
+ requestProperties.append(update.getProperties());
+ }
}
else if (eventResponse instanceof ErrorResponse)
{
@@ -498,11 +529,11 @@
*/
//
- render(context, portletRequest.pageState);
+ render(context, requestProperties, portletRequest.pageState);
}
else if (containerRequest instanceof PortletResourceRequest)
{
- PortletInvocationResponse response = handle(context, containerRequest);
+ PortletInvocationResponse response = invoke(containerRequest);
//
if (response instanceof FragmentResponse)
@@ -557,24 +588,33 @@
}
}
- private void render(PortletControllerContext context, PageNavigationalState pageNS)
throws IOException
+ /**
+ *
+ * @param context
+ * @param pageProperties properties that needs to be rendered on this page
+ * @param pageNS
+ * @throws IOException
+ */
+ private void render(
+ PortletControllerContext context,
+ ResponseProperties pageProperties,
+ PageNavigationalState pageNS) throws IOException
{
HttpServletRequest req = context.getClientRequest();
HttpServletResponse resp = context.getClientResponse();
- //
- resp.setContentType("text/html");
- PrintWriter writer = resp.getWriter();
- writer.print("<html><body>");
+ List<FragmentResponse> fragments = new ArrayList<FragmentResponse>();
+ // What we collect during the different renders
+ // we don't reuse the render properties argument since we want to avoid that
+ // a portlet rendition affects another rendition of a portlet on the same page
+ ResponseProperties renderProperties = new ResponseProperties();
+
//
try
{
for (Portlet portlet : context.getPortlets())
{
- writer.print("<div><div>" + portlet.getContext() +
"</div>");
-
- //
WindowNavigationalState windowNS =
pageNS.getWindowNavigationalState(portlet.getContext().getId());
//
@@ -613,7 +653,7 @@
RenderInvocation render = new RenderInvocation(renderContext);
//
- render.setClientContext(new AbstractClientContext(req));
+ render.setClientContext(new AbstractClientContext(req,
pageProperties.getCookies()));
render.setServerContext(new AbstractServerContext(req, resp));
render.setInstanceContext(instanceContext);
render.setUserContext(new AbstractUserContext(req));
@@ -625,23 +665,97 @@
//
try
{
- context.invoke(render);
+ PortletInvocationResponse response = context.invoke(render);
+
+ if (response instanceof FragmentResponse)
+ {
+ FragmentResponse fragment = (FragmentResponse)response;
+
+ //
+ fragments.add(fragment);
+
+ //
+ ResponseProperties fragmentProperties = fragment.getProperties();
+ if (fragmentProperties != null)
+ {
+ renderProperties.append(fragmentProperties);
+ }
+ }
+
}
catch (PortletInvokerException e)
{
e.printStackTrace();
}
-
- writer.print("</div>");
}
}
catch (PortletInvokerException e)
{
+ // todo
e.printStackTrace();
}
+ // Now we combine the render properties with the page properties
+ pageProperties.append(renderProperties);
+
+ // Render the headers
+ MultiValuedPropertyMap<String> transportHeaders =
pageProperties.getTransportHeaders(false);
+ if (transportHeaders != null)
+ {
+ for (String headerName : transportHeaders.getPropertyNames())
+ {
+ for (String headerValue : transportHeaders.getPropertyValues(headerName))
+ {
+ resp.addHeader(headerName, headerValue);
+ }
+ }
+ }
+
+ // Render the cookies
+ List<Cookie> cookies = pageProperties.getCookies(false);
+ if (cookies != null)
+ {
+ for (Cookie cookie : cookies)
+ {
+ resp.addCookie(cookie);
+ }
+ }
+
+ //
+ resp.setContentType("text/html");
+ PrintWriter writer = resp.getWriter();
+ writer.print("<html>");
+
+ // Render the head contributions
+ writer.print("<head>");
+ MultiValuedPropertyMap<Element> markupHeaders =
pageProperties.getMarkupHeaders(false);
+ if (markupHeaders != null)
+ {
+ for (Element headerValue :
markupHeaders.getPropertyValues("javax.portlet.markup.head.element"))
+ {
+ try
+ {
+ String serializedElement = XMLTools.toString(headerValue);
+ writer.print(serializedElement);
+ }
+ catch (Exception e)
+ {
+ // todo
+ e.printStackTrace();
+ }
+ }
+ }
+ writer.print("</head>");
+
+
+ writer.print("<body>");
+ for (FragmentResponse fragment : fragments)
+ {
+ writer.print("<div>");
+ // Do something with fragment
+ writer.print("</div>");
+ }
writer.print("</body></html>");
-
}
private void updateNavigationalState(
@@ -711,15 +825,34 @@
static class ControllerRequest
{
+
+ /** . */
+ final PortletControllerContext controllerContext;
+
+ ControllerRequest(PortletControllerContext controllerContext)
+ {
+ this.controllerContext = controllerContext;
+ }
}
+ static class ViewRequest extends ControllerRequest
+ {
+ ViewRequest(PortletControllerContext controllerContext)
+ {
+ super(controllerContext);
+ }
+ }
+
static class ContainerRequest extends ControllerRequest
{
/** . */
final String portletId;
- ContainerRequest(String portletId)
+ ContainerRequest(PortletControllerContext controllerContext, String portletId)
{
+ super(controllerContext);
+
+ //
this.portletId = portletId;
}
}
@@ -739,9 +872,15 @@
/** . */
final WindowState windowState;
- PortletRequest(String portletId, Mode mode, WindowState windowState, StateString
navigationalState, PageNavigationalState pageState)
+ PortletRequest(
+ PortletControllerContext controllerContext,
+ String portletId,
+ Mode mode,
+ WindowState windowState,
+ StateString navigationalState,
+ PageNavigationalState pageState)
{
- super(portletId);
+ super(controllerContext, portletId);
//
this.mode = mode;
@@ -751,7 +890,6 @@
}
}
-
static abstract class PortletResourceRequest extends ContainerRequest
{
@@ -775,13 +913,14 @@
final ParameterMap bodyParameters;
PortletResourceRequest(
+ PortletControllerContext controllerContext,
String portletId,
String resourceId,
StateString resourceState,
ParameterMap bodyParameters
)
{
- super(portletId);
+ super(controllerContext, portletId);
//
this.resourceId = resourceId;
@@ -797,9 +936,14 @@
static class FullScopedCacheablePortletResourceRequest extends PortletResourceRequest
{
- FullScopedCacheablePortletResourceRequest(String portletId, String resourceId,
StateString resourceState, ParameterMap bodyParameters)
+ FullScopedCacheablePortletResourceRequest(
+ PortletControllerContext controllerContext,
+ String portletId,
+ String resourceId,
+ StateString resourceState,
+ ParameterMap bodyParameters)
{
- super(portletId, resourceId, resourceState, bodyParameters);
+ super(controllerContext, portletId, resourceId, resourceState, bodyParameters);
}
}
@@ -816,6 +960,7 @@
final WindowState windowState;
PortletScopedPortletResourceRequest(
+ PortletControllerContext controllerContext,
String portletId,
String resourceId,
StateString resourceState,
@@ -824,7 +969,7 @@
Mode mode,
WindowState windowState)
{
- super(portletId, resourceId, resourceState, bodyParameters);
+ super(controllerContext, portletId, resourceId, resourceState, bodyParameters);
//
this.mode = mode;
@@ -840,6 +985,7 @@
private final PageNavigationalState pageState;
PageScopedFullPortletResourceRequest(
+ PortletControllerContext controllerContext,
String portletId,
String resourceId,
StateString resourceState,
@@ -849,7 +995,7 @@
Mode mode,
WindowState windowState)
{
- super(portletId, resourceId, resourceState, bodyParameters, navigationalState,
mode, windowState);
+ super(controllerContext, portletId, resourceId, resourceState, bodyParameters,
navigationalState, mode, windowState);
//
this.pageState = pageState;
@@ -866,6 +1012,7 @@
final ParameterMap bodyParameters;
public PortletActionRequest(
+ PortletControllerContext controllerContext,
String portletId,
StateString interactionState,
ParameterMap bodyParameters,
@@ -874,7 +1021,7 @@
WindowState windowState,
PageNavigationalState pageState)
{
- super(portletId, mode, windowState, navigationalState, pageState);
+ super(controllerContext, portletId, mode, windowState, navigationalState,
pageState);
//
this.interactionState = interactionState;
@@ -889,6 +1036,7 @@
final Map<String, String[]> publicNavigationalStateChanges;
public PortletRenderRequest(
+ PortletControllerContext controllerContext,
String portletId,
StateString navigationalState,
Map<String, String[]> publicNavigationalStateChanges,
@@ -896,7 +1044,7 @@
WindowState windowState,
PageNavigationalState pageState)
{
- super(portletId, mode, windowState, navigationalState, pageState);
+ super(controllerContext, portletId, mode, windowState, navigationalState,
pageState);
//
this.publicNavigationalStateChanges = publicNavigationalStateChanges;
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletControllerContextImpl.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletControllerContextImpl.java 2008-01-24
21:27:57 UTC (rev 9599)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletControllerContextImpl.java 2008-01-24
21:33:17 UTC (rev 9600)
@@ -153,6 +153,7 @@
{
case FULL:
request = new
PortletController.FullScopedCacheablePortletResourceRequest(
+ this,
targetId,
resourceId,
resourceState,
@@ -160,6 +161,7 @@
break;
case PORTLET:
request = new PortletController.PortletScopedPortletResourceRequest(
+ this,
targetId,
resourceId,
resourceState,
@@ -170,6 +172,7 @@
break;
case PAGE:
request = new PortletController.PageScopedFullPortletResourceRequest(
+ this,
targetId,
resourceId,
resourceState,
@@ -196,6 +199,7 @@
//
request = new PortletController.PortletActionRequest(
+ this,
targetId,
interactionState,
formParameters,
@@ -210,6 +214,7 @@
//
request = new PortletController.PortletRenderRequest(
+ this,
targetId,
navigationalState,
publicNavigationalStateChanges,
@@ -219,6 +224,10 @@
}
}
}
+ else
+ {
+ request = new PortletController.ViewRequest(this);
+ }
//
this.request = request;
Modified: modules/portlet/trunk/test/src/test/build.xml
===================================================================
--- modules/portlet/trunk/test/src/test/build.xml 2008-01-24 21:27:57 UTC (rev 9599)
+++ modules/portlet/trunk/test/src/test/build.xml 2008-01-24 21:33:17 UTC (rev 9600)
@@ -242,6 +242,7 @@
<package-jsr286-api-test test="event"/>
<package-jsr286-ext-test test="portletrequests"/>
+ <package-jsr286-ext-test test="portletresponses"/>
<jar jarfile="${test.temp.lib}/portlet-test-lib.jar">
<fileset dir="${target}/test-classes"/>
Added:
modules/portlet/trunk/test/src/test/resources/jsr286/ext/portletresponses-war/WEB-INF/portlet.xml
===================================================================
---
modules/portlet/trunk/test/src/test/resources/jsr286/ext/portletresponses-war/WEB-INF/portlet.xml
(rev 0)
+++
modules/portlet/trunk/test/src/test/resources/jsr286/ext/portletresponses-war/WEB-INF/portlet.xml 2008-01-24
21:33:17 UTC (rev 9600)
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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. ~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+
+<portlet-app
xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2...
http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
+ version="2.0">
+
+ <portlet>
+ <portlet-name>UniversalTestPortletA</portlet-name>
+
<portlet-class>org.jboss.portal.test.portlet.framework.UTP1</portlet-class>
+ <supports>
+ <mime-type>text/html</mime-type>
+ </supports>
+ <supported-processing-event>
+ <name>Event</name>
+ </supported-processing-event>
+ <supported-publishing-event>
+ <name>Event</name>
+ </supported-publishing-event>
+ </portlet>
+
+ <event-definition>
+ <name>Event</name>
+ </event-definition>
+
+</portlet-app>
Added:
modules/portlet/trunk/test/src/test/resources/jsr286/ext/portletresponses-war/WEB-INF/web.xml
===================================================================
---
modules/portlet/trunk/test/src/test/resources/jsr286/ext/portletresponses-war/WEB-INF/web.xml
(rev 0)
+++
modules/portlet/trunk/test/src/test/resources/jsr286/ext/portletresponses-war/WEB-INF/web.xml 2008-01-24
21:33:17 UTC (rev 9600)
@@ -0,0 +1,32 @@
+<?xml version="1.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. ~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+
+<!DOCTYPE web-app PUBLIC
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd">
+<web-app>
+ <listener>
+
<listener-class>org.jboss.portal.unit.PortletTestSuite</listener-class>
+ </listener>
+</web-app>
Modified: modules/portlet/trunk/test/src/test/resources/test/remote-jboss-unit.xml
===================================================================
--- modules/portlet/trunk/test/src/test/resources/test/remote-jboss-unit.xml 2008-01-24
21:27:57 UTC (rev 9599)
+++ modules/portlet/trunk/test/src/test/resources/test/remote-jboss-unit.xml 2008-01-24
21:33:17 UTC (rev 9600)
@@ -189,6 +189,10 @@
<class
name="org.jboss.unit.remote.driver.RemoteTestDriverClient"/>
<property name="archiveId"
value="test-jsr286-ext-portletrequests.war"/>
</generic>
+ <generic>
+ <class
name="org.jboss.unit.remote.driver.RemoteTestDriverClient"/>
+ <property name="archiveId"
value="test-jsr286-ext-portletresponses.war"/>
+ </generic>
<!--Misc Tests-->
<!--