Skip navigation.

Using WSRP with WebLogic Portal

  Previous Next vertical dots separating previous/next from contents/index/pdf Contents View as PDF   Get Adobe Reader

Implementing Custom Data Transfer

Custom data transfer allows portlet developers to exchange arbitrary data between Producers and Consumers; for example,

Custom data transfer allows you to easily resolve these situations and many others like them. Both Simple Producers and Complex Producers can take advantage of this feature.

This section describes how to implement custom data transfer. It includes information on these subjects:

 


Custom Data Transfer Interfaces

Custom data transfer introduces the following "marker" interfaces:

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) is taking place.

com.bea.wsrp.ext.holders.InteractionResponseState

Allows the Producer to return some arbitrary data to the Consumer after an interaction took place.

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.

 


Implementing the Interfaces

The following example illustrates custom data transfer using com.bea.wsrp.ext.holders.SimpleStateHolder. This class provides a default implementation of the above interfaces. You can use this class to exchange simple name-value pairs of data.

Implementing Interfaces in a Complex Producer: Example

To send data, you need to create an instance of this instance and place it in the request as a request attribute. The Producer/Consumer then transmits that object across the wire and make it available as a request attribute on the other end.

In the following example, we are sending a zip code to a remote portlet.

Step 1: Set Up the Environment

Set up your environment by doing the following:

Note: For instructions on how to create the components required by the following steps, Step 1: Set Up Your Environment in chapter "Establishing Interportlet Communications with Remote Portlets".

  1. Either create a domain and a portal application or use an existing domain and portal application. If you are creating a new domain and portal application, name the domain custXferDomain and the application custXfer. Be sure to point the application at custXferDomain.
  2. Create two portal web applications under the portal application custXfer and name them Producer and Consumer, respectively.

Step 2: Create the Producer JSP and Portlet

With the environment in place, you will next create a JSP file on the Producer and a portlet to surface that file. This JSP file will get the state from the request. To do so, do the following:

Note: The following procedure assumes that WebLogic Workshop is running. If it isn't, launch it now.

  1. Right-click Producer in the application tree to open the context menu and select New>JSP File (Figure 6-1).
  2. Figure 6-1 Creating a New JSP File

    Creating a New JSP File


     

    The New File dialog box appears (Figure 6-2).

    Figure 6-2 New File Dialog Box for New JSP

    New File Dialog Box for New JSP


     
  3. In File name, enter zipTest.jsp and click Create.
  4. The default JSP file appears, in Design View, in the middle pane of WebLogic Workshop (Figure 6-3)

    Figure 6-3 Default JSP in Design View

    Default JSP in Design View


     
  5. Click Source View to display the JSP source (Figure 6-4).
  6. Figure 6-4 Default JSP in Source View

    Default JSP in Source View


     
  7. Copy the code in Table 6-1 and replace the contents of the JSP source with it.

  8.  

Listing 6-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%>

When complete, the Source View should look like that shown in Figure 6-5.

Figure 6-5 New JSP Source for zipTest.jsp

New JSP Source for zipTest.jsp


 
  1. Save the file.
  2. Right-click zipTest.jsp in the application tree and select Generate Portlet...
  3. The Portlet Details dialog box appears. Note that zipTest.jsp already appears in the Content URI field (Figure 6-6).

    Figure 6-6 Portlet Details with zipTest.jsp Included

    Portlet Details with zipTest.jsp Included


     
  4. In State, select Minimizable and Maximizable and click Finish.
  5. The portlet zipTest.portlet will be created and appear in the application tree (Figure 6-7).

    Figure 6-7 New JSP Portlet, zipTest.portlet, Added

    New JSP Portlet, zipTest.portlet, Added


     

Step 3: Federate zipTest.portlet to the Consumer

Next, you need to set up a remote portlet on the Consumer to surface in zipTest.portlet from the Producer. Use the following steps.

Note: Before you begin, start WebLogic Server by opening the tools file and selecting WebLogic Server>Start WebLogic Server.

  1. Right-click Consumer in the application tree and select New>Portlet.
  2. The New File dialog box appears.

  3. In File name, enter zipPrime.portlet and click Create.
  4. The Select Portlet Type dialog box appears (Figure 6-8).

    Figure 6-8 Select Portlet Type Dialog Box

    Select Portlet Type Dialog Box


     
  5. Select Remote Portlet and click Next.
  6. The Find/Select Producer dialog box appears (Figure 6-9).

    Figure 6-9 Find/Select Producer Dialog Box

    Find/Select Producer Dialog Box


     
  7. Select Find Producer and, in the field provided, enter:
  8. http://localhost:7001/Producer/producer?WSDL

    and click Retrieve.

    After a few moments, the Find/Select Producer dialog box refreshes, displaying the Producer details, as shown in

    Figure 6-10 Producer Retrieved

    Producer Retrieved


     
  9. Click Register.
  10. The Register dialog box appears (Figure 6-11).

    Figure 6-11 Register Dialog Box

    Register Dialog Box


     
  11. In Producer Handle, enter BEA and leave the other fields blank.
  12. Click Register.
  13. The Find/Select Producer dialog box reappears with BEA in the Select Producer field.

  14. Click Next.
  15. The Select Portlet from List dialog box appears (Figure 6-12).

    Figure 6-12 Select Portlet from List Dialog Box

    Select Portlet from List Dialog Box


     
  16. Select zipTest and click Next.
  17. The Proxy Portlet Details dialog box appears (Figure 6-13).

    Figure 6-13 Proxy Portlet Details Dialog Box

    Proxy Portlet Details Dialog Box


     
  18. Click Finish.
  19. The Proxy Portlet Details dialog box closes and WebLogic Workshop reappears, showing the design view of the new portlet (Figure 6-14).

    Figure 6-14 New Remote Portlet zipPrime.portlet in Design View

    New Remote Portlet zipPrime.portlet in Design View


     
  20. If necessary, save the file.

Step 4: Create and Attach a Backing File to the Consumer

In this step, you will create a backing file called CustomDataBacking.java on the Consumer side and attach that backing file you created in Step 3: Federate zipTest.portlet to the Consumer. Use the following procedure:

  1. Expand the Consumer node to show WEB-INF/src and right-click it to open the context menu, and select New>Folder, as shown in Figure 6-15.
  2. Figure 6-15 Creating a New Folder in WEB-INF/src

    Creating a New Folder in WEB-INF/src


     

    The Create New Folder dialog box appears (Figure 6-16).

    Figure 6-16 Create New Folder Dialog Box

    Create New Folder Dialog Box


     
  3. In Enter new folder name, type backing and click OK.
  4. The backing folder will appear in the application tree under WEB-INF/src, as shown in Figure 6-17.

    Figure 6-17 backing Folder Under WEB-INF/src

    backing Folder Under WEB-INF/src


     
  5. Right-click backing to open the context menu and select New>Java Class (Figure 6-18).
  6. Figure 6-18 Creating a New Java Class

    Creating a New Java Class


     

    The New File dialog box appears.

  7. In File name, enter CustomDataBacking.java and click Create.
  8. A backing file template opens in WebLogic Workshop (Figure 6-19).

    Figure 6-19 Backing File Template

    Backing File Template


     
  9. Copy the code in Table 6-2 into the template and save the file.

  10.  

Listing 6-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
{
   public boolean preRender(HttpServletRequest request, 
HttpServletResponse response)
{
SimpleStateHolder state = new SimpleStateHolder();
state.addParameter("zipCode", "80501");
request.setAttribute(MarkupRequestState.KEY, state);
      return true;
}
}

The template should now look like the example in Figure 6-20.

Figure 6-20 CustomDataBacking.java in WebLogic Workshop

CustomDataBacking.java in WebLogic Workshop


 
  1. Double-click zipPrime.portlet to display it in WebLogic Workshop.
  2. Add the backing file to zipPrime.portlet by typing backing.CustomDataBacking in the Backing File field in the Property Editor, as illustrated in Figure 6-21 and press Tab.
  3. Figure 6-21 Adding a Backing File

     Adding a Backing File


     

Step 5: Test the Application

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

To test the application, do the following:

  1. Right-click Consumer in the application tree to open the context menu and select New>Portal.
  2. The New File dialog box appears.

  3. In File name, enter zipTest.portal and click Create.
  4. The portal is created and appears in the WebLogic Workshop design view (Figure 6-22).

    Figure 6-22 zipTest.portal in WebLogic Workshop Design View

    zipTest.portal in WebLogic Workshop Design View


     

  1. Drag zipTest from the data palette into the portal (you can place it in either placeholder; in Figure 6-23, it is in the right-hand placeholder).
  2. Figure 6-23 zipTest.portlet Added to zipTest.portal

    zipTest.portlet Added to zipTest.portal


     
  3. Save the portal.
  4. Open the Portal menu and select Open Current Portal.
  5. A browser opens, displaying the portal (this might take a few moments). Note the zip code 80501 appearing in the portlet (Figure 6-24).

    Figure 6-24 zipTest.portal Successfully Rendered

    zipTest.portal Successfully Rendered


     

Using this Example in a Simple Producer

The procedure described in Implementing Interfaces in a Complex Producer: Example applies only to complex producers. If you want to use the preceding example in a simple producer, you must make a few modifications. To implement the interfaces in a simple Producer, use this procedure:

  1. In the application custXfer, create a new project; however, instead of a Portal Web Project, make this project a simple Web Project and call it simpleProducer. See Step 1: Set Up the Environment for instructions.
  2. Right-click simpleProducer in the application tree to open the context menu and select Install>WSRP Producer (Figure 6-25.
  3. Figure 6-25 Installing a WSRP Producer

    Installing a WSRP Producer


     

    The application tree will update and show wsrp-producer-config.xml under the simpleProducer/WEB-INF directory.

  4. In simpleProducer create a Java Page Flow by doing the following:
    1. Right-click simpleProducer to open the context menu and select New>Page Flow.
    2. The Page Flow Wizard - Page Flow Name dialog box appears (Figure 6-26).

      Figure 6-26 Page Flow Wizard - Page Flow Name Dialog Box

      Page Flow Wizard - Page Flow Name Dialog Box


       
    3. In Page Flow Name, enter ZipTestPF. Note that Controller Name becomes zipTestController.jpf.
    4. Click Next.
    5. The Page Flow Wizard - Select Page Flow Type dialog box appears (Figure 6-27).

      Figure 6-27 Page Flow Wizard - Select Page Flow Type Dialog Box

      Page Flow Wizard - Select Page Flow Type Dialog Box


       
    6. Select Basic page flow and click Create.
    7. WebLogic Workshop reappears, showing the basic page flow in the Flow View (Figure 6-28).

      Figure 6-28 Basic Page Flow in Flow View

      Basic Page Flow in Flow View


       

    Note that the page flow now includes the file index.jsp.

  5. Double-click the index.jsp icon.
  6. index.jsp opens in the Design View.

  7. Click Source View to display the index.jsp source (Figure 6-29).
  8. Figure 6-29 index.jsp Source View

    index.jsp Source View


     
  9. Copy the code in Listing 6-3 into index.jsp, overwriting its entire default content.

  10.  

Listing 6-3 Using a Page Flow Portlet for a Simple Producer

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

The Source View for index.jsp should now look like Figure 6-30.

Figure 6-30 Updated index.jsp in WebLogic Workshop

Updated index.jsp in WebLogic Workshop


 
  1. Save the file.
  2. Right-click ZipTestPFController.jpf in the application tree to open the context menu and select Generate Portlet...
  3. The Portlet Details dialog box appears (Figure 6-31).

    Figure 6-31 Portlet Details for a JPF Portlet

    Portlet Details for a JPF Portlet


     

    Note that /zipTestPF/ZipTestPFController.jpf has already been entered in the Content URI field.

  4. Select Minimizable and Maximizable and click Finish.
  5. The portlet is created; note that ZipTestPFController.portlet now appears under simpleProducerWeb/WEB-INF(Figure 6-32).

    Figure 6-32 ZipTestPFController Added to Application Tree

    ZipTestPFController Added to Application Tree


     
  6. Federate ZipTestPFController.portlet to the Consumer portal web application following the steps specified above in Step 3: Federate zipTest.portlet to the Consumer. Make the following changes within the procedure:
  7. Note: Ensure that WebLogic Server is running.

  8. Attach the backing file CustomDataBacking.java by typing backing.CustomDataBacking in the Backing File field in the Property Editor. Press Tab.
  9. Save the portlet file.
  10. Test the application by doing the following:
    1. Under the Consumer web application, open zipTest.portal.
    2. Drag ZipTestPFController.portlet from the Data Palette to zipTest.portal.
    3. Save the portal file.
    4. Open the Portal menu and select Open Current Portal.
    5. A browser will open and, after a few moments, the portal will appear, showing the zip code 80501, as shown in (Figure 6-33).

      Figure 6-33 zipTest.portal in a Browser

      zipTest.portal in a Browser


       

Deploying Your Own Interface Implementations

If you want to deploy your own implementations of these interfaces, consider the following practices:

Implementation Rules

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

 

Skip navigation bar  Back to Top Previous Next