Federated Portals Guide

     Previous  Next    Open TOC in new window    View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

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:

 


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:

Note: It is recommend that you use this technique only after trying other techniques for data transfer. The preferred technique for transferring data between producers and consumers is to use custom events. For more information, see Data Transfer with Custom Events.

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, “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 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.

 


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.

Performing Custom Data Transfer includes a detailed example demonstrating how to use these interfaces. For more information on these interfaces, refer to their Javadoc descriptions.

Note: These interfaces are not supported for events and render depencencies requests.

com.bea.wsrp.ext.holders.InteractionRequestState

Allows the consumer to send some arbitrary data to the producer when an interaction (such as a form submission) occurs.

com.bea.wsrp.ext.holders.InteractionResponseState

Allows the producer to return some arbitrary data to the consumer after an interaction occurs.

com.bea.wsrp.ext.holders.MarkupRequestState

Allows the consumer to send some arbitrary data to the producer when a portlet is being refreshed.

com.bea.wsrp.ext.holders.MarkupResponseState

Allows the producer to return some arbitrary data to the producer after portlet is rendered.

com.bea.wsrp.ext.holders.XmlPayload

Transfers XML data between consumers and producers. You can place an instance of this class directly in request and response objects. For more information, see Transferring XML Data.
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.

 


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 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:

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 WebLogic Portal Producers.

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. Setting Up the Example
  2. Creating the Producer JSP and Portlet
  3. Federating zipTest.portlet to the Consumer
  4. Creating a Backing File
  5. Testing the Consumer Application

Setting Up the Example

If you want to try the example discussed in this chapter, you need to run Workshop for WebLogic and perform the prerequisite tasks listed in Table 13-1. For detailed information on performing these basic setup tasks, see the WebLogic Portal tutorial Setting Up Your Portal Development Environment.

Table 13-1 Prerequisite Tasks  
Task
Recommended Name
Create a Portal domain.
wsrpPortalDomain
Create a Portal EAR Project.
wsrpPortalEAR
Create a BEA WebLogic v10.0 Server.
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 13-1 shows the Package Explorer after the prerequisite tasks have been completed.

Figure 13-1 Package Explorer After Prerequisite Tasks are Completed

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 WebLogic Portal Portlet Development Guide.

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 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 Listing 13-1.
  5. Listing 13-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 13-2 shows the editor with the new source code.

    Figure 13-2 New JSP Source for zipTest.jsp


    New JSP Source for zipTest.jsp

  6. Save the file.
  7. 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 Javadoc description.
  8. In the Package Explorer view, open the producerProject/WebContent folder. Right-click zipTest.jsp in the WebContent folder and select Generate Portlet...
  9. The Portlet Details dialog box appears. Note that zipTest.jsp already appears in the Content Path field, as shown in Figure 13-3.

    Figure 13-3 Portlet Details with zipTest.jsp Included


    Portlet Details with zipTest.jsp Included

  10. In the State checkbox, select Minimizable and Maximizable, and click Create.
  11. The portlet zipTest.portlet appears in the Package Explorer, as shown in Figure 13-4.

    Figure 13-4 New JSP Portlet


    New JSP Portlet

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 BEA WebLogic Server v10.0 is selected, and click the Start button, as shown in Figure 13-5.
  2. Figure 13-5 Click the Start Button to Start the Server


    Click the Start Button to Start the Server

  3. In the Package Explorer, open the consumerProject folder.
  4. Right-click the WebContent folder, and select New > Portlet.
  5. 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 13-6.

    Figure 13-6 New Portlet Dialog


    New Portlet Dialog

  6. In the New Portlet dialog, select WebContent as the parent folder, enter zipPrime.portlet in the File name field, and click Finish.
  7. The Select Portlet Type dialog box appears as shown in Figure 13-7.

    Figure 13-7 Select Portlet Type Dialog


    Select Portlet Type Dialog

  8. Select Remote Portlet and click Next. The Portlet Wizard – Producer dialog box appears.
  9. In the Portlet Wizard – Producer dialog, select Find Producer and, in the field provided, enter the following WSDL URL, as shown in Figure 13-8:
  10. 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.
    Figure 13-8 The WSDL URL


    The WSDL URL

  11. After entering the WSDL URL, click Retrieve.
  12. Tip: WSDL stands for Web Services Description Language and is used to describe the services offered by a producer. For more information, see 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 13-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 Complex Producers for more information.
    Figure 13-9 Producer Retrieved


    Producer Retrieved

  13. Click Register. The Register dialog appears.
  14. In the Register dialog, enter myProducer in the Producer Handle field, as shown in Figure 13-10, and click Register. The handle is stored on the consumer and is used to identify the producer.
  15. Figure 13-10 The Register Dialog


    The Register Dialog

  16. In the Portlet Wizard – Producer dialog, click Next. The Select Portlet from List dialog box appears.
  17. From the portlet list, select zipTest, as shown in Figure 13-11.
  18. Figure 13-11 Select Portlet from List Dialog Box


    Select Portlet from List Dialog Box

  19. Click Next. The Proxy Portlet Details dialog box appears, as shown in Figure 13-12.
  20. Figure 13-12 Proxy Portlet Details Dialog Box


    Proxy Portlet Details Dialog Box

  21. Click Create.
  22. The new portlet appears in the Editor, as shown in Figure 13-13.

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


    New Remote Portlet zipPrime.portlet in the Editor

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 Portlet Development Guide.
  1. In the Package Explorer tree, open the consumerProject folder, right-click the src folder, and create a new folder called backing.
  2. The src/backing folder appears in the Package Explorer, as shown in Figure 13-14.

    Tip: Alternatively, instead of a folder, you can create a Java package.
    Figure 13-14 backing Folder


    backing Folder

  3. Right-click the backing folder and select New > Class. The New Java Class dialog appears, as shown in Figure 13-15.
  4. Figure 13-15 New Java Class Dialog


    New Java Class Dialog

  5. In the Name field, enter CustomDataBacking and click Finish. The new Java source file appears in the editor.
  6. Replace the entire contents of the Java source file with the code in Listing 13-2.
  7. Listing 13-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;
    }
    }
  8. Save the file. The completed backing file is shown in Figure 13-16.
  9. Figure 13-16 CustomDataBacking.java in the Editor


    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.
  10. Double-click zipPrime.portlet to display it in the editor.
  11. 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:
  12. backing.CustomDataBacking

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

    Figure 13-17 Adding a Backing File


    Adding a Backing File

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.
  3. The portal is created and appears in the editor, as shown in Figure 13-18.

    Figure 13-18 zipTest.portal in the Editor


    zipTest.portal in the Editor

  4. 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 13-19, it is in the right-hand column).
  5. Figure 13-19 zipTest.portlet Added to zipTest.portal


    zipTest.portlet Added to zipTest.portal

  6. Save the portal.
  7. Run the portal. To do this, right-click zipTest.portal in the Package Explorer and select Run As > Run on Server.
  8. In the Run On Server – Define a New Server dialog, click Finish.
  9. The portal appears in the Workshop for WebLogic browser. The custom data sent from the consumer displays in the portlet, as shown in Figure 13-20.

    Figure 13-20 zipTest.portal Successfully Rendered


    zipTest.portal Successfully Rendered

Custom Data Transfer in a Simple Producer

The previous section, 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 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 Configuring a WebLogic Server Producer.
  2. Use the Custom Data Transfer interfaces listed in Custom Data Transfer Interfaces to set and retrieve data in request and response objects. Follow the same basic procedure described for complex producers in Custom Data Transfer with a Complex Producer.

 


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 Javadoc description.

Listing 13-3 shows sample code that uses XmlPayload.

Listing 13-3 XmlPayload Example
//-- Create an Element object to send. 
Element xml = ...

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

 


Deploying Your Own Interface Implementations

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

General Guidelines

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 Javadoc description.

Implementation Rules

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


  Back to Top       Previous  Next