A JSR168-compliant implementation of inter-portlet communication

Note: there is now a new version of the messaging library available.

Messaging library:

Cross-context messaging:

The messaging library supports messaging between portlets in different web applications, but this requires some configuration and extra work as discussed in the Cross-Context documentation.

If you put all your communicating portlets into the same webapp, you will not need this.

Show the cross-context examples: more

Provided here is an example implementation of a remote MessageStore (an EJB) and corresponding client, with two example portlet applications for testing it.

The EJB (messaging-example-ejb-1.0.jar) needs to be hosted on an appropriate server: install instructions are provided below for JBoss and Geronimo. These instructions assume that this server will be separate from the one on which the portal & portlets are installed (e.g. you have separately downloaded a JBoss installer and a Jetspeed+Tomcat installer), although they could be the same. The portlet webapp using messaging then needs to be configured to connect to the EJB server using the correct JNDI client properties (set in PortletMessaging.properties), and provided with any necessary EJB client libraries in its WEB-INF/lib.

Here are the 'bare' portlet webapps - with no EJB client libraries added - for if you are using a different EJB server version than those I've tried:

Both of these messaging webapps contain the same portlets; their names are marked with "A" and "B" so you can tell which app they are from.
You can test out cross-context messaging most easily with the test portlets Portlet1 and Portlet2: try adding Portlet1A and Portlet2B to the same page, to see how they can communicate.
You can also use the MessageReader portlet as a debug output to see which messages are visible in that webapp - both MessageReaderA and MessageReaderB should see the same messages.

Installing on JBoss more

I've tested this with JBoss 3.2.7 and 4.0.2. The following instructions will not work with 4.0.3, but apparently this problem has been fixed with 4.0.4 (not tried).

  1. (probably necessary) Change the HTTP port (8080) of JBoss's Tomcat so that it doesn't conflict with a separate Portal install on the same machine.
    Edit jboss/server/default/deploy/jbossweb-tomcat5X.sar/server.xml and modify the "HTTP/1.1 Connector on port 8080" to Connector port="7070"
  2. Deploy the EJB, and the portlet-messaging JAR which it depends on.
    Put messaging-example-ejb-1.0.jar in jboss/server/default/deploy/, and portlet-messaging-2.2.jar in jboss/server/default/lib/.
  3. Install the two example portlet webapps.
    • For JBoss 3.2.7more
    • For JBoss 4.0.2more
    • For JBoss 4.0.3 - don't!
    • Another version of JBossmore
      Use the 'bare' webapps messaging-webapp-A.war and messaging-webapp-B.war. Modify both the WARs containing the messaging portlets - either before deploying them to the portal, or after they've been deployed and you can edit the decompressed webapp (restart the portal after making changes if you do this).
      1. The provided messaging webapps have already been configured to use the correct MessageStore and SessionIDRetriever; they just need to be configured to connect to JBoss.
      2. In both WEB-INF/classes/message/PortletMessaging.properties, ensure that the JBoss settings are uncommented and the Geronimo ones are commented or removed.
      3. Copy jboss/client/jbossall-client.jar to both the messaging webapps' WEB-INF/lib/.
  4. Start up JBoss and your Portal server, and try out the portlets!
    jboss/bin/run
  5. Problems
    Have a look in jboss/server/default/log/ for clues... the EJB will output debug messages when it is accessed by the portlets.
    There may also be errors in the portal's log if there is a problem connecting to the EJB. If you're running Tomcat from tomcat/bin/startup.bat in Windows, and errors are only going to the console, not log files, try running it as a windows service instead: "service.bat install" then start the "Apache Tomcat" service.
Installing on Geronimo more

Tested on Geronimo 1.0.

  1. (probably necessary) Change Geronimo's HTTP port so that it doesn't conflict with a separate Portal install on the same machine.
    1. Start up Geronimo.
      geronimo/bin/startup
    2. Go to the web console: http://localhost:8080/console (system/manager).
    3. Navigate to Server -> Web Server, and change the HTTP connector originally on 8080 to 7070.
    4. Restart the server.
    5. Note that the web console will now be accessible at http://localhost:7070/console!
  2. Create the database table that the EJB will use to store the messages, in SystemDatabase:
    CREATE TABLE MessageStoreTable(SESSION_ID VARCHAR(255),STORE BLOB)
    1. With Geronimo running, go to the web console: http://localhost:7070/console (system/manager). (use the correct HTTP port)
    2. Navigate to Misc -> Embedded DB -> DB Manager.
    3. Use DB: SystemDatabase
    4. Add the SQL to the text area: CREATE TABLE MessageStoreTable(SESSION_ID VARCHAR(255),STORE BLOB)
    5. Run SQL
  3. Add the portlet-messaging-2.2.jar as a common library in group portlet-messaging.
    1. With Geronimo running, go to the web console: http://localhost:7070/console (system/manager). (use the correct HTTP port)
    2. Navigate to Services -> Common Libraries
    3. Upload portlet-messaging-2.2.jar:
      Group portlet-messaging
      Artifact portlet-messaging
      Version 2.2
      Type jar
  4. Deploy the EJB
    1. With Geronimo running, go to the web console: http://localhost:7070/console (system/manager). (use the correct HTTP port)
    2. Navigate to Applications -> Deploy New
    3. Upload the EJB Archive, no Plan
    4. Problems
      Try deploying from the console, in geronimo/bin; you'll be able to see the error messages that way:
      java -jar deployer.jar --user system --password manager --syserr deploy D:\messaging-example-ejb-1.0.jar
  5. Install the two example portlet webapps.
    • For Geronimo 1.0 more
    • Another version of Geronimo more
      Use the 'bare' webapps messaging-webapp-A.war and messaging-webapp-B.war. Modify both the WARs containing the messaging portlets - either before deploying them to the portal, or after they've been deployed and you can edit the decompressed webapp (restart the portal after making changes if you do this).
      1. The provided messaging webapps have already been configured to use the correct MessageStore and SessionIDRetriever; they just need to be configured to connect to JBoss.
      2. In both WEB-INF/classes/message/PortletMessaging.properties, ensure that the Geronimo settings are uncommented and the JBoss ones are commented or removed.
      3. Copy all required client libraries to both the messaging webapps' WEB-INF/lib/. You can get these from geronimo/repository. For Geronimo 1.0, these are:
        • openejb / openejb-core
        • cglib / cglib-nodep
        • geronimo / geronimo-security
        • geronimo / geronimo-kernel
        Also, I needed to get from ibiblio:
        • geronimo-spec / geronimo-spec-j2ee-jacc / 1.0-rc4
        • geronimo-spec / geronimo-spec-ejb / 2.1-rc4
  6. Start up Geronimo and your Portal server, and try out the portlets!
    geronimo/bin/startup
  7. Problems
    Have a look in geronimo/var/log/ for clues... the EJB will output debug messages when it is accessed by the portlets.
    There may also be errors in the portal's log if there is a problem connecting to the EJB. If you're running Tomcat from tomcat/bin/startup.bat in Windows, and errors are only going to the console, not log files, try running it as a windows service instead: "service.bat install" then start the "Apache Tomcat" service.