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?)

isRequestedSessionIdFromCookie

false

isRequestedSessionIdFromURL

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 R'*_ssPortlet found at Portlet Open Source Trading Site. You'll need:

  • jars (found in webapps/WEB-INF/lib of your Cocoon build):
    • The pluto jar (pluto-1.0.1-rc1.jar in release 2.1.6).
    • portlet-api-1.0.jar.

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 R_'ssPortlet.war into an exploded web application directory in the servlet container (i.e. webapps/R'_ssPortlet in Tomcat).

  • web.xml - Replace the web.xml with the following for 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:

  • copletdata/portal.xml:
    After the C_*'ocoonPortlet definition add:
   <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>
  • copletinstancedata/portal.xml:
    After the C'*_ocoonPortlet definition add:
   <coplet-instance-data id="RssPortlet" name="standard">
     <coplet-data>RssPortlet</coplet-data>
   </coplet-instance-data>
  • layout/portal.xml:
    After the C_*'ocoonPortlet item definition add:
   <item>
     <coplet-layout name="coplet" layout-renderer-name="portlet-window">
       <coplet-instance-data>RssPortlet</coplet-instance-data>
     </coplet-layout>
   </item>
  • No labels