Author: julien(a)jboss.com
Date: 2008-02-22 06:34:17 -0500 (Fri, 22 Feb 2008)
New Revision: 10082
Added:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/portal/samples/basic/NullFilter.java
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/PortletFilterImpl.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/portal/admin/ui/AdminPortlet.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/portal/samples/basic/FailDuringInitPortlet.java
modules/portlet/trunk/test/src/test/resources/portal/samples/basic-war/WEB-INF/portlet.xml
Log:
- fix a bug with wrong filter name
- add filters in basic sample to test the filter -> container dependencies
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/PortletFilterImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/PortletFilterImpl.java 2008-02-22
10:31:17 UTC (rev 10081)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/PortletFilterImpl.java 2008-02-22
11:34:17 UTC (rev 10082)
@@ -101,7 +101,7 @@
public String getId()
{
- return null;
+ return info.getName();
}
public void setPortletApplication(PortletApplication application)
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/portal/admin/ui/AdminPortlet.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/portal/admin/ui/AdminPortlet.java 2008-02-22
10:31:17 UTC (rev 10081)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/portal/admin/ui/AdminPortlet.java 2008-02-22
11:34:17 UTC (rev 10082)
@@ -25,6 +25,8 @@
import org.jboss.portal.portlet.container.managed.PortletApplicationRegistry;
import org.jboss.portal.portlet.container.managed.ManagedPortletApplication;
import org.jboss.portal.portlet.container.managed.ManagedPortletContainer;
+import org.jboss.portal.portlet.container.managed.ManagedPortletFilter;
+import org.jboss.portal.portlet.container.managed.ManagedObject;
import javax.portlet.GenericPortlet;
import javax.portlet.RenderRequest;
@@ -59,26 +61,30 @@
//
ManagedPortletApplication application =
registry.getManagedPortletApplication(applicationId);
+ ManagedObject managedObject = application;
//
String containerId = req.getParameter("container");
+ if (containerId != null)
+ {
+ managedObject = application.getManagedPortletContainer(containerId);
+ }
+ else
+ {
+ String filterId = req.getParameter("filter");
+ if (filterId != null)
+ {
+ managedObject = application.getManagedPortletFilter(filterId);
+ }
+ }
//
- if (containerId != null)
+ final ManagedObject tmp = managedObject;
+ if (tmp != null)
{
- final ManagedPortletContainer container =
application.getManagedPortletContainer(containerId);
-
- //
if ("start".equals(lifeCycle))
{
- try
- {
- container.managedStart();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
+ tmp.managedStart();
}
else if ("stop".equals(lifeCycle))
{
@@ -87,7 +93,7 @@
{
public void run()
{
- container.managedStop();
+ tmp.managedStop();
}
}.start();
}
@@ -97,40 +103,69 @@
protected void doView(RenderRequest req, RenderResponse resp) throws PortletException,
IOException
{
-
resp.setContentType("text/html");
-
PrintWriter writer = resp.getWriter();
// Use an alias
PortletApplicationRegistry registry =
(PortletApplicationRegistry)getPortletContext().getAttribute("PortletApplicationDeployer");
+ //
for (ManagedPortletApplication application :
registry.getManagedPortletApplications())
{
PortletURL url = resp.createActionURL();
url.setParameter("application", application.getId());
//
- writer.print("<ul><li>Application " + application.getId()
+ " " + application.getStatus() + "</li><ul>");
+ url.setParameter("lifecycle", "stop");
+ String stopURL = url.toString();
//
+ url.setParameter("lifecycle", "start");
+ String startURL = url.toString();
+
+ //
+ writer.print("<ul><li>Application " + application.getId()
+ " " + application.getStatus() +
+ " <a href=\"" + startURL +
"\">Start</a> <a href=\"" + stopURL +
"\">Stop</a></li><ul>");
+
+ //
+ for (ManagedPortletFilter filter : application.getManagedPortletFilters())
+ {
+ url.setParameter("filter", filter.getId());
+
+ //
+ url.setParameter("lifecycle", "stop");
+ stopURL = url.toString();
+
+ //
+ url.setParameter("lifecycle", "start");
+ startURL = url.toString();
+
+ //
+ writer.print("<li>Filter " + filter.getId() + " " +
filter.getStatus() + " <a href=\"" +
+ startURL + "\">Start</a> <a href=\"" +
stopURL + "\">Stop</a></li>");
+ }
+
+ //
for (ManagedPortletContainer container :
application.getManagedPortletContainers())
{
-
url.setParameter("container", container.getId());
+ //
url.setParameter("lifecycle", "stop");
- String stopURL = url.toString();
+ stopURL = url.toString();
+ //
url.setParameter("lifecycle", "start");
- String startURL = url.toString();
+ startURL = url.toString();
- writer.print("<li>Container " + container.getId() + "
" + container.getStatus() + "<a href=\"" +
- startURL + "\">Start</a> <a href=\"" +
stopURL + "\">Stop</a>" + "</li>");
+ //
+ writer.print("<li>Container " + container.getId() + "
" + container.getStatus() + " <a href=\"" +
+ startURL + "\">Start</a> <a href=\"" +
stopURL + "\">Stop</a></li>");
}
writer.print("</ul></ul>");
}
+ //
writer.close();
}
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/portal/samples/basic/FailDuringInitPortlet.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/portal/samples/basic/FailDuringInitPortlet.java 2008-02-22
10:31:17 UTC (rev 10081)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/portal/samples/basic/FailDuringInitPortlet.java 2008-02-22
11:34:17 UTC (rev 10082)
@@ -24,6 +24,10 @@
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
/**
* A portlet that will fail only one time during startup (so it is possible to restart
it).
@@ -50,4 +54,12 @@
// Nothing
}
}
+
+ protected void doView(RenderRequest renderRequest, RenderResponse renderResponse)
throws PortletException, IOException
+ {
+ renderResponse.setContentType("text/html");
+ PrintWriter writer = renderResponse.getWriter();
+ writer.print("A portlet that may fail during init");
+ writer.close();
+ }
}
Added:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/portal/samples/basic/NullFilter.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/portal/samples/basic/NullFilter.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/portal/samples/basic/NullFilter.java 2008-02-22
11:34:17 UTC (rev 10082)
@@ -0,0 +1,75 @@
+/******************************************************************************
+ * 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.filter.RenderFilter;
+import javax.portlet.filter.ActionFilter;
+import javax.portlet.filter.EventFilter;
+import javax.portlet.filter.ResourceFilter;
+import javax.portlet.filter.FilterChain;
+import javax.portlet.filter.FilterConfig;
+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.portlet.ResourceRequest;
+import javax.portlet.ResourceResponse;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class NullFilter implements RenderFilter, ActionFilter, EventFilter,
ResourceFilter
+{
+ public void init(FilterConfig config) throws PortletException
+ {
+ }
+
+ public void doFilter(RenderRequest req, RenderResponse resp, FilterChain chain) throws
IOException, PortletException
+ {
+ chain.doFilter(req, resp);
+ }
+
+ public void doFilter(ActionRequest req, ActionResponse resp, FilterChain chain) throws
IOException, PortletException
+ {
+ chain.doFilter(req, resp);
+ }
+
+ public void doFilter(EventRequest req, EventResponse resp, FilterChain chain) throws
IOException, PortletException
+ {
+ chain.doFilter(req, resp);
+ }
+
+ public void doFilter(ResourceRequest req, ResourceResponse resp, FilterChain chain)
throws IOException, PortletException
+ {
+ chain.doFilter(req, resp);
+ }
+
+ public void destroy()
+ {
+ }
+}
Modified:
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 2008-02-22
10:31:17 UTC (rev 10081)
+++
modules/portlet/trunk/test/src/test/resources/portal/samples/basic-war/WEB-INF/portlet.xml 2008-02-22
11:34:17 UTC (rev 10082)
@@ -66,4 +66,32 @@
</portlet-info>
</portlet>
+ <filter>
+ <filter-name>FilterA</filter-name>
+
<filter-class>org.jboss.portal.portlet.portal.samples.basic.NullFilter</filter-class>
+ <lifecycle>ACTION_PHASE</lifecycle>
+ <lifecycle>EVENT_PHASE</lifecycle>
+ <lifecycle>RENDER_PHASE</lifecycle>
+ <lifecycle>RESOURCE_PHASE</lifecycle>
+ </filter>
+
+ <filter>
+ <filter-name>FilterB</filter-name>
+
<filter-class>org.jboss.portal.portlet.portal.samples.basic.NullFilter</filter-class>
+ <lifecycle>ACTION_PHASE</lifecycle>
+ <lifecycle>EVENT_PHASE</lifecycle>
+ <lifecycle>RENDER_PHASE</lifecycle>
+ <lifecycle>RESOURCE_PHASE</lifecycle>
+ </filter>
+
+ <filter-mapping>
+ <filter-name>FilterA</filter-name>
+ <portlet-name>*</portlet-name>
+ </filter-mapping>
+
+ <filter-mapping>
+ <filter-name>FilterB</filter-name>
+ <portlet-name>HeaderPortlet</portlet-name>
+ </filter-mapping>
+
</portlet-app>