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

Part Number E14235-07
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

12 Transferring Custom Data

WebLogic Portal supports a relatively simple technique for passing custom data between consumers and producers. A set of interfaces is provided that let you attach arbitrary data to request and response objects. This chapter explains how to use these interfaces to achieve custom data transfer and includes detailed examples.

This chapter includes the following topics:

12.1 What is Custom Data Transfer?

Custom data transfer allows portlet developers to exchange arbitrary data between producers and consumers. The primary use cases for custom data transfer are:

Some example use cases for custom data transfer include:

Custom data transfer allows you to easily resolve these situations and many others like them. The technique for using custom data transfer is straightforward, and involves these primary tasks:

  1. Create one or more "holder" classes that implement the interfaces listed in the following section, "Section 12.2, "Custom Data Transfer Interfaces"." A serializable default implementation of the interfaces, called SimpleStateHolder is provided with WebLogic Portal.

  2. Place a serializable holder object in a request or response object, as appropriate. For example, in a consumer application, you can set a holder object as a request parameter and retrieve it in the producer application. See Section 12.3.1, "Custom Data Transfer with a Complex Producer" for a detailed example of this technique.

Both simple producers and complex producers can take advantage of this feature.

12.2 Custom Data Transfer Interfaces

The following interfaces enable the transfer of data between producers and consumers. To perform custom data transfer, implementations of these interfaces must be deployed on both the consumer and producer.

Section 12.3, "Performing Custom Data Transfer" includes a detailed example demonstrating how to use these interfaces. For more information on these interfaces, refer to their Oracle Fusion Middleware Java API Reference for Oracle WebLogic Portaldescriptions.

Note:

These interfaces are not supported for events and render dependencies requests.

Tip:

If you do not want to create your own implementations of these interfaces, the serializable com.bea.wsrp.ext.holders.SimpleStateHolder class provides a default implementation. The examples in this chapter use SimpleStateHolder to pass custom data.

12.3 Performing Custom Data Transfer

This section presents examples that illustrate how to use custom data transfer between consumers and producers. Both examples use the serializable com.bea.wsrp.ext.holders.SimpleStateHolder class, which implements the five interfaces listed previously in Section 12.2, "Custom Data Transfer Interfaces". This class provides a default implementation of the above interfaces that lets you exchange simple name-value pairs of data.

The examples include:

12.3.1 Custom Data Transfer with a Complex Producer

This example explains how to transfer data from a consumer to a complex producer. For information on complex producers, see Section 3.4.2, "WebLogic Portal Producers".

12.3.1.1 Example Overview

In this example, a backing file in the consumer application packages arbitrary data in a com.bea.wsrp.ext.holders.SimpleStateHolder object. This object is attached to a request using the setAttribute() method. The producer retrieves the data from the request and places it in a JSP page. The modified page is then displayed by the consumer application.

The example consists of these steps:

  1. Section 12.3.1.2, "Setting Up the Example"

  2. Section 12.3.1.3, "Creating the Producer JSP and Portlet"

  3. Section 12.3.1.4, "Federating zipTest.portlet to the Consumer"

  4. Section 12.3.1.5, "Creating a Backing File"

  5. Section 12.3.1.6, "Testing the Consumer Application"

12.3.1.2 Setting Up the Example

If you want to try the example discussed in this chapter, you need to run Oracle Enterprise Pack for Eclipse and perform the prerequisite tasks listed in Table 12-1. For detailed information on performing these basic setup tasks, see "Setting Up Your Portal Development Environment" in Oracle Fusion Middleware Tutorials for Oracle WebLogic Portal.

Table 12-1 Prerequisite Tasks

Task Recommended Name

Create a Portal domain.

wsrpPortalDomain 

Create a Portal EAR Project.

wsrpPortalEAR 

Create an Oracle WebLogic Server v10.x.

N/A

Associate the EAR project with the server.

N/A

Create a Portal Web Project and add it to the EAR.

consumerProject 

Create a second Portal Web Project and add it to the EAR.

producerProject 

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

Figure 12-1 Package Explorer After Prerequisite Tasks are Completed

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

We also assume that you know how to view and edit portlet properties in the Properties view. For information, see the Oracle Fusion Middleware Portlet Development Guide for Oracle WebLogic Portal.

12.3.1.3 Creating the Producer JSP and Portlet

With the example environment in place, create a JSP file on the producer and a portlet to surface that file. Code placed in the JSP file retrieves a SimpleStateHolder object from the request, retrieves its data payload, and displays the data.

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

  2. Right-click producerProject/WebContent in the Package Explorer and select New > JSP. The New JavaServer Page dialog appears.

  3. In the dialog, enter zipTest.jsp in the File name field, and click Finish.

  4. Replace the entire contents of the JSP source file with the code in Example 12-1.

    Example 12-1 Code to Get State from the Request

    <%@ page import ="com.bea.wsrp.ext.holders.SimpleStateHolder,
              com.bea.wsrp.ext.holders.MarkupRequestState"%> 
    <%
        SimpleStateHolder state = (SimpleStateHolder)
        request.getAttribute(MarkupRequestState.KEY);
        String zip = (String) state.getParameter("zipCode");
    %>
    <%=zip%>
    

    Figure 12-2 shows the editor with the new source code.

    Figure 12-2 New JSP Source for zipTest.jsp

    Description of Figure 12-2 follows
    Description of "Figure 12-2 New JSP Source for zipTest.jsp"

  5. Save the file.

    Tip:

    Later in this example, you will add a backing file to the proxy portlet in the consumer web application. This backing file creates the SimpleStateHolder object, adds some data to it, and puts the object into the request that is sent from the consumer to the producer. For more information on SimpleStateHolder, refer to its description in Oracle Fusion Middleware Java API Reference for Oracle WebLogic Portal.

  6. In the Package Explorer view, open the producerProject/WebContent folder. Right-click zipTest.jsp in the WebContent folder and select Generate Portlet.

    The Portlet Details dialog box appears. Note that zipTest.jsp already appears in the Content Path field, as shown in Figure 12-3.

    Figure 12-3 Portlet Details with zipTest.jsp Included

    Description of Figure 12-3 follows
    Description of "Figure 12-3 Portlet Details with zipTest.jsp Included "

  7. In the State checkbox, select Minimizable and Maximizable, then click Next and then click Create.

    The portlet zipTest.portlet appears in the Package Explorer, as shown in Figure 12-4.

    Figure 12-4 New JSP Portlet

    Description of Figure 12-4 follows
    Description of "Figure 12-4 New JSP Portlet "

12.3.1.4 Federating zipTest.portlet to the Consumer

Next, create a remote portlet in the consumer application to surface in zipTest.portlet from the producer:

  1. Be sure that WebLogic Server is running. If not, select the Servers tab. Make sure the Oracle WebLogic Server v10.x is selected, and click the Start button, as shown in Figure 12-5.

    Figure 12-5 Click the Start Button to Start the Server

    Description of Figure 12-5 follows
    Description of "Figure 12-5 Click the Start Button to Start the Server"

  2. In the Package Explorer, open the consumerProject folder.

  3. Right-click the WebContent folder, and select New > Portlet.

    Tip:

    The Portlet selection only appears on the New menu if you are using the Portal perspective. Switch to the Portal perspective if Portlet does not appear on the menu.

    The New Portlet dialog box appears, as shown in Figure 12-6.

    Figure 12-6 New Portlet Dialog

    Description of Figure 12-6 follows
    Description of "Figure 12-6 New Portlet Dialog"

  4. In the New Portlet dialog, select WebContent as the parent folder, enter zipPrime.portlet in the File name field, and click Next.

    The Select Portlet Type dialog box appears as shown in Figure 12-7.

    Figure 12-7 Select Portlet Type Dialog

    Description of Figure 12-7 follows
    Description of "Figure 12-7 Select Portlet Type Dialog "

  5. Select Remote Portlet and click Next. The Portlet Wizard – Producer dialog box appears.

  6. In the Portlet Wizard – Producer dialog, select Find Producer and, in the field provided, enter the following WSDL URL, as shown in Figure 12-8:

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

    Tip:

    Of course, the host name localhost is only appropriate if the producer is running on the same server as the consumer. We co-located the consumer and producer to simplify the presentation of this example. Typically, producers and consumers do not run in the same server.

  7. After entering the WSDL URL, click Retrieve.

    Tip:

    WSDL stands for Web Services Description Language and is used to describe the services offered by a producer. For more information, see Section 3.4.3, "WebLogic Portal Consumers".

    After a few moments, the Portlet Wizard – Producer dialog box refreshes, and registration information appears in the Producer Details panel, as shown in Figure 12-9.

    Tip:

    Registration is an optional feature described in the WSRP specification. A WebLogic Portal complex producer implements this option and, therefore, requires consumers to register before discovering and interacting with portlets offered by the producer. See Section 3.4.2.2, "Complex Producers" for more information.

    Figure 12-9 Producer Retrieved

    Description of Figure 12-9 follows
    Description of "Figure 12-9 Producer Retrieved"

  8. Click Register. The Register dialog appears.

  9. In the Register dialog, enter myProducer in the Producer Handle field, as shown in Figure 12-10, and click Register. The handle is stored on the consumer and is used to identify the producer.

    Figure 12-10 The Register Dialog

    Description of Figure 12-10 follows
    Description of "Figure 12-10 The Register Dialog"

  10. In the Portlet Wizard – Producer dialog, click Next. The Select Portlet from List dialog box appears.

  11. From the portlet list, select zipTest, as shown in Figure 12-11.

    Figure 12-11 Select Portlet from List Dialog Box

    Description of Figure 12-11 follows
    Description of "Figure 12-11 Select Portlet from List Dialog Box "

  12. Click Next. The Proxy Portlet Details dialog box appears, as shown in Figure 12-12.

    Figure 12-12 Proxy Portlet Details Dialog Box

    Description of Figure 12-12 follows
    Description of "Figure 12-12 Proxy Portlet Details Dialog Box "

  13. Click Create.

    The new portlet appears in the Editor, as shown in Figure 12-13.

    Figure 12-13 New Remote Portlet zipPrime.portlet in the Editor

    Description of Figure 12-13 follows
    Description of "Figure 12-13 New Remote Portlet zipPrime.portlet in the Editor"

12.3.1.5 Creating a Backing File

In this step, you will create a backing file called CustomDataBacking.java in the consumer application. Then, you will attach the backing file to the remote portlet you created previously, zipPrime.portlet.

Tip:

A backing file is a Java class that adds functionality to a portlet. For information on backing files, see the Oracle Fusion Middleware Portlet Development Guide for Oracle WebLogic Portal.

  1. In the Package Explorer tree, open the consumerProject folder, expand the Java Resources node, and right-click the src folder, and create a new Source Folder called backing.

    The src/backing folder appears in the Package Explorer, as shown in Figure 12-14.

    Tip:

    Alternatively, instead of a folder, you can create a Java package.

    Figure 12-14 backing Folder

    Description of Figure 12-14 follows
    Description of "Figure 12-14 backing Folder"

  2. Right-click the backing folder and select New > Class. The New Java Class dialog appears, as shown in Figure 12-15.

    Figure 12-15 New Java Class Dialog

    Description of Figure 12-15 follows
    Description of "Figure 12-15 New Java Class Dialog"

  3. In the Name field, enter CustomDataBacking and click Finish. The new Java source file appears in the editor.

  4. Replace the entire contents of the Java source file with the code in Example 12-2.

    Example 12-2 Adding an Instance of SimpleStateHolder

    package backing;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import com.bea.netuix.servlets.controls.content.backing.AbstractJspBacking;
    import com.bea.wsrp.ext.holders.MarkupRequestState;
    import com.bea.wsrp.ext.holders.SimpleStateHolder;
    
    public class CustomDataBacking extends AbstractJspBacking
    {
       private static final long serialVersionUID = 1L;
       public boolean preRender(HttpServletRequest request, 
          HttpServletResponse response)
       {
          SimpleStateHolder state = new SimpleStateHolder();
          state.addParameter("zipCode", "80501");
          request.setAttribute(MarkupRequestState.KEY, state);
          return true;
       }
    }
    
  5. Save the file. The completed backing file is shown in Figure 12-16.

    Figure 12-16 CustomDataBacking.java in the Editor

    Description of Figure 12-16 follows
    Description of "Figure 12-16 CustomDataBacking.java in the Editor"

    Tip:

    The backing file implements the AbstractJspBacking.preRender() method. This method is called before the request is sent to the producer. The implementation attaches a SimpleStateHolder object containing custom data to the request. This object will be retrieved on the producer where the data is extracted and displayed in the remote portlet.

  6. Double-click zipPrime.portlet to display it in the editor.

  7. Add the backing file to zipPrime.portlet. To do this, enter the full classname of the backing file in the Backing File field in the Properties view:

    backing.CustomDataBacking

    Figure 12-17 shows the class name after it has been added.

    Figure 12-17 Adding a Backing File

    Description of Figure 12-17 follows
    Description of "Figure 12-17 Adding a Backing File"

12.3.1.6 Testing the Consumer Application

With the consumer application components in place, you can now test the configuration. If the test is successful, the zip code 80501, provided by the backing file, will appear in the remote portlet when it is rendered.

To test the application:

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

  2. In the File name field, enter zipTest.portal and click Finish.

    The portal is created and appears in the editor, as shown in Figure 12-18.

    Figure 12-18 zipTest.portal in the Editor

    Description of Figure 12-18 follows
    Description of "Figure 12-18 zipTest.portal in the Editor"

  3. Drag the remote portlet zipPrime.portlet from Package Explorer view into the portal. (You can place it in either the left or right column; in Figure 12-19, it is in the right-hand column).

    Figure 12-19 zipTest.portlet Added to zipTest.portal

    Description of Figure 12-19 follows
    Description of "Figure 12-19 zipTest.portlet Added to zipTest.portal"

  4. Save the portal.

  5. Run the portal. To do this, right-click zipTest.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 appears in the Oracle Enterprise Pack for Eclipse browser. The custom data sent from the consumer displays in the portlet, as shown in Figure 12-20.

    Figure 12-20 zipTest.portal Successfully Rendered

    Description of Figure 12-20 follows
    Description of "Figure 12-20 zipTest.portal Successfully Rendered "

12.3.2 Custom Data Transfer in a Simple Producer

The previous section, Section 12.3.1, "Custom Data Transfer with a Complex Producer", explains how to transfer data between a WebLogic Portal consumer application and a complex producer running in a WebLogic Portal domain. You can also transfer data between a WebLogic Portal consumer and a simple producer running in a WebLogic Server domain.

Tip:

For a detailed discussion of complex and simple producers, see Section 3.4.2, "WebLogic Portal Producers".

To use custom data transfer with a simple producer:

  1. Properly configure a simple producer running in a WebLogic Server domain. The procedure for doing this is explained in Chapter 8, "Configuring a WebLogic Server Producer."

  2. Use the Custom Data Transfer interfaces listed in Section 12.2, "Custom Data Transfer Interfaces" to set and retrieve data in request and response objects. Follow the same basic procedure described for complex producers in Section 12.3.1, "Custom Data Transfer with a Complex Producer".

12.4 Transferring XML Data

Use an implementation of the com.bea.wsrp.ext.holders.XmlPayload interface to transfer XML data (objects of type Element) between consumers and producers. You can place an instance of this class directly in request and response objects. For more information on the XmlPayload interface, refer to its description in Oracle Fusion Middleware Java API Reference for Oracle WebLogic Portal.

Example 12-3 shows sample code that uses XmlPayload.

Example 12-3 XmlPayload Example

//-- Create an Element object to send. 
Element xml = ... 

XmlPayload payload = new XmlPayload(xml);
httpRequest.setAttribute(MarkupRequestState.KEY, payload); 

12.5 Deploying Your Own Interface Implementations

This section discusses guidelines for implementing the custom data transfer interfaces listed in Section 12.2, "Custom Data Transfer Interfaces".

12.5.1 General Guidelines

  • The implementation must be serializable.

  • The same class version of the implementation must be deployed on both the producer and consumer. If the versions are different, the implementations must make sure to have the same serialVersionUID for all versions.

  • Sending large amounts of data may have performance implications.

    Tip:

    The com.bea.wsrp.ext.holders.SimpleStateHolder class provides a default implementation of the four data transfer interfaces. This class lets you exchange simple name-value pairs of data. For detailed information on the methods of this class, refer to its description in Oracle Fusion Middleware Java API Reference for Oracle WebLogic Portal.

12.5.2 Implementation Rules

Whether a consumer or producer can send custom data depends on the type of request. These rules apply:

  • Consumers can always send InteractionRequestState. There are no exceptions.

  • Producers can always return InteractionResponseState. There are no exceptions.

  • Consumers can send MarkupRequestState only when there is a need to refresh the portlet. For example, if caching is enabled on the remote portlet, consumer may not always send a request to the producer to generate markup.

  • Consumers cannot return MarkupResponseState if any the following options are enabled:

    • Returning markup as an attachment

    • Local proxy

      In both the cases, the producer invokes the portlet (typically JSPs) after creating the SOAP response, which is too late to update the SOAP response.