Author: julien(a)jboss.com
Date: 2008-02-08 16:53:06 -0500 (Fri, 08 Feb 2008)
New Revision: 9874
Added:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/portal/
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/portal/samples/
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/portal/samples/basic/
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/portal/samples/basic/ErrorPortlet.java
modules/portlet/trunk/test/src/test/resources/portal/
modules/portlet/trunk/test/src/test/resources/portal/samples/
modules/portlet/trunk/test/src/test/resources/portal/samples/basic-war/
modules/portlet/trunk/test/src/test/resources/portal/samples/basic-war/WEB-INF/
modules/portlet/trunk/test/src/test/resources/portal/samples/basic-war/WEB-INF/portlet.xml
modules/portlet/trunk/test/src/test/resources/portal/samples/basic-war/WEB-INF/web.xml
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/Constants.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/PortletTag.java
modules/portlet/trunk/test/src/test/build.xml
modules/portlet/trunk/test/src/test/resources/simple-portal-war/WEB-INF/jsp/error.jsp
modules/portlet/trunk/test/src/test/resources/simple-portal-war/layouts/default.jsp
Log:
handle error return code in the jsp error
Added:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/portal/samples/basic/ErrorPortlet.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/portal/samples/basic/ErrorPortlet.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/portal/samples/basic/ErrorPortlet.java 2008-02-08
21:53:06 UTC (rev 9874)
@@ -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.portal.samples.basic;
+
+import javax.portlet.GenericPortlet;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.PortletException;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class ErrorPortlet extends GenericPortlet
+{
+ protected void doView(RenderRequest renderRequest, RenderResponse renderResponse)
throws PortletException, IOException
+ {
+ throw new PortletException("Some exception");
+ }
+}
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/Constants.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/Constants.java 2008-02-08
20:30:51 UTC (rev 9873)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/Constants.java 2008-02-08
21:53:06 UTC (rev 9874)
@@ -37,9 +37,12 @@
public static final String ERROR_STATUS =
"org.jboss.portal.portlet.portal.error.status";
/** . */
- public static final String ERROR_EXCEPTION =
"org.jboss.portal.portlet.portal.error.exception";
+ public static final String ERROR_CAUSE =
"org.jboss.portal.portlet.portal.error.cause";
/** . */
+ public static final String ERROR_MESSAGE =
"org.jboss.portal.portlet.portal.error.message";
+
+ /** . */
public static final String ERROR_PORTLET_NAME =
"org.jboss.portal.portlet.portal.error.portlet_name";
/** . */
@@ -50,4 +53,13 @@
/** . */
public static final String NOT_FOUND = "not_found";
+
+ /** . */
+ public static final String PORTLET_ERROR = "portlet_error";
+
+ /** . */
+ public static final String INTERNAL_ERROR = "internal_error";
+
+ /** . */
+ public static final String UNAVAILABLE = "unavailable";
}
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/PortletTag.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/PortletTag.java 2008-02-08
20:30:51 UTC (rev 9873)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/PortletTag.java 2008-02-08
21:53:06 UTC (rev 9874)
@@ -22,12 +22,14 @@
******************************************************************************/
package org.jboss.portal.portlet.test.jsp.taglib;
-import org.jboss.portal.portlet.test.jsp.taglib.PortletResult;
import org.jboss.portal.portlet.test.jsp.PortalResponse;
import org.jboss.portal.portlet.test.jsp.PagePortletControllerContext;
import org.jboss.portal.portlet.test.controller.TestInstanceContext;
import org.jboss.portal.portlet.test.controller.TestPortalContext;
import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.portlet.invocation.response.FragmentResponse;
+import org.jboss.portal.portlet.invocation.response.ErrorResponse;
+import org.jboss.portal.portlet.invocation.response.UnavailableResponse;
import org.jboss.portal.portlet.invocation.RenderInvocation;
import org.jboss.portal.portlet.controller.state.PageNavigationalState;
import org.jboss.portal.portlet.controller.state.WindowNavigationalState;
@@ -49,7 +51,6 @@
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
-import javax.servlet.http.HttpServletRequest;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.Collections;
@@ -95,17 +96,12 @@
/** . */
private String errorPageAttr;
- /** . */
private int status;
-
- /** . */
private Set<WindowState> supportedWindowStates;
-
- /** . */
private Set<Mode> supportedModes;
-
- /** . */
private Mode initialMode;
+ private PageTag pageTag;
+ private PortalResponse response;
/** . */
PortletResult result;
@@ -213,18 +209,16 @@
this.initialMode = initialMode;
this.supportedModes = supportedModes;
this.supportedWindowStates = supportedWindowStates;
+ this.pageTag = (PageTag)findAncestorWithClass(this, PageTag.class);
+ this.response = getPortalResponse();
}
-// private void handleError
-
public int internalDoStartTag() throws JspException
{
updateInternalState();
//
- PortalResponse response = getPortalResponse();
PagePortletControllerContext context = response.getPortletControllerContext();
- PageTag pageTag = (PageTag)findAncestorWithClass(this, PageTag.class);
//
Portlet portlet = context.findPortlet(applicationNameAttr, nameAttr);
@@ -232,44 +226,8 @@
//
if (portlet == null)
{
- if (errorPageAttr != null)
- {
- RequestDispatcher rd =
pageContext.getServletContext().getRequestDispatcher(errorPageAttr);
- if (rd != null)
- {
- ServletRequest request= pageContext.getRequest();
+ handleError(null, Constants.NOT_FOUND, null, null);
- //
- try
- {
- pageTag.status = PageTag.Status.SUSPENDED;
- request.setAttribute(Constants.ERROR_STATUS, Constants.NOT_FOUND);
- request.setAttribute(Constants.ERROR_APPLICATION_NAME,
applicationNameAttr);
- request.setAttribute(Constants.ERROR_PORTLET_NAME, nameAttr);
-
- //
- rd.include(pageContext.getRequest(), new JspWriterResponse(response,
pageContext.getOut()));
- }
- catch (ServletException e)
- {
- // Shall we do smth else ?
- e.printStackTrace();
- }
- catch (IOException e)
- {
- // Shall we do smth else ?
- e.printStackTrace();
- }
- finally
- {
- pageTag.status = PageTag.Status.ACTIVE;
- request.removeAttribute(Constants.ERROR_STATUS);
- request.removeAttribute(Constants.ERROR_APPLICATION_NAME);
- request.removeAttribute(Constants.ERROR_PORTLET_NAME);
- }
- }
- }
-
// We cannot show an absent portlet, no meta data
return SKIP_BODY;
}
@@ -282,39 +240,37 @@
{
if (windowId.equals(pageTag.maximizedId))
{
- result = render(response, portlet, windowId);
status = BUFFERED;
+
+ //
+ return render(portlet, windowId, EVAL_BODY_BUFFERED);
}
else
{
status = SKIPPED;
+ return SKIP_BODY;
}
}
else
{
- result = render(response, portlet, windowId);
status = RENDERED;
- }
- //
- switch (status)
- {
- case SKIPPED:
- return SKIP_BODY;
- case RENDERED:
- return EVAL_BODY_INCLUDE;
- case BUFFERED:
- return EVAL_BODY_BUFFERED;
- default:
- throw new AssertionError();
+ //
+ return render(portlet, windowId, EVAL_BODY_INCLUDE);
}
}
}
public int internalDoEndTag() throws JspException
{
+ if (bodyContent != null)
+ {
+ pageTag.content = bodyContent.getString();
+ }
+
result = null;
+/*
//
switch (status)
{
@@ -324,20 +280,17 @@
break;
case BUFFERED:
PageTag pageTag = (PageTag)findAncestorWithClass(this, PageTag.class);
- pageTag.content = bodyContent.getString();
break;
default:
throw new AssertionError();
}
+*/
//
return EVAL_PAGE;
}
- public PortletResult render(
- PortalResponse response,
- Portlet portlet,
- String windowId)
+ public int render(Portlet portlet, String windowId, int rt)
{
PagePortletControllerContext context = response.getPortletControllerContext();
@@ -397,28 +350,104 @@
render.setPublicNavigationalState(publicNS);
//
- PortletInvocationResponse portletResponse = null;
try
{
- portletResponse = context.invoke(render);
+ PortletInvocationResponse portletResponse = context.invoke(render);
+ //
+ if (portletResponse instanceof FragmentResponse)
+ {
+ result = new PortletResult(
+ nameAttr,
+ applicationNameAttr,
+ windowId,
+ portletResponse,
+ initialMode,
+ supportedModes,
+ supportedWindowStates);
+ //
+ return rt;
+ }
+ else if (portletResponse instanceof ErrorResponse)
+ {
+ ErrorResponse error = (ErrorResponse)portletResponse;
+
+ //
+ handleError(windowId, Constants.PORTLET_ERROR, error.getCause(),
error.getMessage());
+
+ //
+ return SKIP_BODY;
+ }
+ else if (portletResponse instanceof UnavailableResponse)
+ {
+ handleError(windowId, Constants.UNAVAILABLE, null, null);
+
+ //
+ return SKIP_BODY;
+ }
+ else
+ {
+ handleError(windowId, Constants.INTERNAL_ERROR, null, null);
+
+ //
+ return SKIP_BODY;
+ }
}
catch (PortletInvokerException e)
{
- e.printStackTrace();
+ handleError(windowId, Constants.INTERNAL_ERROR, e, e.getMessage());
- // todo
+ //
+ return SKIP_BODY;
}
+ }
- //
- return new PortletResult(
- nameAttr,
- applicationNameAttr,
- windowId,
- portletResponse,
- initialMode,
- supportedModes,
- supportedWindowStates);
+ private void handleError(String windowId, String errorStatus, Throwable cause, String
message)
+ {
+ if (errorPageAttr != null)
+ {
+ RequestDispatcher rd =
pageContext.getServletContext().getRequestDispatcher(errorPageAttr);
+ if (rd != null)
+ {
+ ServletRequest request= pageContext.getRequest();
+
+ //
+ try
+ {
+ pageTag.status = PageTag.Status.SUSPENDED;
+ request.setAttribute(Constants.ERROR_STATUS, errorStatus);
+ request.setAttribute(Constants.ERROR_CAUSE, cause);
+ request.setAttribute(Constants.ERROR_MESSAGE, message);
+ request.setAttribute(Constants.ERROR_WINDOW_ID, windowId);
+ request.setAttribute(Constants.ERROR_APPLICATION_NAME,
applicationNameAttr);
+ request.setAttribute(Constants.ERROR_PORTLET_NAME, nameAttr);
+
+ //
+ rd.include(pageContext.getRequest(), new JspWriterResponse(response,
pageContext.getOut()));
+ }
+ catch (ServletException e)
+ {
+ // Shall we do smth else ?
+ e.printStackTrace();
+ }
+ catch (IOException e)
+ {
+ // Shall we do smth else ?
+ e.printStackTrace();
+ }
+ finally
+ {
+ pageTag.status = PageTag.Status.ACTIVE;
+ request.removeAttribute(Constants.ERROR_STATUS);
+ request.removeAttribute(Constants.ERROR_CAUSE);
+ request.removeAttribute(Constants.ERROR_MESSAGE);
+ request.removeAttribute(Constants.ERROR_WINDOW_ID);
+ request.removeAttribute(Constants.ERROR_APPLICATION_NAME);
+ request.removeAttribute(Constants.ERROR_PORTLET_NAME);
+ }
+ }
+ }
}
+
}
Modified: modules/portlet/trunk/test/src/test/build.xml
===================================================================
--- modules/portlet/trunk/test/src/test/build.xml 2008-02-08 20:30:51 UTC (rev 9873)
+++ modules/portlet/trunk/test/src/test/build.xml 2008-02-08 21:53:06 UTC (rev 9874)
@@ -762,12 +762,23 @@
<copy todir="${test.temp.dir}/remotecontrol-portlet-war">
<fileset dir="src/test/resources/remotecontrol-portlet-war"/>
- <fileset dir="${target}/classes"
-
includes="org/jboss/portal/simple/samples/RemoteControlResourcePortlet.class"/>
+ <fileset dir="${target}/classes"
includes="org/jboss/portal/simple/samples/RemoteControlResourcePortlet.class"/>
</copy>
<jar jarfile="${target}/remotecontrol-portlet.war">
<fileset dir="${test.temp.dir}/remotecontrol-portlet-war"/>
</jar>
+
+ <mkdir dir="${test.temp.dir}/portal"/>
+ <mkdir dir="${test.temp.dir}/portal/samples"/>
+ <copy todir="${test.temp.dir}/portal/samples-basic-war">
+ <fileset dir="src/test/resources/portal/samples/basic-war"/>
+ <fileset dir="${target}/classes"
includes="org/jboss/portal/portlet/portal/samples/basic/**"/>
+ </copy>
+ <mkdir dir="${target}/portal"/>
+ <jar jarfile="${target}/portal/samples-basic.war">
+ <fileset dir="${test.temp.dir}/portal/samples-basic-war"/>
+ </jar>
+
</target>
</project>
\ No newline at end of file
Added:
modules/portlet/trunk/test/src/test/resources/portal/samples/basic-war/WEB-INF/portlet.xml
===================================================================
---
modules/portlet/trunk/test/src/test/resources/portal/samples/basic-war/WEB-INF/portlet.xml
(rev 0)
+++
modules/portlet/trunk/test/src/test/resources/portal/samples/basic-war/WEB-INF/portlet.xml 2008-02-08
21:53:06 UTC (rev 9874)
@@ -0,0 +1,41 @@
+<?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_1_0.xsd"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1...
http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
+ version="1.0">
+
+ <portlet>
+ <portlet-name>ErrorPortlet</portlet-name>
+
<portlet-class>org.jboss.portal.portlet.portal.samples.basic.ErrorPortlet</portlet-class>
+ <supports>
+ <mime-type>text/html</mime-type>
+ </supports>
+ <portlet-info>
+ <title></title>
+ </portlet-info>
+ </portlet>
+
+</portlet-app>
Added:
modules/portlet/trunk/test/src/test/resources/portal/samples/basic-war/WEB-INF/web.xml
===================================================================
---
modules/portlet/trunk/test/src/test/resources/portal/samples/basic-war/WEB-INF/web.xml
(rev 0)
+++
modules/portlet/trunk/test/src/test/resources/portal/samples/basic-war/WEB-INF/web.xml 2008-02-08
21:53:06 UTC (rev 9874)
@@ -0,0 +1,29 @@
+<?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. ~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+
+<web-app version="2.4"
+
xmlns="http://java.sun.com/xml/ns/j2ee"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+</web-app>
Modified:
modules/portlet/trunk/test/src/test/resources/simple-portal-war/WEB-INF/jsp/error.jsp
===================================================================
---
modules/portlet/trunk/test/src/test/resources/simple-portal-war/WEB-INF/jsp/error.jsp 2008-02-08
20:30:51 UTC (rev 9873)
+++
modules/portlet/trunk/test/src/test/resources/simple-portal-war/WEB-INF/jsp/error.jsp 2008-02-08
21:53:06 UTC (rev 9874)
@@ -1,7 +1,19 @@
<%@ page language="java" %>
-Portlet was not rendered<br/>
+
+<div class="portlet">
+ <div class="portlet-frame">
+ <div class="header full-width">
+ <div class="header-layer full-width">
+ <div class="title two-third-width
float-left"><h2>Error</h2></div>
+ <div class="controls third-width float-right">
+ </div>
+ </div>
+ </div>
<%=
request.getAttribute("org.jboss.portal.portlet.portal.error.status")%><br/>
<%=
request.getAttribute("org.jboss.portal.portlet.portal.error.portlet_name")%><br/>
<%=
request.getAttribute("org.jboss.portal.portlet.portal.error.application_name")%><br/>
-<%=
request.getAttribute("org.jboss.portal.portlet.portal.error.exception")%><br/>
+<%=
request.getAttribute("org.jboss.portal.portlet.portal.error.cause")%><br/>
+<%=
request.getAttribute("org.jboss.portal.portlet.portal.error.message")%><br/>
<%=
request.getAttribute("org.jboss.portal.portlet.portal.error.window_id")%><br/>
+</div>
+</div>
Modified:
modules/portlet/trunk/test/src/test/resources/simple-portal-war/layouts/default.jsp
===================================================================
---
modules/portlet/trunk/test/src/test/resources/simple-portal-war/layouts/default.jsp 2008-02-08
20:30:51 UTC (rev 9873)
+++
modules/portlet/trunk/test/src/test/resources/simple-portal-war/layouts/default.jsp 2008-02-08
21:53:06 UTC (rev 9874)
@@ -30,6 +30,7 @@
<jsp:attribute name="leftcol">
<jbp:portlet name="RemoteControl"
applicationName="remotecontrol-portlet" />
<jbp:portlet name="Foo" applicationName="bar" />
+ <jbp:portlet name="ErrorPortlet"
applicationName="samples-basic" />
</jsp:attribute>
<jsp:attribute name="rightcol">
<jbp:portlet name="GoogleMap"
applicationName="google-map-portlet" />