Basics

JSR168 defines API for writing portable (across portal implementations) portlets in Java, and is similar (and related) to the Servlets spec.

To implement JSR168 Portlet using Cocoon, JSR168 Environment is introduced.


If you are looking for a way to run a cocoon web app as a JSR168 portlet in a JSR168 portlet container see CocoonAppAsJSR168Portlet.

-- BastianBowe 03.02.05

Environment

JSR168 environment for Cocoon maps Portlet primitives onto Cocoon primitives. Most of the time mapping is obvious:

org.apache.cocoon.environment.portlet

javax.portlet

PortletRequest

PortletRequest

PortletResponse

PortletResponse

ActionRequest

ActionRequest

...

...

PortletCookie

PortletPreferences

But there are times when it is not so obvious. Let's look at PortletRequest:

org.apache.cocoon.environment.portlet.PortletRequest

javax.portlet.PortletRequest

headers

properties

cookies (only name and value are populated)

preferences

header X-Portlet-Mode

portletMode

header X-Window-State

windowState

pathInfo

parameter cocoon-portlet-path

servletPath

no analogy; populated by CocoonPortlet

contentLength

-1

contentType

null

protocol

JSR168

remoteAddr

null

remoteHost

null

method

GET for RenderRequest, POST for ActionRequest

pathTranslated

null

queryString

""

requestURI

contextPath (what should be here?)

is!RequestedSessionIdFromCookie

false

is!RequestedSessionIdFromURL

true

The rest of Request interface methods are mapped 1:1 to corresponding PortletRequest methods (no surprises).

Deployment

This example documents how to install the RssPortlet found at Portlet Open Source Trading Site. You'll need:

Move these two jars into a library shared across web applications in your servlet container. In Tomcat this should be $CATALINA_BASE/shared/lib however as of release 5.0.28 this did not work and the jars need to be placed in $CATALINA_HOME/common/lib.

On Tomcat, Cocoon must be configured to allow access to other web applications. This is enabled by creating a configuration file with crossContext="true" specified. For Tomcat release 5.0, this is documented at Server Configuration Reference. An example configuration file might look like:

<Context path="/cocoon" docBase="${catalina.home}/webapps/cocoon"
        debug="0" crossContext="true">
</Context>

Unjar RssPortlet.war into an exploded web application directory in the servlet container (i.e. webapps/RssPortlet in Tomcat).

<?xml version="1.0" encoding="UTF-8"?>

<!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>
  <!-- Servlet Configuration ========================================== -->
  <servlet>
    <servlet-name>RssPortlet</servlet-name>
    <display-name>Pluto wrapper for RssPortlet</display-name>
    <servlet-class>org.apache.pluto.core.PortletServlet</servlet-class>
    <init-param>
      <param-name>portlet-guid</param-name>
      <param-value>RssPortlet.RssPortlet</param-value>
    </init-param>
    <init-param>
      <param-name>portlet-class</param-name>
      <param-value>com.plumtree.portlet.portlets.RssPortlet</param-value>
    </init-param>
  </servlet>

  <!-- URL space mappings ============================================= -->
  <servlet-mapping>
    <servlet-name>RssPortlet</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
</web-app>

To integrate the portlet into the Cocoon sample site:

   <coplet-data id="RssPortlet" name="standard">
      <title>RssPortlet</title>
      <coplet-base-data>Portlet</coplet-base-data>
      <attribute>
         <name>portlet</name>
         <value xsi:type="java:java.lang.String" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">RssPortlet.RssPortlet</value>
      </attribute>
      <attribute>
         <name>buffer</name>
         <value xsi:type="java:java.lang.Boolean" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">true</value>
      </attribute>
   </coplet-data>

   <coplet-instance-data id="RssPortlet" name="standard">
     <coplet-data>RssPortlet</coplet-data>
   </coplet-instance-data>

   <item>
     <coplet-layout name="coplet" layout-renderer-name="portlet-window">
       <coplet-instance-data>RssPortlet</coplet-instance-data>
     </coplet-layout>
   </item>

JSR168Portlet (last edited 2009-09-20 23:40:42 by localhost)