Skip navigation.
Arch2Arch Tab BEA.com

Using Web Services with WebLogic Portal 8.1

by Alex Toussaint
01/28/2004

Introduction


By converging the development of Web services and portals, WebLogic Portal 8.1 and WebLogic Workshop 8.1 enable developers to connect quickly and expose Web services in their enterprise portals.

In this article, we will take you step by step through connecting to a Web service, creating a Java control that talks to that Web service, and exposing that service inside WebLogic Portal using Java Page Flow.

Selecting the Web Service


Most of the available public Web services provide a simple interface service that performs a single task, like telling you the weather for a particular zip code. There are also other services that expose a rich set of capabilities and are more complex. For this article, we will use the set of services available from Amazon.com. They provide a very complete set of Web services that developers can use to work with the Amazon.com systems. To get started you have to register with Amazon.com and download their Web services SDK. Follow the link below to download their SDK and register:

http://www.amazon.com/webservices

Next you have to apply for a token. This is a simple ID string that tells Amazon who you are and gives you access to their test Web services gateway for development purposes. The token will be required in order to make the example in this article work. Registration takes a few minutes and you will get an email with your token in seconds. Below is a link to request a token from Amazon.com

https://associates.amazon.com/exec/panama/associates/join/developer/application.html

Once you have the Amazon SDK and your token, we can start building a control and a portlet to expose the different services in a portal. For this example, we will be using WebLogic Portal 8.1 and WebLogic Workshop 8.1 for Microsoft Windows 2000 or XP.

Building a Java Control


For this example, we will be using the Sampleportal sample application available with WebLogic Portal 8.1. After the installation is completed, you should be able to access it by following this directory path in Windows Explorer:

<installation dir>\WebLogic81\samples\portal\portalApp\sampleportal

In order to get started, launch the WebLogic Workshop development environment. You can do this from the Start menu under the BEA WebLogic Platform 8.1 group, or just by double-clicking the WebLogic Workshop icon under:

<installation dir>\WebLogic81\workshop

Once WebLogic Workshop is running, we will need to open the portalApp.work file from:

<installation dir>\WebLogic81\samples\portal\portalApp

This is the application and project we will use to create the Java Control to interface with Amazon.com Web services.

Once you have the application open in WebLogic Workshop, you can follow the steps below to create our Java control:
  1. Inside the sampleportal root create a directory called "amazon."
  2. Drop a copy of the "AmazonWebServices.wsdl" file you received with the Amazon SDK inside the Amazon directory.

  3. 1

  4. From the WebLogic Workshop Application palette right click on the AmazonWebServices.wsdl file. Select the option to "Generate Service Control."

1

At this point WebLogic Workshop will use the. wsdl file to generate a Java control (.jcx file), with all the methods that are represented in the .wsdl file. This is done automatically for you. This saves a lot of time, prevents the confusion of dealing with the different Web services types, and creates continuity with the XML provided to work with these services.

1

The control provides a set of Java interfaces that can be called once the control is instantiated. Notice the collection of available methods available in the control window and set of parameters in the property editor. As you can see, in just a few minutes we were able to obtain a rich .wsdl file from Amazon.com and generate a Java control to expose Amazon's Web services inside our portal.

Building a Java Page Flow


Now we will create our initial front-end flow using Java page flows. From the application palette in WebLogic Workshop, right-click on the Java control file we just created and select the option to "Generate Page Flow." This will take you through a simple wizard with a few steps to name and select the method or methods to expose in our portal. Java page flow is a struts-based flow technology available with WebLogic Workshop and WebLogic Portal 8.1.

1

After you are done generating the page flow you should see a set of pages and actions like a standard struts application. The pages and actions will provide the presentation technology we need to interface with Java controls and therefore the Amazon Web services.

1

In order to take a closer look at what we have so far, flip to the source view of the recently created page flow. Check the different actions and the code involved. For this article, we made a few changes in order to provide a nicer look for the portlet. You can download the sample Java control and page flow zip file below and see how the example works in your portal. To use the provided sample, you will need to edit the sample page flow to include your developer token.

Building a Portlet


Once you have generated the Java control and the page flow, you are ready to include your work in the portal. Open the sampleportal.portal file and select the page or book in which you wish to display the Amazon portlet, then drag and drop your .jpf file in it. WebLogic Workshop will immediately ask you if you would like to create a portlet. Click "Yes" and a .portlet file representing your Amazon portlet will be created automatically. This portlet will also be available for other portals in the same Web application.

1

Next, we will render the portal and see our portlet in action. From WebLogic Workshop, you can start the WebLogic Server for the sampleportal. Go to Tools >> WebLogic Server >> Start WebLogic Server. This will fire up the portal domain located at:

<installation dir> WebLogic81\samples\domains\portal

After the server starts, you can open the existing portal from WebLogic Workshop. Go to Portal >> Open Existing Portal. A browser will be launched and you will see our sampleportal with the newly created portlet. At this point, you can click on the portlet and execute different searches with it.

1

a. Click on the action to search books.

1

b. Search for a book.

1

c. Display of results

Debugging Features


The last point to review is the debugging capabilities available in WebLogic Workshop for helping advanced development of Web Services, Java page flows, portals, JSPs, business processes and other resources.

You can easily step through your code and set break points in key areas to see the behavior of the portlet during execution. In the following screen shot, a break point was set right before execution of the Java page flow, which invokes the Web services via the Java control.

1

You can see the different threads running and the value of every variable in this particular context. Once the call gets executed and the Java control talks to the Amazon.com Web services, you can see the new values that were sent back from Amazon.com inside of the variable.

1

This example shows how debugging can help you during the development of complex portlets using Java Page Flows, Java Controls, and Web Services.

Summary


WebLogic Portal 8.1, along with WebLogic Workshop 8.1, provides the only environment that supports advanced Web Service and portal development to match the development needs of an enterprise. By leveraging WebLogic Workshop capabilities in these areas and new technologies such as Java page flows, you can quickly build and deploy new portal services.

Below are some related links you may find useful:

Getting started with portal development

A Tour Through WebLogic Workshop 8.1

Portal "How do I?"

Page Flows and Struts

WebLogic Workshop Java Controls

Download


Download the sample portlet, control, and page flow from this article: WS_WLP81.zip (21.9 KB)

Article Tools

Email E-mail
Print Print
Blog Blog

Related Products

Check out the products mentioned in this article:

Bookmark Article

del.icio.us del.icio.us
Digg Digg
DZone DZone
Furl Furl
Reddit Reddit