Skip navigation.
Arch2Arch Tab BEA.com

Deploying Java Portlets with WebLogic Portal 8.1 SP3

by Alex Toussaint
09/21/2004

Java portlets are built based on the JSR 168 portlet standard. Sometimes they are packaged and made available to developers in Web Application Archive (WAR) files. This article describes how to use JSR 168 portlets distributed in a WAR file.
Download the author's files associated with this article


Starting with WebLogic Portal 8.1 SP3, there are two new ways to make portlets that are packaged in a WAR file available in the portal. You can either integrate the portlets into an existing Portal Web application or you may choose to keep the portlets in a separate Web application. We will make use of the Portlet Preparer Tool and Web services for Remote Portlets (WSRP) to showcase the two approaches. You should select the approach that best match your needs:
  • Single WAR file - Uses the portlet preparer tool to integrate the content of the WAR into an existing project. If you are using a small set of third party portlets and your Portal project, this approach may be best for you.
  • Multiple WAR files - Uses WSRP to keep portlets in a separate WAR and reference them from the destination Portal project. If you have a very large project with several third party portlets you may want to consider using this approach.
We will discuss these two approaches in detail below.

Single WAR File - Using the Portlet Preparer Tool
The Portlet Preparer Tool is available as a utility from dev2dev at:
http://dev2dev.bea.com/codelibrary/code/portletpreparer.jsp

The tool creates.portlet files out of JSR168 portlets contained in the WAR file, thereby allowing WebLogic Workshop to import the contents of that file into a Portal Web project. The steps to run the preparer tool are simple and straightforward. There are two options to consider:

  • Adding portlets to a new project
  • Adding portlets to an existing portal project

Below are the steps for each scenario:

Adding Portlets to a New Project
To import a WAR file containing JSR168 portlets, complete the following steps:

  1. Extract portletConverter.jar to a temporary location on your hard drive (In the following instructions this directory will be called <converter-root>).
  2. Place your WAR file in <converter-root>.
  3. Set the WEBLOGIC_HOME in env.sh or env.bat (depending on your platform).
  4. run env.sh or env.bat (depending on your platform).
  5. run ant -Dwar.file= (where <war-file-name> is the name of the WAR file).
  6. A directory called tempDir under <converter-root> is created.
  7. Open WebLogic Workshop and import the tempDir as a portal Web project.

Adding Portlets to an Existing Portal Project
To add portlets to an existing portal Web application, complete the following steps:

  1. Complete steps 1-7 above.
  2. Copy any necessary classes to the WEB-INF\classes directory and the necessary jars to the WEB-INF\lib directory.
  3. Make necessary changes to the web.xml (example: servlet definitions).
  4. Add elements to the portlet.xml for each portlet added (these can be copied from the portlet.xml in the tempDir created above).
  5. Copy the .portlet files from tempDir\portlets to your Web application
  6. Add the portlets to your portal.

Multiple WAR files: Using Web Services for Remote Portlets (WSRP)

Using WSRP you can deploy Java portlets in a separate Web application and reference them from your Portal project. For more details on how WSRP works please visit the links below and download WebLogic Portal 8.1 SP3:


Below is a scenario where the SamplePortal is the main portal from which you create references to portlets in other WARs. This allows you to surface portlets from different WAR files into the SamplePortal.

  1. Create a new Portal project, separate from your portal, and follow steps 1-7 from the above section "Adding portlets to a new project".
  2. Launch the Portal samples domain and login to the Administration Portal under: http://localhost:7001/portalAppAdmin .
  3. Under the Portals tab, click on the Library which is on the left hand side.
  4. After the tree expands, click on the Portlet Producers icon.
  5. Once the producer resources panel shows up on the right side, click on the "Browse/Add Producers" tab.
  6. Under the "Enter Producer to Browse" box, enter: http://localhost:7001/<new portlet war file>/producer?wsdl . Click "OK".
  7. At this point you should see a list of producer's properties including available portlets. Click "Add Producer" and fill in the registration fields.
  8. After registering, you will be at the "Available Producers" window. From the "Available Producers" box, click the "Register" button. On the dialog box, click "Save".
  9. Click the producer that you registered and pick the portlet(s) you want to reference from your portal.


At this point you can click on "All Portlets" in the library tree and you should see the remote portlet you just added. There is also a convenient portlet category, "All Remote Portlets," created under the "Category" drop-down menu in the "Available Portlets" box. Now you can add the remote portlet to a page and make them available to users.

In this scenario the SamplePortal will be playing consumer role while your other Web applications will be playing producer role.

Making the Pluto Test Suite Portlets available in the SamplePortal
Below is an example to highlight the use of portlets in multiple WAR files. The basic idea is to have a set of portlets available in one Web application and allow for the WebLogic Portal in another Web application to make use of these portlets.

In the example below we downloaded the Pluto test portlets (JSR 168 - test suite) from Apache. Next, we created a new Web application, used the portlet tool to import the WAR file, and finally used WSRP to make them available in the Portal Web application.

  1. Download the latest Pluto test suite portlets from Apache. (For your convenience we have attached a copy with this article)
  2. Use the Portlet Tool to make the war ready for import by the WebLogic Workshop

    1

    Note that the .portlet files have been created for you and the WAR is ready to be imported.
  3. Perform the import step of the WAR file as a portal project in order to get 168 support. You can do that by clicking the import option from your application inside the Workshop.

1

Edit the portlet.tld file to point to the BEA implementation of the JSR 168 standard. (For your convenience we have attached a copy with this article)

At this point you have created a new Web application and imported your 168 portlets. Now let's make them available in another Web application. This example uses the SamplePortal Web application. There are two ways to bring these portlets into the SamplePortal. From Workshop you can use the portlet wizard and create a reference to the newly created Web application, or from the administration portal you can also create a reference.

The following steps will use the administration portal. Be sure to have a portal and desktop created. In this example portal "P1" and a desktop "D1" were created with the SamplePortal template.
  1. Login to the administration portal
  2. Add a new page to the SamplePortal and called Pluto Test
  3. Go to the Library, select portlet producers and do an add new producer
  4. Enter the URL: http://localhost:7001/<new_web_app>/producer?wsdl
  5. Perform the add of the producer and the registration
  6. Go back and pick the portlet you want to add. For this example pick the "Test Portlet #1" which is part of the Pluto Test suite.

    1

  7. Go to your desktop "D1" and select to add a portlet, pick "Test Portlet #1"

When you launch the desktop you should see a new page called "Pluto Test" and inside the page you should see the "Test Portlet #1" from the Pluto test suite which is located on a separate Web application.

1

Note: The SamplePortal is located inside the sampleportal Web application and that the Pluto Test Suite Portlets are located inside the new Pluto Web application we created.

Other Considerations
One consideration that may reduce deployment time is to use a scale down version of the Portal project. You can create your own project that only includes support for JSR 168 and no other services. Tags related to the portal content management services, Java pages flows, and other non-168 services could be removed.

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