Portals Bridges

Portals Bridges

The eXo Portlet Container was tested using apache Portals Bridges.

EXO-PC was tested using four Portals Bridges: jsf, perl, php, struts. The Portals Bridges official site is http://portals.apache.org/bridges/.

1 Building a util-bridge jar file

You may build it using eXo Platform sources at projects/portlet-container/trunk/applications/util-bridge

The resulted library will have the name "exo.pc.util-bridge-trunk.jar".

2 JSF - sbridgejsfportlet

Sources located at: projects/portlet-container/trunk/applications/bridges/jsf

An addition to web.xml

<!-- Listener, that does all the startup work (configuration, init). -->
    <listener>
      <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
    </listener>
    <!-- the Faces Servlet -->
    <servlet>
      <servlet-name>Faces Servlet</servlet-name>
      <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
      <load-on-startup>1</load-on-startup>
    </servlet>
    <!-- extension mapping -->
    <servlet-mapping>
      <servlet-name>Faces Servlet</servlet-name>
      <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>

A sample portlet.xml

<portlet>
      <description>sbridgejsfportlet</description>
      <portlet-name>sbridgejsfportlet</portlet-name>
      <display-name>sbridgejsfportlet</display-name>
      <portlet-class>org.apache.portals.bridges.jsf.FacesPortlet</portlet-class>
      <init-param>
        <name>ViewPage</name>
        <value>/view.jsp</value>
      </init-param>
      <init-param>
        <name>HelpPage</name>
        <value>/help.html</value>
      </init-param>
      <expiration-cache>-1</expiration-cache>
      <supports>
        <mime-type>text/html</mime-type>
        <portlet-mode>VIEW</portlet-mode>
        <portlet-mode>HELP</portlet-mode>
      </supports>
        <supported-locale>en</supported-locale>
      <portlet-info>
        <title>sbridgejsfportlet</title>
        <short-title>sbridgejsfportlet</short-title>
        <keywords>sbridgejsfportlet</keywords>
      </portlet-info>
    </portlet>

A sample faces-config.xml

<faces-config xmlns="http://java.sun.com/JSF/Configuration">
    <!-- Install Replacement Factory Objects -->
    <factory>
      <faces-context-factory>org.apache.portals.bridges.jsf.FacesContextFactoryImpl</faces-context-factory>
    </factory>
    <!-- Install Replacement Application Objects -->
    <application>
      <view-handler>org.apache.portals.bridges.jsf.PortletViewHandlerImpl</view-handler>
    </application>
  </faces-config>

Additional files for this test application: view.jsp, help.html /WEB-INF/tld/ myfaces_core.tld, myfaces_ext.tld, myfaces_html.tld

Necessary libs:

  • portals-bridges-common-1.0.jar
  • portals-bridges-jsf-1.0.jar
  • myfaces-api-1.1.4.jar
  • myfaces-impl-1.1.4.jar
  • tomahawk-1.1.4.jar

3 PERL - sbridgeperlportlet

Sources located at: projects/portlet-container/trunk/applications/bridges/perl

A sample portlet.xml

<portlet>
      <description>sbridgeperlportlet</description>
      <portlet-name>sbridgeperlportlet</portlet-name>
      <display-name>sbridgeperlportlet</display-name>
      <portlet-class>org.apache.portals.bridges.perl.PerlPortlet</portlet-class>
      <init-param>
        <name>PerlScript</name>
        <value>perl.cgi</value>
      </init-param>
      <init-param>
        <name>ScriptPath</name>
        <value>cgi-bin</value>
      </init-param>
      <expiration-cache>-1</expiration-cache>
      <supports>
        <mime-type>text/html</mime-type>
        <portlet-mode>VIEW</portlet-mode>
      </supports>
        <supported-locale>en</supported-locale>
      <portlet-info>
        <title>sbridgeperlportlet</title>
        <short-title>sbridgeperlportlet</short-title>
        <keywords>sbridgeperlportlet</keywords>
      </portlet-info>
    </portlet>

Additional files for this test application: WEB-INF/cgi-bin/perl.cgi

Necessary libs:

  • jetspeed-rewriter-2.0.jar
  • portals-bridges-common-1.0.jar
  • portals-bridges-perl-1.0.jar
You can get these libs by surfing to the download page of http://portals.apache.org/bridges/. Download the full distribution and copy the concerned libs.

4 PHP - sbridgephpportlet

Sources located at: projects/portlet-container/trunk/applications/bridges/php

web.xml Nothing changes.

A sample portlet.xml

<portlet id="php-demo">
      <description>The PHP portlet runs PHP applications inside a portlet, with minimal re-coding required.</description>
      <portlet-name>php-demo</portlet-name>
      <display-name>PHP Portlet</display-name>
      <portlet-class>org.apache.portals.bridges.php.PHPApplicationPortlet</portlet-class>
    <init-param>
        <name>ServletContextProvider</name>
        <value>org.apache.portals.bridges.php.PHPServletContextProviderImpl</value>
      </init-param>
      <init-param>
        <name>StartPage</name>
        <value>index.php</value>
      </init-param>
      <expiration-cache>-1</expiration-cache>
      <supports>
        <mime-type>text/html</mime-type>
        <portlet-mode>VIEW</portlet-mode>
      </supports>
      <portlet-info>
          <title>PHP demo Portlet</title>
          <short-title>PHP Portlet</short-title>
          <keywords>PHP,demo,bridge</keywords>
      </portlet-info>
  </portlet>

Additional files for this test application: index.html, index.php

Necessary libs:

  • phpportlet-1.0.jar
  • portals-bridges-common-1.0.jar
  • portals-bridges-php-1.0.jar

5 STRUTS - sbridgestrutsportlet

Apache has a Struts bridge that will let your existing struts application run with little to no modification of your application. Make sure you read and understand this : http://portals.apache.org/bridges/multiproject/portals-bridges-struts/features.html

We have small demo project that demonstrates how to use it. Sources located at: projects/portlet-container/trunk/applications/bridges/struts

5.1 web.xml

First you need to replace your action servlet by the one provided by the bridge.

<servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.portals.bridges.struts.PortletServlet</servlet-class>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
      <param-name>debug</param-name>
      <param-value>2</param-value>
    </init-param>
    <init-param>
      <param-name>detail</param-name>
      <param-value>2</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>

5.2 portlet.xml

Then configure a generic struts portlet.

<portlet id="StrutsPortlet">
      <portlet-name>sbridgestrutsportlet</portlet-name>
      <portlet-class>org.apache.portals.bridges.struts.StrutsPortlet</portlet-class>
      <init-param>
        <name>ServletContextProvider</name>
        <value>org.exoplatform.ServletContextProviderImpl</value>
      </init-param>
      <init-param>
        <name>ViewPage</name>
        <value>/view.do</value>
      </init-param>
      <init-param>
        <name>EditPage</name>
        <value>/edit.do</value>
      </init-param>
      <init-param>
        <name>StrutsPortletConfigLocation</name>
        <value>WEB-INF/struts-portlet-config.xml</value>
      </init-param>
      <expiration-cache&#620;</expiration-cache>
      <supports>
        <mime-type>text/html</mime-type>
        <portlet-mode>VIEW</portlet-mode>
        <portlet-mode>EDIT</portlet-mode>
      </supports>
      <portlet-info>
        <title>sbridgestrutsportlet</title>
        <keywords>Struts</keywords>
      </portlet-info>
    </portlet>

As you can see, the bridge relies on a portal-provided ServletContextProvider.
We provided it in a tiny jar : exo.pc.util-bridge-trunk.jar.
Source code is here : /portlet-container/trunk/applications/util-bridge

5.3 struts-config.xml

Your struts configuraton also needs to be updated with a portlet aware RequestProcessor.

<struts-config>
  <form-beans>
    <form-bean name="dummy" type="org.apache.struts.action.DynaActionForm">
      <form-property name="abc" type="java.lang.String" />
    </form-bean>
  </form-beans>
  <global-exceptions>
    <exception key="errors.general" type="java.lang.Exception" path="/error.jsp" />
  </global-exceptions>
  <global-forwards>
    <forward name="view" path="/View.do" />
    <forward name="failure" path="/Error.do" />
    <forward name="error" path="/Error.do" />
  </global-forwards>
  <action-mappings>
    <action path="/View" forward="/view.jsp" />
    <action path="/Edit" forward="/edit.jsp" />
    <action path="/Error" forward="/error.jsp"/>
    <action name="dummy" path="/ViewSubmit" scope="request" type="org.exoplatform.portletcontainer.applications.sbridgestrutsportlet.SubmitAction" unknown="false"
      validate="false">
      <forward name="success" path="/View.do" />
    </action>
  </action-mappings>
  <controller pagePattern="$M$P" inputForward="false" processorClass="org.apache.portals.bridges.struts.SpringDelegatingPortletProcessor" />
</struts-config>

If your struts actions are backed by spring framework, you may already be using org.springframework.web.struts.DelegatingRequestProcessor.

In order to keep bridge + spring capabilities, you will need to mix them in your own request processor such as :

public class SpringDelegatingPortletProcessor extends DelegatingRequestProcessor {

  public SpringDelegatingPortletProcessor() {
    super();
  }

  public void process(HttpServletRequest request, HttpServletResponse response) throws IOException,
      ServletException {
    if (PortletServlet.isPortletRequest(request)) {
      if (!(response instanceof PortletServletResponseWrapper)) {
        response = new PortletServletResponseWrapper(request, response);
      }
    }
    super.process(request, response);
  }

  protected boolean processRoles(HttpServletRequest request, HttpServletResponse response,
      ActionMapping mapping) throws IOException, ServletException {
    boolean proceed = super.processRoles(request, response, mapping);
    if (proceed && PortletServlet.isPortletRequest(request)
        && ((PortletServlet) super.servlet).performActionRenderRequest(request, response, mapping)) {
      return false;
    } else
      return proceed;
  }

}

5.4 struts-portlet-config.xml

It is the StrutsBridge configuraiton file.

<config>
      <render-context>
        <attribute name="errors"/>
        <attribute name="message"/>
      </render-context>
      <portlet-url-type>
        <resource path="/images/"/>
      </portlet-url-type>
    </config>

5.5 Dependencies

Add this to your pom:

<dependency>
      <groupId>org.exoplatform.portletcontainer</groupId>
      <artifactId>exo.pc.util-bridge</artifactId>
      <version>${org.exoplatform.pc.version}</version>
    </dependency>

    <dependency>
      <groupId>struts</groupId>
      <artifactId>struts</artifactId>
      <version>1.2.9</version>
    </dependency>
    
    <dependency>
      <groupId>org.apache.portals.bridges</groupId>
      <artifactId>portals-bridges-struts-1.2.7</artifactId>
      <version>1.0.4</version>
    </dependency>

Additionally, drop exo.pc.util-bridge-trunk.jar into your WEB-INF/lib

wsrp_service_and_struts_portlet.png

Tags:
Created by Alexey Zavizionov on 06/11/2007
Last modified by Sören Schmidt on 07/21/2009

Products

generated on Thu Sep 02 15:43:30 UTC 2010

eXo Optional Modules

eXo Core Foundations


Copyright (c) 2000-2010. All Rights Reserved - eXo platform SAS
2.4.30451