Skip Headers
Oracle® Fusion Middleware Federated Portals Guide for Oracle WebLogic Portal
10g Release 3 (10.3.2)

Part Number E14235-02
Go to Documentation Home
Home
Go to Table of Contents
Contents
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

7 Interportlet Communication with Remote Portlets

WebLogic Portal supports interportlet communication (IPC) between producers and consumers. For example, a remote portlet deployed in a producer application can handle a minimize event fired by a local portlet in a consumer. This chapter presents a detailed example explaining how to use interportlet communication with remote portlets.

This chapter includes these sections:

7.1 Introduction

WebLogic Portal provides an extension to the WSRP protocol that allows remote portlets to fire events during the interaction phase of their lifecycle. For detailed information on the WebLogic Portal IPC architecture for federated portlets, see Section 3.5.4, "Interportlet Communication with Events".

Communication between portlets deployed in consumer and producer applications is bi-directional. Events fired by local portlets can be handled by portlets deployed in a producer, and vice versa.

The example in this chapter demonstrates one way to implement event handling in a federated portal. In this example, the event handler is added to the portlet on the producer. When a local portlet on the consumer fires an event, the remote portlet on the producer receives the event and handles it (changes the text displayed in the portlet).

Note:

Whenever you implement event handling in a federated environment, remember that you must add event handlers to portlets in the producer application before you create proxy portlets in consumers. If you change a producer portlet's metadata, such as by adding an event handler, consumers are not notified of that change. The correct procedure is to add the event handler to the portlet on the producer before you create the remote portlet on the consumer.

For additional information on IPC in WebLogic Portal, see the Oracle Fusion Middleware Portlet Development Guide for Oracle WebLogic Portal.

7.2 Firing and Handling a Minimize Event

This section presents a detailed example demonstrating how to use event handling in a remote portlet. In this example, a remote portlet on the consumer fires an onMinimize event. The onMinimize event is fired when a portlet is minimized. When the event is fired from a local portlet in a consumer, the event is handled on the producer. The onMinimize event is one of several standard events supported by the WebLogic Portal framework. For a complete list of standard events, see the Oracle Fusion Middleware Portlet Development Guide for Oracle WebLogic Portal.

In this example, when the user minimizes the remote portlet on the consumer, the producer handles the event and changes some text in the portlet.

Tip:

Remote portlets can also handle custom events. For detailed information on using custom events with remote portlets, see Section 7.4, "Data Transfer with Custom Events".

This example includes these steps:

  1. Section 7.2.1, "Setting Up Your Environment"

  2. Section 7.2.2, "Creating the Portlets on the Producer"

  3. Section 7.2.3, "Creating the Consumer Portlets"

  4. Section 7.2.4, "Testing the Application"

7.2.1 Setting Up Your Environment

If you want to try the example discussed in this section, you need to run Oracle Enterprise Pack for Eclipse and perform the prerequisite tasks and set up the example environment.

To set up the example environment, perform the prerequisite tasks outlined in Table 7-1. If you are not familiar with the specific procedures for these tasks, they are described in detail in the WebLogic Portal tutorial Oracle Fusion Middleware Tutorials for Oracle WebLogic Portal.

Table 7-1 Prerequisite Tasks

Task Recommended Name

1. Create a WebLogic Portal domain.

ipcWsrpDomain 

2. Create a Portal EAR Project.

ipcWsrpPortalEAR 

3. Create an Oracle WebLogic Server v10.x.

N/A

3. Associate the EAR project with the server.

N/A

4. Create a Portal Web Project

consumerWeb

5. Create a second Portal Web Project

producerWeb

Figure 7-1 shows the Package Explorer after the prerequisite tasks have been completed.

Figure 7-1 Package Explorer After Prerequisite Tasks are Completed

Description of Figure 7-1 follows
Description of "Figure 7-1 Package Explorer After Prerequisite Tasks are Completed"

7.2.2 Creating the Portlets on the Producer

In this task, you create two JSP files on the producer-side, along with the JSP portlets that surface these files. You also create a backing file that contains the instructions necessary to complete the communication between two portlets and add an event handler to one of the portlets. Once you have created the portlets and attached the backing file, you will test the application in your browser.

7.2.2.1 Create the JSP Files and Portlets

To create the JSP files that the portlets deployed on the producer will surface:

  1. Be sure you have set up the example environment as explained previously in Section 7.2.1, "Setting Up Your Environment".

  2. In the Project View, right-click the WebContent folder and select New > Portlet.

  3. In the New Portlet dialog, enter the name aPortlet.portlet for the new portlet, and click Next.

  4. In the Select Portlet Type wizard page, select JSP/HTML Portlet, and click Next. (See Figure 7-2.)

    Figure 7-2 Select Portlet Type

    Description of Figure 7-2 follows
    Description of "Figure 7-2 Select Portlet Type"

  5. In the Portlet Details wizard page, select the Minimizable and Maximizable states, and click Create. (See Figure 7-3.)

    Figure 7-3 Portlet Details

    Description of Figure 7-3 follows
    Description of "Figure 7-3 Portlet Details"

  6. Locate the aPortlet.jsp file. By default, it will be in the WebContent/aportlet folder. Double-click the file to open it in the editor.

  7. Replace the default text in the file with the text "Minimize Me!" as shown in Figure 7-4.

    Figure 7-4 JSP File Showing Edited Body Text

    Description of Figure 7-4 follows
    Description of "Figure 7-4 JSP File Showing Edited Body Text "

  8. Save the file as aPortlet.jsp

  9. In the same directory, make a copy of aPortlet.jsp, and call the copy bPortlet.jsp.

  10. Open bPortlet.jsp in the editor and copy the code from Example 7-1 into the JSP, replacing everything from <netui:html> through </netui:html>. This code simply displays text placed in the request by a backing file, which you will create and attach to the portlet in a subsequent step.

    Example 7-1 New JSP Code for bPortlet.jsp

    <netui:html>
       <% String event = (String)request.getAttribute("minimizeEvent");%>
          <head>
             <title>
                Web Application Page
             </title>
          </head>
          <body>
             <p>
                Listening for portlet A minimize event:<%=event%>
             </p>
          </body>
    </netui:html>
    

    Figure 7-5 shows the completed JSP source file in the editor.

    Figure 7-5 Updated JSP Source

    Description of Figure 7-5 follows
    Description of "Figure 7-5 Updated JSP Source "

  11. Save the file.

  12. Following the same steps you used previously, generate a portlet from the bPortlet.jsp file.

    Checkpoint: At this point the you have created the following files in the producerWeb/WebContent folder:

    • aPortlet.jsp

    • aPortlet.portlet

    • bPortlet.jsp

    • bPortlet.portlet.

7.2.2.2 Create the Backing File

In this example, we use a backing file attached to the portlet in the producer to handle the onMinimize event fired on the consumer.

Tip:

For detailed information on backing files, refer to the Oracle Fusion Middleware Portlet Development Guide for Oracle WebLogic Portal.

To create the backing file:

  1. In producerWeb, expand the Java Resources node, right-click the src folder, and select New > Package from the menu. The Create New Folder dialog box appears.

  2. Create a source folder called backing.

    The backing folder appears under producerWeb/Java Resources/src, as shown in Figure 7-6.

    Figure 7-6 New Backing File Package

    Description of Figure 7-6 follows
    Description of "Figure 7-6 New Backing File Package"

  3. Right-click the backing package and select New > Class. The New Java Class dialog appears.

  4. In the Name field, enter Listening and click Finish. The new Java class appears in the editor.

  5. Delete the default contents of Listening.java, and copy the code from Example 7-2 into Listening.java.

  6. Save Listening.java.

Example 7-2 Backing File Code for listening.java

package backing;
import com.bea.netuix.servlets.controls.content.backing.AbstractJspBacking;
import com.bea.netuix.events.Event;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Listening extends AbstractJspBacking 
{ 
     static final long serialVersionUID=1L;
     private static boolean minimizeEventHandled = false;
     public void handlePortalEvent(HttpServletRequest request,
        HttpServletResponse response, Event event)
    {
        minimizeEventHandled = true;
    }
    public boolean preRender(HttpServletRequest request, HttpServletResponse
         response)
    {
        if (minimizeEventHandled){
                request.setAttribute("minimizeEvent","minimize event handled");
        }else{
                request.setAttribute("minimizeEvent",null);
        }
        // reset
        minimizeEventHandled = false;
         return true;
    }
}

The source should now look like that shown in Figure 7-7.

Figure 7-7 Listening.java with Updated Backing File Code

Description of Figure 7-7 follows
Description of "Figure 7-7 Listening.java with Updated Backing File Code"

7.2.2.3 Attach the Backing File

Now you will attach the backing file created in the previous section to bPortlet.portlet.

  1. In the Package Explorer, double-click bPortlet.portlet to open it.

  2. Click on the portlet in the editor to display the portlet's properties. To be sure you see all the properties, click on the border of the portlet, as shown in Figure 7-8.

    Figure 7-8 Click to Display All Portlet Properties

    Description of Figure 7-8 follows
    Description of "Figure 7-8 Click to Display All Portlet Properties"

    Tip:

    If the Properties view is not visible in your perspective, select Window > Show View > Properties. If you want to learn more about editing portlet properties, see the Oracle Fusion Middleware Portlet Development Guide for Oracle WebLogic Portal.
  3. In the Properties view, type backing.Listening into the Backable Properties > Portlet Backing File field, as shown in Figure 7-9 and press Return.

    Tip:

    You might need to expand the value column to enter text in the Portlet Backing File field.

    Figure 7-9 Attaching the Backing File in the Properties View

    Description of Figure 7-9 follows
    Description of "Figure 7-9 Attaching the Backing File in the Properties View"

  4. Save the file.

7.2.2.4 Add the Event Handler to bPortlet

You now add the event handler to bPortlet.portlet. The handler will be configured to listen for an event fired by another portlet and execute an action in response to that event. To add the event handler:

  1. Be sure the file bPortlet.portlet is open. If it is not, double-click it in the Package Explorer.

  2. Click on the portlet in the editor to display the portlet's properties, as shown previously in Figure 7-8.

  3. In the portlet editor, click the Event Handlers link, as shown in Figure 7-10. The Event Handlers dialog appears.

    Figure 7-10 Event Handlers Link

    Description of Figure 7-10 follows
    Description of "Figure 7-10 Event Handlers Link"

    Figure 7-11 Portlet Event Handlers Dialog Box

    Description of Figure 7-11 follows
    Description of "Figure 7-11 Portlet Event Handlers Dialog Box "

  4. Click Add Handler and select Handle Portal Event from the drop-down menu.

    The Portlet Event Handlers dialog box expands to allow entry of more details, as shown in Figure 7-12.

    Figure 7-12 Event Handler Dialog Box Expanded

    Description of Figure 7-12 follows
    Description of "Figure 7-12 Event Handler Dialog Box Expanded "

  5. Accept the defaults for all fields except Portlet.

  6. In the Portlet field, click the ellipses button (...). The Please Choose a File dialog box appears.

  7. Select aPortlet.portlet and click OK.

    The dialog box closes and aPortlet_1 appears in the Listen to list and the Portlet field, as shown in Figure 7-13. The label aPortlet_1 is the definition label of the portlet to which the event handler will listen.

    Tip:

    The definition label is a unique identifier for the portlet. A default value is entered automatically, but you can change the value. Each portlet must have a unique value. See the Oracle Fusion Middleware Portlet Development Guide for Oracle WebLogic Portal for more information.

    Figure 7-13 Adding portlet_1

    Description of Figure 7-13 follows
    Description of "Figure 7-13 Adding portlet_1"

  8. Click the Event drop-down menu to open the list of portal events that the handler can listen for and select onMinimize, as shown in Figure 7-14.

    Figure 7-14 Event Drop-down List

    Description of Figure 7-14 follows
    Description of "Figure 7-14 Event Drop-down List "

  9. Click Add Action... to open the action drop-down menu and select Invoke BackingFile Method.

  10. Open the Method drop-down menu and enter handlePortalEvent, as shown in Figure 7-15. This method is defined in the backing file that is attached to bPortlet. The source code for the backing file was shown previously in Example 7-2.

    Figure 7-15 Adding the Backing File Method

    Description of Figure 7-15 follows
    Description of "Figure 7-15 Adding the Backing File Method"

  11. Click OK.

    The event handler is added. Note that the Value field of the Event Handlers property now indicates 1 Event Handler.

    Note:

    WebLogic Portal attempts to validate the settings of the Event Handlers dialog. You will receive an error message if any problems are detected. For detailed information on the WebLogic Portal validation framework, see the Oracle Fusion Middleware Portal Development Guide for Oracle WebLogic Portal.

    Checkpoint: You added a backing file and an event handler to bPortlet. The event handler is configured to invoke the handlePortalEvent() method in the backing file when the portlet receives an onMinimize event fired by aPortlet. In the next task, you test the application to make sure that the portlets function properly in a local environment. Then, you will create a remote portlet in a consumer application to test the interportlet communication in a federated portal environment.

7.2.2.5 Test the Application

Create a portal in the producer application called ipcLocal.portal:

  1. In the Package Explorer, right-click producerWeb/WebContent and select New > Portal. The New Portal dialog appears.

  2. In the File name field, enter ipcLocal.portal and click Finish. The portal is created and appears in the editor.

  3. Drag both aPortlet.portlet and bPortlet.portlet from the Package Explorer onto the portal layout, as shown in Figure 7-16.

    Figure 7-16 Portal Layout with Portlets Added

    Description of Figure 7-16 follows
    Description of "Figure 7-16 Portal Layout with Portlets Added"

  4. Save the portal.

  5. Run the portal. To do this, right-click ipcLocal.portal in the Package Explorer and select Run As > Run on Server.

  6. In the Run On Server – Define a New Server dialog, click Finish.

    The portal renders in the default browser, as shown in Figure 7-17.

    Figure 7-17 ipcLocal Portal in Browser

    Description of Figure 7-17 follows
    Description of "Figure 7-17 ipcLocal Portal in Browser"

  7. Minimize aPortlet.

    Note the content change in bPortlet.

    Figure 7-18 ipcLocal Portal with aPortlet Minimized

    Description of Figure 7-18 follows
    Description of "Figure 7-18 ipcLocal Portal with aPortlet Minimized"

7.2.2.6 Summary

You created a portal containing two local portlets. You configured the portlet called bPortlet to respond to an onMinimize event fired from the portlet called aPortlet. The onMinimize event is a standard event that all WebLogic Portal portlets can fire. When bPortlet receives an onMinimize event, a backing file method is called that modifies the text displayed by the portlet.

In the following steps, you will create a federated portal that uses interportlet communication.

7.2.3 Creating the Consumer Portlets

In this section, you create two portlets in the consumer application, one a JSP portlet and the other a remote portlet. The remote portlet consumes the portlet you created previously on the producer, bPortlet.portlet.

7.2.3.1 Setting Up the Exercise

Before you continue with this exercise:

  1. In the Package Explorer, copy aPortlet.jsp from the producerWeb/WebContent folder and paste it into the consumerWeb/WebContent folder. For convenience, we reuse this portlet from the producer application. Its function in the consumer portal is simply to provide a portlet that you can minimize.

  2. Right-click consumerWeb/WebContent/aPortlet.jsp and select Generate Portlet.

  3. In the Portlet Details dialog, select Minimizable, Maximizable, and click Create. The new portlet layout appears in the editor.

7.2.3.2 Creating the Remote Portlet

To create the remote portlet:

  1. Open the consumerWeb folder in the Package Explorer, right-click on the WebContent folder, and select New > Portlet.

  2. In the New Portlet dialog, enter bPrime.portlet in the File name field, and click Finish.

  3. In the Select Portlet Type dialog of the Portlet Wizard, pick Remote Portlet, and click Next.

  4. In the Producer dialog, select Find Producer.

  5. Enter the producer's WSDL URL in the text field, as shown in Figure 7-19. The WSDL URL for this example is:

    http://host:port/producerWeb/producer?wsdl

    for example:

    http://localhost:7001/producerWeb/producer?wsdl

    Tip:

    WSDL stands for Web Services Description Language and is used to describe the services offered by a producer. For more information, see Chapter 3, "Federated Portal Architecture."
  6. Click Retrieve.

    After a few seconds, the dialog box refreshes, showing the Producer Details, as shown in Figure 7-19.

    Figure 7-19 Find Producer Dialog

    Description of Figure 7-19 follows
    Description of "Figure 7-19 Find Producer Dialog "

  7. Click Register.

  8. In the Register dialog, enter a name for the producer in the Producer Handle field, and click Register. You are returned to the Producer dialog.

  9. In the Producer dialog, click Next. The Select Portlet from List dialog appears.

  10. In the Select Portlet from List dialog, select bPortlet, as shown in Figure 7-20.

    Figure 7-20 Select Portlet From List Dialog Box

    Description of Figure 7-20 follows
    Description of "Figure 7-20 Select Portlet From List Dialog Box"

  11. Click Next. The Proxy Portlet Details dialog box appears.

  12. Click Create.

    The remote portlet appears as bPrime.portlet in the consumerWeb/WebContent folder in the Package Explorer.

  13. Change the portlet's title to bPrime. To do this, edit the Title field in the portlet's Properties view, as shown in Figure 7-21.

    Figure 7-21 Changing the Portlet Title

    Description of Figure 7-21 follows
    Description of "Figure 7-21 Changing the Portlet Title"

  14. Save the portlet.

    Tip:

    In the Properties view for bPortlet (in the producerWeb/WebContent folder) be sure the Render Cacheable property is set to false.

7.2.3.3 Summary

With the completion of the two consumer portlets, you have now created all of the necessary components to demonstrate interportlet communications between a remote and a local portlet. In the next step, you will add the consumer portlets to a consumer portal and raise an event on one portlet that will cause a reaction on the other.

7.2.4 Testing the Application

In this step, you test the consumer application to verify that minimizing aPortlet will change the content of bPrime (the remote portlet). You create a portal and add the two portlets created in Section 7.2.3, "Creating the Consumer Portlets". You then build the application and view the portal in a browser.

7.2.4.1 Build the Portal

Create a portal in the consumer application called ipcConsumer.portal:

  1. In the Package Explorer, right-click consumerWeb/WebContent and select New > Portal. The New Portal dialog appears.

  2. In the File name field, enter ipcConsumer.portal and click Finish. The portal is created and appears in the editor.

  3. Drag both aPortlet.portlet and bPrime.portlet from the consumerWeb/WebContent folder onto the portal layout. The result is shown in Figure 7-22.

    Figure 7-22 Consumer Portal Layout

    Description of Figure 7-22 follows
    Description of "Figure 7-22 Consumer Portal Layout"

  4. Save the portal.

7.2.4.2 Test the Portal

From a user's perspective, the consumer portal works exactly as if all portlets were local. The user is not aware that bPrime is a remote portlet hosted in a producer application. To test the consumer portlet, minimize aPortlet. The remote portlet, bPrime, responds changing the text it displays.

  1. Run the portal. To do this, right-click ipcConsumer.portal in the Package Explorer and select Run As > Run on Server.

  2. In the Run On Server – Define a New Server dialog, click Finish. A browser opens displaying the ipcConsumer portal, as shown in Figure 7-23.

    Figure 7-23 Consumer Portal in a Browser

    Description of Figure 7-23 follows
    Description of "Figure 7-23 Consumer Portal in a Browser"

  3. In aPortlet, click the Minimize button. The portlet aPortlet minimizes and the contents of bPortlet change, as shown in Figure 7-24.

    Figure 7-24 Consumer Portal in Browser After Minimize Event

    Description of Figure 7-24 follows
    Description of "Figure 7-24 Consumer Portal in Browser After Minimize Event"

7.3 Inside the Remote Portlet File

Example 7-3 shows an excerpt from the XML content of a .portlet file for the remote portlet described previously in this chapter, bPrime.portlet. Note that the element dispatchToRemotePortlet is added as part of the handleEvent definition. This element indicates that the consumer must dispatch the event to the producer.

Example 7-3 Excerpt from the bPrime.portlet File

...
<netuix:handleEvent event="onMinimize" eventLabel="handlePortalEvent1"
    fromSelfInstanceOnly="false" onlyIfDisplayed="true"
    sourceDefinitionLabels="aPortlet_1"> <netuix:dispatchToRemotePortlet/>
</netuix:handleEvent>
...

7.4 Data Transfer with Custom Events

Custom events are the recommended method for passing data between portlets deployed in consumer applications and portlets in remote producer applications. This section outlines a possible technique for passing data from a consumer to a producer using custom events. For more information on custom events, see "Custom Event Handling" in the Oracle Fusion Middleware Portlet Development Guide for Oracle WebLogic Portal.

Tip:

You can use custom events to pass data between any portlets, whether the portlets are local or on remote producers. For more information on event payloads that can be used with WSRP, see Section 7.5, "Event Payloads Over WSRP."

Figure 7-25 illustrates the configuration of the example discussed in this section.

Figure 7-25 Example configuration

Description of Figure 7-25 follows
Description of "Figure 7-25 Example configuration"

7.4.1 Retrieving the Event on the Producer

This section illustrates how a portlet on the producer can be configured to handle a custom event containing a payload. In this case, the portlet is a Java portlet associated with the class shown in Example 7-4. See also Section 7.5, "Event Payloads Over WSRP."

Example 7-4 Sample Java Portlet Class

import java.io.IOException;
import javax.portlet.PortletException;
import javax.portlet.GenericPortlet;
import javax.portlet.RenderResponse;
import javax.portlet.RenderRequest;
import javax.portlet.EventResponse;
import javax.portlet.EventRequest;
import javax.portlet.Event;
import javax.portlet.ProcessEvent;
 
public class JavaPortlet extends GenericPortlet 
{
                       @ProcessEvent(qname="{urn:com:oracle:wlp:netuix:event:custom}messageCustomEvent")
    public void getMessage(EventRequest request, EventResponse response)
        throws PortletException, IOException 
    {
        Event event = request.getEvent();
 
        // Get the event's payload
        String message = (String)event.getValue();         
        response.setRenderParameter("message0", message);
    }
 
    public void doView(RenderRequest request, RenderResponse response)
        throws PortletException, IOException 
    {
        String message = request.getParameter("message0");
        if (message == null) message = "";
        response.setContentType("text/html");
        response.getWriter().write("<p><b>Message From Consumer: </b>" +
        message + "</p>");
    }
}  

The getMessage() method receives the event object containing the payload sent from the consumer to the producer. In the following steps, you will configure the portlet.xml file to mark the portlet as processing this event. Note that in this case the custom event is fired by a portlet deployed to the consumer application.

To configure the event handler in the producer portlet:

  1. In Oracle Enterprise Pack for Eclipse, create a Java portlet using the class shown in Example 7-4.

  2. In the Package Explorer, double-click the Java portlet file to open the portlet in the editor, as shown in Figure 7-26.

    Figure 7-26 Java Portlet in the Editor

    Description of Figure 7-26 follows
    Description of "Figure 7-26 Java Portlet in the Editor"

  3. Click the No event handlers link in the Java portlet editor to open the Event Handler dialog box.

    Tip:

    The Portlet Event Handlers dialog box lets you create and configure event handlers for a portlet. An event handler listens for an event and takes a specified action when the event is received.
  4. In the Portlet Event Handlers dialog, click Add Processing Event...

  5. In the Define or Choose a Portlet Event Definition dialog, enter {urn:com:oracle:wlp:netuix:event:custom}messageCustomEvent in the QName or NCName field and click OK.

  6. Click OK on the Portlet Event Handlers dialog.

    Tip:

    For detailed information on the Event Namespace and Alias fields, see "About QNames and Aliases" in the Oracle Fusion Middleware Portlet Development Guide for Oracle WebLogic Portal.

    Figure 7-27 shows the completed dialog.

    Figure 7-27 Portlet Event Handlers Dialog

    Description of Figure 7-27 follows
    Description of "Figure 7-27 Portlet Event Handlers Dialog"

The Java portlet is now configured to handle an event called messageCustomEvent with the default custom event namespace of urn:com:oracle:wlp:netuix:event:custom. When this event is received, the portlet container will invoke the getMessage() method in the Java portlet class. This event handler provides a mechanism for interportlet communication whether the portlets are running locally or on a remote producer.

7.4.2 Firing the Event in the Consumer

A consumer portlet can be configured to fire a custom event, which is then handled on the producer. Example 7-5 illustrates code that could be used in a local portlet on the consumer to fire a custom event and attach a payload to that event.

Example 7-5 Sample Event-Firing Code

PortletBackingContext context =
PortletBackingContext.getPortletBackingContext(getRequest());
  context.fireCustomEvent("messageCustomEvent", form.getMessage());
return new Forward("success");

Refer to Oracle Fusion Middleware Java API Reference for Oracle WebLogic Portal for more information on the fireCustomEvent() method. For more information on portlet development and event handling, see the Oracle Fusion Middleware Portlet Development Guide for Oracle WebLogic Portal.

7.5 Event Payloads Over WSRP

This section discusses how WebLogic Portal handles event payloads sent over WSRP, and explains the rules WLP uses to package and convert event payloads. With knowledge of these rules, you can write portlets to send and/or receive events over WSRP from any other portlet, even if the portlet is on a third-party WSRP producer.

Tip:

For additional detailed information on how event payloads are handled over WSRP, review the Javadoc for the class com.bea.wsrp.model.markup.IEventContext.

7.5.1 Overview

Events can be sent from any portlet on the consumer or producer to any other portlet on the consumer or to any producer. The consumer is responsible for receiving events and distributing them to the appropriate portlets.When events are sent over WSRP, the event payload object must be sent in XML form to be WSRP-compliant, but the WSRP 2.0 specification does not dictate a particular scheme for encoding event payloads to ensure interoperability. It is therefore possible that an event could be received from a portlet on a third-party WSRP producer, and that WebLogic Portal would not know how to convert the event's payload to a Java object. For this reason, Oracle WebLogic Portal avoids converting event payloads to Java objects whenever possible. This allows a Oracle WebLogic Portal consumer to distribute events between portlets on third-party producers even though the consumer cannot understand the event payload. When event payload conversion into or from a WSRP SOAP message is necessary, WebLogic Portal follows the guidelines discussed in this section. Two special Java objects are used for WSRP event payloads in these cases:

  • com.bea.wsrp.ext.holders.NamedStringArray – This class represents the optional NamedStringArray schema type defined in the WSRP 2.0 specification for event payloads, and represents an ordered list of name/value pairs of simple strings.

  • com.bea.wsrp.ext.holders.XmlPayload – This class represents arbitrary XML for an event's payload.

7.5.2 How WLP Packages Event Payloads in XML Format

When packaging an event payload into a WSRP SOAP message, WebLogic Portal uses the following logic to convert the event payload to XML. This scenario occurs, for example, when an event is sent by a portlet on the consumer and needs to be delivered to a portlet on a producer, or when a portlet on a WLP producer sends an event.

  1. If the event's payload is an instance of the com.bea.wsrp.ext.holders.NamedStringArray class, the event payload is encoded in a WSRP 2.0 NamedStringArray schema type.

  2. Otherwise, if the event's payload is an instance of com.bea.wsrp.ext.holders.XmlPayload, the event payload is encoded as the XML represented by the object.

  3. Otherwise, if the event's payload is a Java object with a Java Architecture for XML Binding (JAXB) binding, JAXB serialization will be used to encode the payload as XML.

  4. Otherwise, the event's payload is serialized using Java serialization, base-64 encoded, and put in a WLP-specific XML event schema type.

7.5.3 How WLP Converts an Event Payload to a Java Object

When converting an event payload from a WSRP SOAP message to a Java object, WebLogic Portal uses the following logic. This scenario occurs, for example, when an event is sent by a producer portlet and delivered to a portlet on the consumer, or when an event is received by a portlet on a WLP producer.

  1. If the event's payload in the SOAP message is encoded in a WSRP 2.0 NamedStringArray schema type, it is converted into a com.bea.wsrp.ext.holders.NamedStringArray object.

  2. Otherwise, if the event's payload in the SOAP message is encoded in the WLP-specific serialized Java object schema, the object is deserialized. Note that this requires the appropriate Java class that is being deserialized to be in the class path.

  3. Otherwise, JAXB deserialization is attempted on the XML representation of the event's payload.

  4. If JAXB deserialization fails, an object of type com.bea.wsrp.ext.holders.XmlPayload is created to hold the raw XML representation of the event payload.

7.6 Using Shared Parameters

Shared parameters allow portlets (including remote portlets) to share simple String values with other portlets during all phases of the portlet lifecycle. For detailed information, see "Using Shared Parameters" in the Oracle Fusion Middleware Portlet Development Guide for Oracle WebLogic Portal.

7.7 Adding Event Aliases

If a remote portlet handles a custom event, you have the opportunity to create aliases for the event in the remote portlet. Aliases provide a mechanism for renaming events as they are delivered to individual portlets, allowing communication between portlets that may not have been designed to communicate with each other. For detailed information on aliases, see "About QNames and Aliases" in the Oracle Fusion Middleware Portlet Development Guide for Oracle WebLogic Portal.

To add alias(es) to an event in a remote portlet:

  1. Bring up the Portlet Event Handlers dialog. One way to do this is in the Properties view, click the Event Handlers button. Another way is to click the Event Handlers link in the portlet editor. If no event handlers exist for the portlet, this link is called No event handlers.

  2. In the WLP-Handled Events column of the dialog select Handle Custom Event.

  3. In the right side of the dialog, click Edit next to the Aliases field. The Provide List of QName Alias(es) dialog appears, as shown in Figure 7-28.

    Figure 7-28 Provide List of QName Alias(es) Dialog

    Description of Figure 7-28 follows
    Description of "Figure 7-28 Provide List of QName Alias(es) Dialog"

  4. Add one or more aliases to the list. The new button brings up a dialog that helps you to construct the alias properly. For detailed information on constructing alias names, see "About QNames and Aliases" in the Oracle Fusion Middleware Portlet Development Guide for Oracle WebLogic Portal.

  5. Click OK to complete the task.