Author: chris.laprun(a)jboss.com
Date: 2008-02-04 14:06:09 -0500 (Mon, 04 Feb 2008)
New Revision: 9748
Added:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/ControllerResponse.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/ErrorControllerResponse.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/FragmentRenderer.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PageRenderControllerResponse.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/RedirectControllerResponse.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/RenderControllerResponse.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/ResourceRenderControllerResponse.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/SimpleFragmentRenderer.java
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/PortletURLRenderer.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletController.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletRequestHandler.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletResourceRequestHandler.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/RequestHandler.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/ViewRequestHandler.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/simple/SimplePortalServlet.java
Log:
- Move response/rendering to ControllerResponse hierarchy.
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-02-04
18:24:07 UTC (rev 9747)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortalServlet.java 2008-02-04
19:06:09 UTC (rev 9748)
@@ -22,6 +22,7 @@
******************************************************************************/
package org.jboss.portal.portlet.test;
+import org.jboss.portal.portlet.test.controller.ControllerResponse;
import org.jboss.portal.portlet.test.controller.PortletController;
import org.jboss.portal.portlet.test.controller.PortletControllerContextImpl;
@@ -69,7 +70,7 @@
//
PortletController controller = new PortletController();
- //
- controller.process(context.getRequest());
+ ControllerResponse response = controller.process(context.getRequest());
+ response.render(context);
}
}
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletURLRenderer.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletURLRenderer.java 2008-02-04
18:24:07 UTC (rev 9747)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortletURLRenderer.java 2008-02-04
19:06:09 UTC (rev 9748)
@@ -22,26 +22,26 @@
******************************************************************************/
package org.jboss.portal.portlet.test;
+import org.jboss.portal.common.io.IOTools;
+import org.jboss.portal.common.text.CharBuffer;
+import org.jboss.portal.common.text.FastURLEncoder;
+import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.portlet.ActionURL;
+import org.jboss.portal.portlet.ContainerURL;
import org.jboss.portal.portlet.Portlet;
import org.jboss.portal.portlet.PortletURL;
import org.jboss.portal.portlet.RenderURL;
-import org.jboss.portal.portlet.ActionURL;
-import org.jboss.portal.portlet.StateString;
import org.jboss.portal.portlet.ResourceURL;
-import org.jboss.portal.portlet.ContainerURL;
+import org.jboss.portal.portlet.StateString;
import org.jboss.portal.portlet.cache.CacheLevel;
-import org.jboss.portal.common.text.CharBuffer;
-import org.jboss.portal.common.text.FastURLEncoder;
-import org.jboss.portal.common.util.Tools;
-import org.jboss.portal.common.io.IOTools;
import static org.jboss.portal.portlet.test.URLParameterConstants.*;
import org.jboss.portal.portlet.test.controller.PageNavigationalState;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import java.util.Map;
-import java.util.HashMap;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -119,8 +119,7 @@
try
{
byte[] bytes = PageNavigationalState.serialize(pageNS);
- String ns = Tools.toHexString(bytes);
- pageState = ns;
+ pageState = Tools.toHexString(bytes);
}
catch (IOException e)
{
@@ -235,7 +234,7 @@
//
boolean first = true;
- for (Map.Entry<String,String> entry : parameters.entrySet())
+ for (Map.Entry<String, String> entry : parameters.entrySet())
{
String name = entry.getKey();
String value = entry.getValue();
Added:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/ControllerResponse.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/ControllerResponse.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/ControllerResponse.java 2008-02-04
19:06:09 UTC (rev 9748)
@@ -0,0 +1,41 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.test.controller;
+
+import java.io.IOException;
+
+/**
+ * Must be used as base class for high level response provided by the controller that
will be translated into something
+ * at the portal level. The goal is to avoid to manipulate the HTTP response directly.
+ * <p/>
+ * The test bed will of course use the HTTP response but the Presentation Framework will
work differently.
+ * <p/>
+ * So we really need to abstract everything done with the HttpServletResponse and *never*
use it in the controller.
+ * <p/>
+ * Typical usage should be : ControllerResponse response =
controller.invoker(ControllerRequest request);
+ */
+public interface ControllerResponse
+{
+ void render(PortletControllerContext context) throws IOException;
+}
Property changes on:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/ControllerResponse.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/ErrorControllerResponse.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/ErrorControllerResponse.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/ErrorControllerResponse.java 2008-02-04
19:06:09 UTC (rev 9748)
@@ -0,0 +1,60 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.test.controller;
+
+import org.apache.log4j.Logger;
+import org.jboss.portal.portlet.invocation.response.ErrorResponse;
+
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class ErrorControllerResponse implements ControllerResponse
+{
+ private ErrorResponse error;
+ private static final Logger log = Logger.getLogger(ErrorControllerResponse.class);
+
+ public ErrorControllerResponse(ErrorResponse error)
+ {
+ this.error = error;
+ }
+
+ public void render(PortletControllerContext context) throws IOException
+ {
+ //
+ if (error.getCause() != null)
+ {
+ log.error("Portlet action threw an error: " + error.getMessage(),
error.getCause());
+ }
+ else
+ {
+ log.error("Portlet action threw an error: " + error.getMessage());
+ }
+
+ //
+ context.getClientResponse().sendError(404, error.getMessage());
+ }
+}
Property changes on:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/ErrorControllerResponse.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/FragmentRenderer.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/FragmentRenderer.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/FragmentRenderer.java 2008-02-04
19:06:09 UTC (rev 9748)
@@ -0,0 +1,38 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.test.controller;
+
+import org.jboss.portal.portlet.invocation.response.ErrorResponse;
+import org.jboss.portal.portlet.invocation.response.FragmentResponse;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public interface FragmentRenderer
+{
+ String renderPortlet(FragmentResponse fragment);
+
+ String renderError(ErrorResponse error);
+}
Property changes on:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/FragmentRenderer.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PageRenderControllerResponse.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PageRenderControllerResponse.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PageRenderControllerResponse.java 2008-02-04
19:06:09 UTC (rev 9748)
@@ -0,0 +1,245 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.test.controller;
+
+import org.jboss.portal.Mode;
+import org.jboss.portal.WindowState;
+import org.jboss.portal.common.util.MultiValuedPropertyMap;
+import org.jboss.portal.common.util.ParameterMap;
+import org.jboss.portal.common.xml.XMLTools;
+import org.jboss.portal.portlet.Portlet;
+import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.portlet.StateString;
+import org.jboss.portal.portlet.impl.spi.AbstractClientContext;
+import org.jboss.portal.portlet.impl.spi.AbstractSecurityContext;
+import org.jboss.portal.portlet.impl.spi.AbstractServerContext;
+import org.jboss.portal.portlet.impl.spi.AbstractUserContext;
+import org.jboss.portal.portlet.impl.spi.AbstractWindowContext;
+import org.jboss.portal.portlet.invocation.RenderInvocation;
+import org.jboss.portal.portlet.invocation.response.ErrorResponse;
+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.test.PortletURLRenderer;
+import org.jboss.portal.portlet.test.TestInstanceContext;
+import org.jboss.portal.portlet.test.TestRenderContext;
+import org.jboss.portal.portlet.test.WindowNavigationalState;
+import org.w3c.dom.Element;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class PageRenderControllerResponse extends RenderControllerResponse
+{
+ private FragmentRenderer fragmentRenderer = new SimpleFragmentRenderer();
+ private List<FragmentResponse> fragments;
+ private List<ErrorResponse> errors;
+ private PageNavigationalState pageState;
+
+ public PageRenderControllerResponse(ResponseProperties properties,
PageNavigationalState pageState)
+ {
+ super(properties);
+ this.pageState = pageState;
+ }
+
+ public void setFragmentRenderer(FragmentRenderer fragmentRenderer)
+ {
+ this.fragmentRenderer = fragmentRenderer;
+ }
+
+ protected void renderContent(HttpServletResponse resp) throws IOException
+ {
+ //
+ resp.setContentType("text/html");
+ PrintWriter writer = resp.getWriter();
+ writer.print("<html>");
+
+ // Render the head contributions
+ writer.print("<head>");
+ MultiValuedPropertyMap<Element> markupHeaders =
properties.getMarkupHeaders();
+ List<Element> headElement =
markupHeaders.getValues("javax.portlet.markup.head.element");
+ if (headElement != null)
+ {
+ for (Element headerValue : headElement)
+ {
+ 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(fragmentRenderer.renderPortlet(fragment));
+
+ }
+
+ for (ErrorResponse error : errors)
+ {
+ writer.print(fragmentRenderer.renderError(error));
+ }
+
+ writer.print("</body></html>");
+ }
+
+ protected void prepareRendering(PortletControllerContext context)
+ {
+
+ // 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
+ {
+ Collection<Portlet> portlets = context.getPortlets();
+
+ int capacity = portlets.size();
+ fragments = new ArrayList<FragmentResponse>(capacity);
+ errors = new ArrayList<ErrorResponse>(capacity);
+
+ for (Portlet portlet : portlets)
+ {
+ WindowNavigationalState windowNS =
pageState.getWindowNavigationalState(portlet.getContext().getId());
+
+ //
+ Mode mode = Mode.VIEW;
+ WindowState windowState = WindowState.NORMAL;
+ StateString portletNS = null;
+
+ //
+ if (windowNS != null)
+ {
+ if (windowNS.getMode() != null)
+ {
+ mode = windowNS.getMode();
+ }
+ if (windowNS.getWindowState() != null)
+ {
+ windowState = windowNS.getWindowState();
+ }
+ if (windowNS.getPortletNavigationalState() != null)
+ {
+ portletNS = windowNS.getPortletNavigationalState();
+ }
+ }
+
+ //
+ ParameterMap publicNS = pageState.getPublicNavigationalState(portlet);
+
+ RenderInvocation render = createRenderInvocation(context, properties,
pageState, portlet, windowNS, mode, windowState, portletNS, publicNS);
+
+ //
+ try
+ {
+ 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);
+ }
+ }
+ else if (response instanceof ErrorResponse)
+ {
+ ErrorResponse error = (ErrorResponse)response;
+ errors.add(error);
+ }
+
+ }
+ catch (PortletInvokerException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+ catch (PortletInvokerException e)
+ {
+ // todo
+ e.printStackTrace();
+ }
+
+ // Now we combine the render properties with the page properties
+ properties.append(renderProperties);
+ }
+
+ protected RenderInvocation createRenderInvocation(
+ PortletControllerContext context, ResponseProperties pageProperties,
PageNavigationalState pageNS, Portlet portlet,
+ WindowNavigationalState windowNS, Mode mode, WindowState windowState, StateString
portletNS, ParameterMap publicNS)
+ {
+ HttpServletRequest req = context.getClientRequest();
+ HttpServletResponse resp = context.getClientResponse();
+
+ //
+ PortletURLRenderer renderer = new PortletURLRenderer(pageNS, windowNS, portlet,
req, resp);
+ //
+ TestInstanceContext instanceContext = new TestInstanceContext(req,
portlet.getContext(), false);
+
+ TestRenderContext renderContext = new TestRenderContext(renderer,
PortletController.MARKUP_INFO);
+
+ //
+ RenderInvocation render = new RenderInvocation(renderContext);
+ render.setClientContext(new AbstractClientContext(req,
pageProperties.getCookies()));
+ render.setServerContext(new AbstractServerContext(req, resp));
+ render.setInstanceContext(instanceContext);
+ render.setUserContext(new AbstractUserContext(req));
+ render.setWindowContext(new AbstractWindowContext(portlet.getContext().getId()));
+ render.setPortalContext(PortletController.getPortalContext());
+ render.setSecurityContext(new AbstractSecurityContext(req));
+ render.setTarget(instanceContext.getTarget());
+ render.setMode(mode);
+ render.setWindowState(windowState);
+ render.setNavigationalState(portletNS);
+ render.setPublicNavigationalState(publicNS);
+ return render;
+ }
+}
Property changes on:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PageRenderControllerResponse.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletController.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletController.java 2008-02-04
18:24:07 UTC (rev 9747)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletController.java 2008-02-04
19:06:09 UTC (rev 9748)
@@ -22,48 +22,18 @@
******************************************************************************/
package org.jboss.portal.portlet.test.controller;
-import org.jboss.portal.Mode;
-import org.jboss.portal.WindowState;
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.util.ParameterMap;
-import org.jboss.portal.common.xml.XMLTools;
-import org.jboss.portal.portlet.Portlet;
import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.StateString;
import org.jboss.portal.portlet.cache.CacheLevel;
-import org.jboss.portal.portlet.impl.spi.AbstractClientContext;
import org.jboss.portal.portlet.impl.spi.AbstractPortalContext;
-import org.jboss.portal.portlet.impl.spi.AbstractSecurityContext;
-import org.jboss.portal.portlet.impl.spi.AbstractServerContext;
-import org.jboss.portal.portlet.impl.spi.AbstractUserContext;
-import org.jboss.portal.portlet.impl.spi.AbstractWindowContext;
-import org.jboss.portal.portlet.invocation.RenderInvocation;
-import org.jboss.portal.portlet.invocation.response.ErrorResponse;
-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.spi.PortalContext;
-import org.jboss.portal.portlet.test.controller.PageNavigationalState;
-import org.jboss.portal.portlet.test.PortletURLRenderer;
-import org.jboss.portal.portlet.test.TestInstanceContext;
-import org.jboss.portal.portlet.test.TestRenderContext;
import org.jboss.portal.portlet.test.WindowNavigationalState;
-import org.jboss.portal.web.IllegalRequestException;
-import org.w3c.dom.Element;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
/**
@@ -77,20 +47,17 @@
static final MarkupInfo MARKUP_INFO = new MarkupInfo(MediaType.HTML,
"UTF8");
/** . */
- // private final boolean redirectAfterAction = true;
+ static final PortalContext portalContext;
- /** . */
- private final PortalContext portalContext;
-
- public PortletController() throws IllegalRequestException,
UnsupportedEncodingException
+ static
{
Map<String, String> portalProperties = new HashMap<String, String>();
portalProperties.put("javax.portlet.markup.head.element.support",
"true");
- this.portalContext = new AbstractPortalContext(portalProperties);
+ portalContext = new AbstractPortalContext(portalProperties);
}
- public void process(ControllerRequest controllerRequest) throws IOException,
PortletInvokerException
+ public ControllerResponse process(ControllerRequest controllerRequest) throws
IOException, PortletInvokerException
{
RequestHandler handler;
@@ -111,231 +78,14 @@
throw new PortletInvokerException("Unknown request type: " +
controllerRequest.getClass().getName());
}
- handler.handle(controllerRequest);
+ return handler.handle(controllerRequest);
}
- /**
- * @param context
- * @param pageProperties properties that needs to be rendered on this page
- * @param pageNS
- * @throws IOException
- */
- void render(PortletControllerContext context, ResponseProperties pageProperties,
PageNavigationalState pageNS) throws IOException
+ static PortalContext getPortalContext()
{
- HttpServletRequest req = context.getClientRequest();
- HttpServletResponse resp = context.getClientResponse();
-
- List<FragmentResponse> fragments = Collections.emptyList();
- List<ErrorResponse> errors = Collections.emptyList();
-
- // 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
- {
- Collection<Portlet> portlets = context.getPortlets();
-
- int capacity = portlets.size();
- fragments = new ArrayList<FragmentResponse>(capacity);
- errors = new ArrayList<ErrorResponse>(capacity);
-
- for (Portlet portlet : portlets)
- {
- WindowNavigationalState windowNS =
pageNS.getWindowNavigationalState(portlet.getContext().getId());
-
- //
- PortletURLRenderer renderer = new PortletURLRenderer(pageNS, windowNS,
portlet, req, resp);
-
- //
- Mode mode = Mode.VIEW;
- WindowState windowState = WindowState.NORMAL;
- StateString portletNS = null;
-
- //
- if (windowNS != null)
- {
- if (windowNS.getMode() != null)
- {
- mode = windowNS.getMode();
- }
- if (windowNS.getWindowState() != null)
- {
- windowState = windowNS.getWindowState();
- }
- if (windowNS.getPortletNavigationalState() != null)
- {
- portletNS = windowNS.getPortletNavigationalState();
- }
- }
-
- //
- ParameterMap publicNS = pageNS.getPublicNavigationalState(portlet);
-
- //
- TestInstanceContext instanceContext = new TestInstanceContext(req,
portlet.getContext(), false);
- TestRenderContext renderContext = new TestRenderContext(renderer,
MARKUP_INFO);
-
- //
- RenderInvocation render = new RenderInvocation(renderContext);
-
- //
- render.setMode(mode);
- render.setWindowState(windowState);
- render.setNavigationalState(portletNS);
- render.setPublicNavigationalState(publicNS);
-
- //
- render.setClientContext(new AbstractClientContext(req,
pageProperties.getCookies()));
- render.setServerContext(new AbstractServerContext(req, resp));
- render.setInstanceContext(instanceContext);
- render.setUserContext(new AbstractUserContext(req));
- render.setWindowContext(new
AbstractWindowContext(portlet.getContext().getId()));
- render.setPortalContext(getPortalContext());
- render.setSecurityContext(new AbstractSecurityContext(req));
- render.setTarget(instanceContext.getTarget());
-
- //
- try
- {
- 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);
- }
- }
- else if (response instanceof ErrorResponse)
- {
- ErrorResponse error = (ErrorResponse)response;
- errors.add(error);
- }
-
- }
- catch (PortletInvokerException e)
- {
- e.printStackTrace();
- }
- }
- }
- catch (PortletInvokerException e)
- {
- // todo
- e.printStackTrace();
- }
-
- // Now we combine the render properties with the page properties
- pageProperties.append(renderProperties);
-
- // Render the headers and cookies
- renderTransportHeaders(pageProperties, resp);
- renderCookies(pageProperties, resp);
-
- //
- resp.setContentType("text/html");
- PrintWriter writer = resp.getWriter();
- writer.print("<html>");
-
- // Render the head contributions
- writer.print("<head>");
- MultiValuedPropertyMap<Element> markupHeaders =
pageProperties.getMarkupHeaders();
- List<Element> headElement =
markupHeaders.getValues("javax.portlet.markup.head.element");
- if (headElement != null)
- {
- for (Element headerValue : headElement)
- {
- 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)
- {
- if (fragment.getType() != FragmentResponse.TYPE_EMPTY)
- {
- writer.print("<div class=\"portlet\">");
- writer.print(fragment.getBuffer().getContent());
- writer.print("</div>");
- }
- else
- {
- writer.print("<div/>");
- }
- }
-
- for (ErrorResponse error : errors)
- {
- writer.print("<div class='error'>");
- writer.print(error.toHTML());
- writer.print("</div>");
- }
-
- writer.print("</body></html>");
- }
-
- void renderCookies(ResponseProperties pageProperties, HttpServletResponse resp)
- {
- List<Cookie> cookies = pageProperties.getCookies();
- for (Cookie cookie : cookies)
- {
- resp.addCookie(cookie);
- }
- }
-
- void renderTransportHeaders(ResponseProperties pageProperties, HttpServletResponse
resp)
- {
- MultiValuedPropertyMap<String> transportHeaders =
pageProperties.getTransportHeaders();
- for (String headerName : transportHeaders.keySet())
- {
- for (String headerValue : transportHeaders.getValues(headerName))
- {
- resp.addHeader(headerName, headerValue);
- }
- }
- }
-
- PortalContext getPortalContext()
- {
return portalContext;
}
- /**
- * Must be used as base class for high level response provided by the controller that
will be translated into
- * something at the portal level. The goal is to avoid to manipulate the HTTP response
directly.
- * <p/>
- * The test bed will of course use the HTTP response but the Presentation Framework
will work differently.
- * <p/>
- * So we really need to abstract everything done with the HttpServletResponse and
*never* use it in the controller.
- * <p/>
- * Typical usage should be : ControllerResponse response =
controller.invoker(ControllerRequest request);
- */
- static class ControllerResponse
- {
-
- }
-
static class ControllerRequest
{
/** . */
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletRequestHandler.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletRequestHandler.java 2008-02-04
18:24:07 UTC (rev 9747)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletRequestHandler.java 2008-02-04
19:06:09 UTC (rev 9748)
@@ -65,7 +65,7 @@
return (PortletRequest)request;
}
- void processResponse(PortletRequest portletRequest, PortletInvocationResponse
response) throws IOException, PortletInvokerException
+ ControllerResponse processResponse(PortletRequest portletRequest,
PortletInvocationResponse response) throws IOException, PortletInvokerException
{
PortletControllerContext context = portletRequest.controllerContext;
@@ -83,35 +83,19 @@
//
if (response instanceof ErrorResponse)
{
- ErrorResponse error = (ErrorResponse)response;
-
- //
- if (error.getCause() != null)
- {
- log.error("Portlet action threw an error: " + error.getMessage(),
error.getCause());
- }
- else
- {
- log.error("Portlet action threw an error: " + error.getMessage());
- }
-
- //
- context.getClientResponse().sendError(404, error.getMessage());
+ return new ErrorControllerResponse((ErrorResponse)response);
}
else if (response instanceof UpdateNavigationalStateResponse)
{
// Update portlet NS
- if (response instanceof UpdateNavigationalStateResponse)
- {
- UpdateNavigationalStateResponse updateResponse =
(UpdateNavigationalStateResponse)response;
- updateNavigationalState(context, portletRequest.portletId, updateResponse,
pageState);
+ UpdateNavigationalStateResponse updateResponse =
(UpdateNavigationalStateResponse)response;
+ updateNavigationalState(context, portletRequest.portletId, updateResponse,
pageState);
- //
- ResponseProperties update = updateResponse.getProperties();
- if (update != null)
- {
- requestProperties.append(update);
- }
+ //
+ ResponseProperties update = updateResponse.getProperties();
+ if (update != null)
+ {
+ requestProperties.append(update);
}
//
@@ -138,13 +122,13 @@
//
if (eventResponse instanceof UpdateNavigationalStateResponse)
{
- UpdateNavigationalStateResponse update =
(UpdateNavigationalStateResponse)eventResponse;
+ UpdateNavigationalStateResponse eventStateResponse =
(UpdateNavigationalStateResponse)eventResponse;
// Update ns
- updateNavigationalState(context, event.getPortletContext().getId(),
update, pageState);
+ updateNavigationalState(context, event.getPortletContext().getId(),
eventStateResponse, pageState);
// Add events if any
- for (UpdateNavigationalStateResponse.Event portletEvent :
update.getEvents())
+ for (UpdateNavigationalStateResponse.Event portletEvent :
eventStateResponse.getEvents())
{
Event producedEvent = new Event(portletEvent.getName(),
portletEvent.getPayload(), portletContext);
List<Event> consumedEvents =
eventCC.getConsumedEvents(producedEvent);
@@ -152,7 +136,7 @@
}
//
- ResponseProperties updateProperties = update.getProperties();
+ ResponseProperties updateProperties = eventStateResponse.getProperties();
if (updateProperties != null)
{
requestProperties.append(updateProperties);
@@ -170,41 +154,14 @@
}
else if (response instanceof HTTPRedirectionResponse)
{
- HTTPRedirectionResponse redirection = (HTTPRedirectionResponse)response;
- context.getClientResponse().sendRedirect(redirection.getLocation());
- return;
+ return new RedirectControllerResponse((HTTPRedirectionResponse)response);
}
else
{
System.out.println("Not yet handled " + response);
}
- /*
- if (response instanceof RenderResponse && redirectAfterAction)
- {
- PortletURLRenderer renderer = new PortletURLRenderer(navState, portlet,
req, resp);
- final RenderResponse render = (RenderResponse)response;
- String location = renderer.renderURL(new RenderURL()
- {
- public StateString getNavigationalState()
- {
- return render.getNavigationalState();
- }
- public Mode getMode()
- {
- return render.getMode();
- }
- public WindowState getWindowState()
- {
- return render.getWindowState();
- }
- }, null, null, true);
- response = new HTTPRedirectionResponse(location);
- }
- */
-
- //
- controller.render(context, requestProperties, pageState);
+ return new PageRenderControllerResponse(requestProperties, pageState);
}
PortletInvocationResponse invoke(PortletRequest portletRequest) throws
PortletInvokerException
@@ -275,7 +232,7 @@
actionInvocation.setInstanceContext(instanceContext);
actionInvocation.setUserContext(new AbstractUserContext(req));
actionInvocation.setWindowContext(new
AbstractWindowContext(portlet.getContext().getId()));
- actionInvocation.setPortalContext(controller.getPortalContext());
+ actionInvocation.setPortalContext(getPortalContext());
actionInvocation.setSecurityContext(new AbstractSecurityContext(req));
actionInvocation.setRequestContext(new AbstractRequestContext(req));
actionInvocation.setTarget(instanceContext.getTarget());
@@ -330,7 +287,7 @@
eventInvocation.setInstanceContext(instanceContext);
eventInvocation.setUserContext(new AbstractUserContext(req));
eventInvocation.setWindowContext(new
AbstractWindowContext(portlet.getContext().getId()));
- eventInvocation.setPortalContext(controller.getPortalContext());
+ eventInvocation.setPortalContext(getPortalContext());
eventInvocation.setSecurityContext(new AbstractSecurityContext(req));
eventInvocation.setTarget(instanceContext.getTarget());
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletResourceRequestHandler.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletResourceRequestHandler.java 2008-02-04
18:24:07 UTC (rev 9747)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletResourceRequestHandler.java 2008-02-04
19:06:09 UTC (rev 9748)
@@ -25,7 +25,6 @@
import org.jboss.portal.Mode;
import org.jboss.portal.WindowState;
-import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.common.util.ParameterMap;
import org.jboss.portal.portlet.Portlet;
import org.jboss.portal.portlet.PortletInvokerException;
@@ -38,22 +37,19 @@
import org.jboss.portal.portlet.impl.spi.AbstractUserContext;
import org.jboss.portal.portlet.impl.spi.AbstractWindowContext;
import org.jboss.portal.portlet.invocation.ResourceInvocation;
+import org.jboss.portal.portlet.invocation.response.ErrorResponse;
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.spi.ResourceInvocationContext;
-import org.jboss.portal.portlet.test.controller.PageNavigationalState;
import org.jboss.portal.portlet.test.PortletURLRenderer;
import org.jboss.portal.portlet.test.ResourceTestContext;
import org.jboss.portal.portlet.test.TestInstanceContext;
import org.jboss.portal.portlet.test.WindowNavigationalState;
import static org.jboss.portal.portlet.test.controller.PortletController.*;
-import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
-import java.io.Writer;
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
@@ -66,69 +62,21 @@
super(controller);
}
- void processResponse(PortletResourceRequest request, PortletInvocationResponse
response) throws IOException, PortletInvokerException
+ ControllerResponse processResponse(PortletResourceRequest request,
PortletInvocationResponse response) throws IOException, PortletInvokerException
{
- HttpServletResponse resp = request.controllerContext.getClientResponse();
-
//
if (response instanceof FragmentResponse)
{
FragmentResponse fragment = (FragmentResponse)response;
- ResponseProperties props = fragment.getProperties();
- //
- if (props != null)
- {
- controller.renderTransportHeaders(props, resp);
- controller.renderCookies(props, resp);
- }
-
- //
- if (fragment.getType() == FragmentResponse.TYPE_EMPTY)
- {
- resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
- }
- else
- {
- String contentType = fragment.getContentType();
- if (contentType != null)
- {
- resp.setContentType(contentType);
- }
-
- //
- if (fragment.getType() == FragmentResponse.TYPE_BYTES)
- {
- ServletOutputStream out = null;
- try
- {
- out = resp.getOutputStream();
- out.write(fragment.getBytes().toByteArray());
- }
- finally
- {
- IOTools.safeClose(out);
- }
- }
- else
- {
- Writer writer = null;
- try
- {
- writer = resp.getWriter();
- writer.write(fragment.getChars().toString());
- }
- finally
- {
- writer.close();
- }
- }
- }
+ return new ResourceRenderControllerResponse(fragment.getProperties(),
fragment);
}
else
{
// todo
}
+
+ return new ErrorControllerResponse(new ErrorResponse("Couldn't handle
resource request"));
}
PortletInvocationResponse invoke(PortletResourceRequest portletResourceRequest) throws
PortletInvokerException
@@ -198,7 +146,7 @@
TestInstanceContext instanceContext = new TestInstanceContext(req,
portlet.getContext(), true);
ResourceInvocationContext resourceInvocationContext = new
ResourceTestContext(renderer, MARKUP_INFO);
ResourceInvocation resourceInvocation = new
ResourceInvocation(resourceInvocationContext);
-
+
//
resourceInvocation.setResourceId(portletResourceRequest.resourceId);
resourceInvocation.setCacheLevel(cacheability);
@@ -215,7 +163,7 @@
resourceInvocation.setInstanceContext(instanceContext);
resourceInvocation.setUserContext(new AbstractUserContext(req));
resourceInvocation.setWindowContext(new
AbstractWindowContext(portlet.getContext().getId()));
- resourceInvocation.setPortalContext(controller.getPortalContext());
+ resourceInvocation.setPortalContext(getPortalContext());
resourceInvocation.setSecurityContext(new AbstractSecurityContext(req));
resourceInvocation.setRequestContext(new AbstractRequestContext(req));
resourceInvocation.setTarget(instanceContext.getTarget());
Added:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/RedirectControllerResponse.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/RedirectControllerResponse.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/RedirectControllerResponse.java 2008-02-04
19:06:09 UTC (rev 9748)
@@ -0,0 +1,47 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.test.controller;
+
+import org.jboss.portal.portlet.invocation.response.HTTPRedirectionResponse;
+
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class RedirectControllerResponse implements ControllerResponse
+{
+ private HTTPRedirectionResponse redirection;
+
+ public RedirectControllerResponse(HTTPRedirectionResponse redirection)
+ {
+ this.redirection = redirection;
+ }
+
+ public void render(PortletControllerContext context) throws IOException
+ {
+ context.getClientResponse().sendRedirect(redirection.getLocation());
+ }
+}
Property changes on:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/RedirectControllerResponse.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/RenderControllerResponse.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/RenderControllerResponse.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/RenderControllerResponse.java 2008-02-04
19:06:09 UTC (rev 9748)
@@ -0,0 +1,91 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.test.controller;
+
+import org.jboss.portal.common.util.MultiValuedPropertyMap;
+import org.jboss.portal.portlet.invocation.response.ResponseProperties;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public abstract class RenderControllerResponse implements ControllerResponse
+{
+ protected ResponseProperties properties = new ResponseProperties();
+
+ protected RenderControllerResponse(ResponseProperties properties)
+ {
+ this.properties = properties;
+ }
+
+ public void render(PortletControllerContext context) throws IOException
+ {
+ prepareRendering(context);
+ HttpServletResponse resp = context.getClientResponse();
+
+ // Render the headers and cookies
+ if (properties != null)
+ {
+ renderTransportHeaders(properties, resp);
+ renderCookies(properties, resp);
+ }
+
+ renderContent(resp);
+ }
+
+ protected abstract void renderContent(HttpServletResponse resp)
+ throws IOException;
+
+ private void renderCookies(ResponseProperties pageProperties, HttpServletResponse
resp)
+ {
+ List<Cookie> cookies = pageProperties.getCookies();
+ for (Cookie cookie : cookies)
+ {
+ resp.addCookie(cookie);
+ }
+ }
+
+ private void renderTransportHeaders(ResponseProperties pageProperties,
HttpServletResponse resp)
+ {
+ MultiValuedPropertyMap<String> transportHeaders =
pageProperties.getTransportHeaders();
+ for (String headerName : transportHeaders.keySet())
+ {
+ for (String headerValue : transportHeaders.getValues(headerName))
+ {
+ resp.addHeader(headerName, headerValue);
+ }
+ }
+ }
+
+ protected void prepareRendering(PortletControllerContext context)
+ {
+ // default behavior does nothing
+ return;
+ }
+}
Property changes on:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/RenderControllerResponse.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/RequestHandler.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/RequestHandler.java 2008-02-04
18:24:07 UTC (rev 9747)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/RequestHandler.java 2008-02-04
19:06:09 UTC (rev 9748)
@@ -26,15 +26,15 @@
this.controller = controller;
}
- public void handle(ControllerRequest request) throws PortletInvokerException,
IOException
+ public ControllerResponse handle(ControllerRequest request) throws
PortletInvokerException, IOException
{
T req = downcastRequest(request);
PortletInvocationResponse response = invoke(req);
- processResponse(req, response);
+ return processResponse(req, response);
}
- abstract void processResponse(T request, PortletInvocationResponse response) throws
IOException, PortletInvokerException;
+ abstract ControllerResponse processResponse(T request, PortletInvocationResponse
response) throws IOException, PortletInvokerException;
abstract PortletInvocationResponse invoke(T controllerRequest) throws
PortletInvokerException;
Added:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/ResourceRenderControllerResponse.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/ResourceRenderControllerResponse.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/ResourceRenderControllerResponse.java 2008-02-04
19:06:09 UTC (rev 9748)
@@ -0,0 +1,93 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.test.controller;
+
+import org.jboss.portal.common.io.IOTools;
+import org.jboss.portal.portlet.invocation.response.FragmentResponse;
+import org.jboss.portal.portlet.invocation.response.ResponseProperties;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.Writer;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class ResourceRenderControllerResponse extends RenderControllerResponse
+{
+ private FragmentResponse fragment;
+
+ public ResourceRenderControllerResponse(ResponseProperties properties,
FragmentResponse fragment)
+ {
+ super(properties);
+ this.fragment = fragment;
+ }
+
+ protected void renderContent(HttpServletResponse resp) throws IOException
+ {
+ //
+ if (fragment.getType() == FragmentResponse.TYPE_EMPTY)
+ {
+ resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
+ }
+ else
+ {
+ String contentType = fragment.getContentType();
+ if (contentType != null)
+ {
+ resp.setContentType(contentType);
+ }
+
+ //
+ if (fragment.getType() == FragmentResponse.TYPE_BYTES)
+ {
+ ServletOutputStream out = null;
+ try
+ {
+ out = resp.getOutputStream();
+ out.write(fragment.getBytes().toByteArray());
+ }
+ finally
+ {
+ IOTools.safeClose(out);
+ }
+ }
+ else
+ {
+ Writer writer = null;
+ try
+ {
+ writer = resp.getWriter();
+ writer.write(fragment.getChars().toString());
+ }
+ finally
+ {
+ writer.close();
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
Property changes on:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/ResourceRenderControllerResponse.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/SimpleFragmentRenderer.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/SimpleFragmentRenderer.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/SimpleFragmentRenderer.java 2008-02-04
19:06:09 UTC (rev 9748)
@@ -0,0 +1,69 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.test.controller;
+
+import org.jboss.portal.portlet.invocation.response.ErrorResponse;
+import org.jboss.portal.portlet.invocation.response.FragmentResponse;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class SimpleFragmentRenderer implements FragmentRenderer
+{
+ public String renderPortlet(FragmentResponse fragment)
+ {
+
+ if (fragment.getType() != FragmentResponse.TYPE_EMPTY)
+ {
+ String frag;
+
+ //
+ if (fragment.getType() == FragmentResponse.TYPE_BYTES)
+ {
+ frag = fragment.getBytes().toString();
+ }
+ else
+ {
+ frag = fragment.getChars().toString();
+ }
+
+ StringBuilder builder = new StringBuilder(frag.length() + 50);
+ builder.append("<div
class=\"portlet\">").append(frag).append("</div>");
+ return builder.toString();
+ }
+ else
+ {
+ return "<div/>";
+ }
+ }
+
+ public String renderError(ErrorResponse error)
+ {
+ String html = error.toHTML();
+ StringBuilder builder = new StringBuilder(html + 50);
+ builder.append("<div
class='error'>").append(html).append("</div>");
+ return builder.toString();
+ }
+}
Property changes on:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/SimpleFragmentRenderer.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/ViewRequestHandler.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/ViewRequestHandler.java 2008-02-04
18:24:07 UTC (rev 9747)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/ViewRequestHandler.java 2008-02-04
19:06:09 UTC (rev 9748)
@@ -26,7 +26,6 @@
import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
import org.jboss.portal.portlet.invocation.response.ResponseProperties;
-import org.jboss.portal.portlet.test.controller.PageNavigationalState;
import static
org.jboss.portal.portlet.test.controller.PortletController.ControllerRequest;
import static org.jboss.portal.portlet.test.controller.PortletController.ViewRequest;
@@ -43,9 +42,9 @@
super(controller);
}
- void processResponse(ViewRequest request, PortletInvocationResponse response) throws
IOException, PortletInvokerException
+ ControllerResponse processResponse(ViewRequest request, PortletInvocationResponse
response) throws IOException, PortletInvokerException
{
- controller.render(request.controllerContext, new ResponseProperties(), new
PageNavigationalState());
+ return new PageRenderControllerResponse(new ResponseProperties(), new
PageNavigationalState());
}
PortletInvocationResponse invoke(ViewRequest controllerRequest) throws
PortletInvokerException
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/simple/SimplePortalServlet.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/simple/SimplePortalServlet.java 2008-02-04
18:24:07 UTC (rev 9747)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/simple/SimplePortalServlet.java 2008-02-04
19:06:09 UTC (rev 9748)
@@ -22,6 +22,7 @@
******************************************************************************/
package org.jboss.portal.simple;
+import org.jboss.portal.portlet.test.controller.ControllerResponse;
import org.jboss.portal.portlet.test.controller.PortletController;
import org.jboss.portal.portlet.test.controller.PortletControllerContextImpl;
@@ -70,6 +71,7 @@
PortletController controller = new PortletController();
//
- controller.process(context.getRequest());
+ ControllerResponse response = controller.process(context.getRequest());
+ response.render(context);
}
}
\ No newline at end of file