LDD Today

Using the Lotus Workflow Java API in Domino and WebSphere


by JoAnn Jordan
and Seol Young Park

Level: Advanced
Works with: Lotus Workflow, Domino, WebSphere
Updated: 02-Dec-2002

Lotus Workflow offers more than 50 LotusScript API functions to provide developers a basic set of functionality for building customized applications. In addition, Lotus Workflow 3.0 introduced JavaScript and Java APIs to help support Web applications.

You can use the Java API to integrate Lotus Workflow beyond its "out of the box" capabilities, for example, running workflow processes on a WebSphere server.

This article describes the Lotus Workflow Java API. We begin with a brief introduction to its functions, then explain how to configure Domino and WebSphere to run them. We conclude by explaining how you can use our Lotus Workflow Java API demo with the sample application that ships with Lotus Workflow to create your own applications. This demo includes a custom Purchase Order process that incorporates the Lotus Workflow Java API. This process can run in both Domino and WebSphere. (Our demo replaces the previous LWF Java API demo.) You can download our demo from the Sandbox.

This article assumes that you're an experienced Java programmer and are familiar with Lotus Workflow features and terminology. We also assume that you are familiar with the Domino Designer and WebSphere environments, especially WebSphere Application Server and WebSphere Studio Application Developer.

What is the Lotus Workflow Java API?
The Lotus Workflow Java API is an application programming interface you can use to build JavaServer Pages (JSPs) and servlets. This API lets you easily integrate people-centric processes into e-commerce applications. The objects in the Lotus Workflow API are almost identical to the objects found in Lotus Workflow.

The Java API supports n-tier architecture for e-business solutions. (N-tier architecture is a programming technique that extends the traditional client/server 2-tier architecture. For example, an application can use a 3-tier architecture in which different parts of its code run on the client, the application server, and the data server.) The following diagram shows how the Java API fits into n-tier architecture. The presentation layer (JSPs and servlets) is shown outside the firewall; within the firewall are the application logic (including the process definition) and Workflow data (residing in Domino, DB2, and other database management systems).

Lotus Workflow Java API architecture


The Lotus Workflow Java API is implemented as a set of Java Beans designed to run on multiple platforms, including the WebSphere Application Server (WAS). It can be considered a wrapper on top of Lotus Workflow and Java beans that call Notes agents, and it can access views and fields in Notes documents. With the Lotus Workflow Java API for WebSphere, you can combine the strengths of IBM WebSphere and Lotus Domino using servlets and JSPs. You can also access Domino and Lotus Workflow services to extend workflow functionality to areas such as organization information (via the Domino Directory and Lotus Workflow Organization Directory) and automation (including mail notification).

The Lotus Workflow Java API is based on the Object Management Group (OMG) standards Lotus has mapped to Java interfaces. Where necessary, Lotus has extended the OMG standard to enhance functionality. Extended objects use the naming convention, ExtendedXXXX, for example, ExtendedDocument object. (For more information, refer to the OMG Workflow Management Facility Specification.)

The objects in the Lotus Workflow Java API are almost identical to the objects found in Lotus Workflow. All Lotus Workflow API objects adhere to the OMG specification naming conventions where possible. Wherever objects needed to be extended, they were extended and given the names ExtendedXXX. The following table outlines this relationship:

OMG TerminologyLotus Workflow Terminology
ExtendedActivityAccessBeanLWF ActivityInstance
ExtendedProcessAccessBeanLWF Job
ExecutionObjectAccessBeanNo equivalent object in LWF
ProcessManagerAccessBeanLWF Process
WorklistHandlerAccessBeanLWF WorklistHandler
BinderAccessBeanLWF Binder
ExtendedDocumentAccessBeanLWF Document
ResourceAccessBeanLWF User
AssignmentAccessBeanNo object in LWF for this object

For more information, refer to the Lotus Workflow Application Programming Interface (API) Reference.

Configuring Domino and WebSphere for the Lotus Workflow Java API
The Lotus Workflow Java APIs take advantage of the document management capabilities of Domino, as well as the scalability of the WebSphere Application Server. To deploy the Workflow Java APIs, you must first install both Domino and WebSphere and configure Single Sign On (SSO) for both. You must also enable DIIOP in Domino. This section explains how to do this and offers links to more detailed information.

Our example has been configured and tested to work with:
Later releases of these products should also work.

Single Sign On (SSO)
The Lotus Workflow Java APIs use an LTPA token generated by authenticating with Single Sign On (SSO). LTPA (Lightweight Third Party Authentication) is an IBM technology that uses tokens to represent users' credentials. (See the IBM WebSphere Security Overview for a description of LTPA.) SSO works by placing the LTPA token on the user's PC after the user successfully authenticates. Other servlets, JSPs, and Notes databases can then use this token to obtain the user's credentials. This allows a Web user to move from one application to another without being prompted repeatedly for user name and password.

The requirements for enabling SSO are:
In the following sections, we describe how to enable SSO in both WebSphere Advanced Server and Domino. For more information about WebSphere/Domino security and SSO, consult the IBM Redbook Domino and WebSphere Together.

Configuring SSO in WebSphere
SSO in the WebSphere Application Server is configured from the WAS Administrator's Console in the Security Center:

WAS Security Center


Before beginning the following procedure to configure SSO in WebSphere, make sure both Domino and the LDAP task are running. You also need to specify information about your Domino server and generate an LTPA key which you'll need for setting up SSO in Domino.
Configuring SSO in Domino
Follow these steps to configure SSO in Domino:
Your SSO Configuration document should look as follows:

Configuring SSO in Domino


Verify that your SSO is configured correctly and working by opening a secure site in both WebSphere and Domino. You should be prompted only once for your user credentials.

Configuring the DIIOP task in Domino
The Java APIs require that the DIIOP task be running on Domino and that users initiating the workflow processes have rights to run restricted Java agents. These steps are described below:
Configuring the Lotus Workflow Java API demo
Our Lotus Workflow Java API demo is based on the Purchase Order process that comes with Lotus Workflow. We customized this process with the Lotus Workflow Java API, to allow it to run on both Domino and WebSphere. The process has all the features as the standard Purchase Order, although we have customized the UI to ensure it functions consistently on all platforms.

The Lotus Workflow Java API demo (LWFJavaAPIDemo.zip) can be downloaded from the Sandbox. This demo consists of two files:
Configuring the Request for Quote process (optional)
In addition to the Purchase Order process, our demo includes the forms and the process for the Request for Quote (RFQ) process from the previous Java API demo. If you want to run the RFQ process, you must copy the necessary forms from our Lotus Workflow Java API demo, and paste them into the Lotus Workflow Sample application database that comes with the product. To do this, perform the following steps. (If you only want to use our sample Purchase Order process, skip this procedure.)
Before continuing, verify that you can start both the Purchase Order and RFQ processes in the Start New Job box.

Importing LWFJavaAPIDemo.ear into WebSphere Application Server
After you extract the Enterprise Application file LWFJavaAPIDemo.ear from LWFJavaAPIDemo.zip, you must import it into your WebSphere Application Server (WAS). To do this:
After you install LWFJavaAPIDemo.ear on your WAS server, go to a secure database (for example, the Domino Directory database on your Domino server). This authenticates your first SSO token. Then go to http://<yourserver.xxx.yyy>/Demo/Pages/home.html to start the demo.

Using our Java API demo code
In this section, we use WebSphere Studio Application Developer (WSAD) to run and examine our demo code. This will help you understand how our code works, so you can customize it to your own needs. Let's start by looking inside our demo. The flow is simple:
We will examine the custom codes step-by-step. But first, you must import LWFJavaAPIDemo.ear into WSAD:
The remainder of this section is presented as a series of seven main steps:
Each of these steps has its own subsection.

Step1: Modify the CustomConstants.java file
Before you can use our demo, you must edit its CustomConstants.java file to include the server name and the replica ID of your Lotus Workflow application database. (By default, the replica ID is the same as the Lotus Workflow Sample Application database.) To do this:
Editing CustomConstants.java screen


Step 2: Generate the LTPA token for SSO and run the application
WSAD comes equipped with a full WebSphere test environment. However, this test environment does not support SSO and therefore, can't generate LTPA keys or tokens. To do this, you must first navigate to a secure site. This creates an LTPA token on your machine, which the Java APIs need for authentication. To do this:
Generate LTPA token screen


Step 3: Creating a Purchase Order
Now that you (finally) have your demo application up and running, let's take a look at it in action. To begin, click Purchase Order. This displays the following screen:

Lotus Workflow Purchase Order form

Internally, clicking Purchase Order starts CommandServlet, using the following line of code:

<A href="/Demo/CommandServlet?COMMAND=POCREATESTARTCLAIM&NEWPROCESSNAME=Purchase Order">Purchase Order</A>

This code passes parameters to CommandServlet, including which command to run, and the process name with which to create a job. CommandServlet calls the PO_createAndStartProcessAndClaimFirstActivity method to create a job and to return to the page Purchase_Request.jsp. You can also pass the new name for the job created via URL by modifying the <A> link tag. For example:

<A href="/Demo/CommandServlet?COMMAND=POCREATESTARTCLAIM&NEWPROCESSNAME=Purchase Order&NEWJOBNAME=xxxxxxxx">Purchase Order</A>

If you don't explicitly specify a job name, the code creates a random job name using the current date/time:

public void PO_createAndStartProcessAndClaimFirstActivity(HttpServletRequest request,HttpServletResponse response) }

Note the fieldsToSave parameter. This parameter is a Hashtable with field names and value pairs. If it has the entry DocumentKey, its value is used as the UNID of a document in the application database, as well as the main document in the binder. The Priority argument determines the process's priority.

Step 4. Define JSPs to display
There are several ways to define which JSP to use to present the document in a page:
Advanced Process Properties



With all of these methods, the order of the definitions is important. The two methods which return the JSP name, ExtendedDocumentAccessBean.getJSP(), and BinderAccessBean.getDocuments("SELECT JSP", -1), first check the JSPOS field, then the mapping, and finally the form name.

Step 5: Viewing the workflow activities
ActivityList.jsp in our demo demonstrates how to display jobs in a page. First, we get the WorklistHandlerAccessBean with the WorklistHandlerKey, which has the format <ServerName>#<ReplicaIDOfAppDB>. Then we retrieve information from the WorklistHandlerAccessBean using an SQL-like query language. The following example shows how to get either activities in progress or new activities.

<% %>

Result sets are returned as a non-null java.util.Vector, and its elements are instances of java.lang.String. If an error occurs (for example, the wrong syntax in the query statement), null is returned.

The strings have the following characteristics:
After we get the results, we now parse the string returned by the query shown above in the format Activity Key | Name | Description | Activity status | Activity Owner(s) | Due date. We then save this to the array Token to display. The first token (Activity Key) is used as a link to open the actual activity.

for (Enumeration e = ownedActivities.elements(); e.hasMoreElements();) { }

After the code runs, the following screen appears:

Lotus Workflow API for WebSphere - Personal Worklist


Step 6: Opening an activity
The ActivityList.jsp generates a link to open each activity. For instance:

<A href="/Demo/CommandServlet?COMMAND=OPENACTIVITY&ACTIVITY=ExtendedActivity%23tjfdud%.........." target="contentF">Check Account</A>.

When you click an activity link, the openActivity method in the CommandServlet executes and passes the activity and document objects to the session. This information is used in the DisplayActivity.jsp.

public void openActivity(HttpServletRequest request, HttpServletResponse response) {
In the DisplayActivity.jsp, we use the useBean tag to access the activity and the name of the document passed and use this information in the JSP codes:

<jsp:useBean id="document" type="com.ibm.websphere.workflow.ExtendedDocumentAccessBean" scope="session"></jsp:useBean>
<jsp:useBean id="activity" type="com.ibm.websphere.workflow.ExtendedActivityAccessBean" scope="session"></jsp:useBean>

Using the <jsp:include page="<%= document.getJSP() %>" ...> line, we display the rest of the page with the JSP returned.

Step 7: Completing or claiming activities
The following code provides context-sensitive links or buttons to complete or claim an activity. It checks the status of the activity first and generates the button to complete it on-the-fly. When a user clicks the Complete button to submit a document, CommandServlet executes the PO_SaveAndComplete method:

<% if (activityState.equalsIgnoreCase("OPEN.RUNNING")) { %>
<INPUT type="submit" name="Complete" value="Complete">
<INPUT type="hidden" name="COMMAND" value="POSAVECOMPLETE">
<% } %>

public void PO_saveAndComplete(HttpServletRequest request,HttpServletResponse response) {
You also can design decision and/or routing options before completing or claiming. To do this, get the ExtendedDocumentAccessBean object and setDecision method before calling activity.claim() or activity.complete():

activity.setDecision("Decision",request.getParameter("Decision"));

To enable/disable decision/routing options, add the following code to your JSP:

<% if (activityName.equalsIgnoreCase("Options")&& activity.getState().equalsIgnoreCase("OPEN.RUNNING")) {%>
<INPUT type="radio" name="Decision" value="Multiple Source">Multiple Source active<BR>
<INPUT type="radio" name="Decision" value="Single Source">Single Source<BR>
<% } else if(activityName.equalsIgnoreCase("Options")) {%>
<INPUT type="radio" name="Decision" value="Multiple Source" disabled>Multiple Source disable<BR>
<INPUT type="radio" name="Decision" value="Single Source" disabled>Single Source<BR>
<%}%>

Building Web applications with the power of Lotus Workflow
We've shown how you can use Lotus Workflow Java API in WebSphere and Domino. Our goal is to give you an indication of how easily you can integrate the power of Lotus Workflow into your Web-based e-business solutions. Give it a try!


ABOUT JOANN JORDAN
JoAnn Jordan joined Lotus/IBM in 1996 and has been a member of the Lotus Workflow quality assurance team since 2000. Previously, JoAnn worked on products such as Lotus Smart Suite and Freelance Graphics.

ABOUT SEOL YOUNG PARK
Seol Young Park joined Lotus/IBM in 1994. She's been a member of the Lotus Workflow team since 1999, serving as a developer for the Lotus Workflow Engine. Previously, Seol Young worked on multiple projects for the International Product Development team.