Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Implementing a workflow using design patterns with WebSphere Process Choreographer, Part 1

Fred Simmons (fredsid@us.ibm.com), Consultant, Software Services for WebSphere, IBM
<b>Fred Simmons</b> is a consultant for IBM Software Services for WebSphere in Research Triangle Park, North Carolina. You can contact Fred at <a href="mailto:fredsid@us.ibm.com">fredsid@us.ibm.com</a>.
Jeng Yoong Tan (jtan@us.ibm.com), Consultant, Software Services for WebSphere, IBM
<b>Jeng Yoong Tan</b> is a consultant with IBM Software Services for WebSphere in Research Triangle Park, North Carolina. Jeng has received extensive dinosaur training from his son, Nicholas Tan. You can contact Jeng at <a href="mailto:jtan@us.ibm.com">jtan@us.ibm.com</a>.

Summary:  This article shows how to build and test a business process that contains several basic activities. This business process will call a simple Web service to accomplish some of the activities.

Date:  10 Aug 2005
Level:  Intermediate

Activity:  7573 views
Comments:  

Introduction

This article will give you a basic knowledge of workflow and show you how to implement it using IBM® WebSphere® Process Choreographer, which is a component of WebSphere Studio Application Developer Integration Edition V5.1. The article will also show you how to integrate a Process Choreographer workflow with a Web service.

Prerequisites

To run the examples in this article, you will need WebSphere Studio Application Developer Integration Edition V5.1 (hereafter called Application Developer), with the latest software updates installed.


ChocoDino, Inc.
The Choco-Triceratops

In 1989, Kwesi Gadzi and his family emigrated from Ghana to Brooklyn, New York. After spending ten years as a programmer he decided to start his own business. Kwesi noticed that his children liked chocolate. They liked dinosaurs. So he started a company, ChocoDino, Inc., that manufactured and sold chocolates shaped like dinosaurs. He now sells four different types of chocolate dinosaurs:

  • Choco-Triceratops,
  • White Chocolate Ankylosaurus
  • Cherry Chocolate Pterosaurs
  • Braciosaurs Brownie (everyone's favorite)

As ChocoDino, Inc, grew, Kwesi decided that he needed an ordering process for his chocolates. You will implement this business process for him using WebSphere Process Choreographer.

What you will learn

At the end of this article, you should be able to use WebSphere Process Choreographer to:

  • Create a simple chocolate dinosaur ordering process using the Services and Business Process wizards.
  • Add Receive, Reply, Assign, Invoke, and Switch Activities to a chocolate dinosaur business process.
  • Understand how to include a child business process as part of a parent business process.
  • Include Web services as part of the chocolate dinosaur business process.
  • Configure and use a Staff Activity which will let Kwesi interact with your business process.
  • Feel comfortable navigating through the Business Process Editor and Perspective using Application Developer.
  • Identify the various design patterns throughout the development of the ChocoDino business process.

Overview: ChocoDino order process

Business Process Execution Language for Web Services (BPEL4WS) is a language for specifying the behavior of business processes. BPEL4WS expands the Web services interaction model and enables it to support business transactions. WebSphere Process Choreographer implements the BPEL4WS standard and offers important additions such as Staff Activity and Java Snippet. A Staff Activity allows human interaction with your workflow, while a Java Snippet lets you add Java code to your business process.

All variables, partner links, and activities in this article begin with at capital letter. Assignment activities used for setup begin with a lowercase letter. While this convention is not a standard, it's a good practice because it highlights the relevant business activities.

In this article, you will use BPEL4WS to build a Chocolate Dinosaur Order Process using Application Developer. This process will accept an order for chocolate dinosaurs as input. A Chocolate Dinosaur Order consists of a customer number, an item number corresponding to one of the four chocolate dinosaur types, a unique order identifier, and the quantity of chocolate dinosaurs. The business process will process the order by performing the following tasks:

  • Attempt to fulfill the order for chocolate dinosaurs.
  • If the order is fulfilled, ship the chocolate dinosaurs and bill the customer.

The output of this process will be an order-completed status flag set to true or false and a comment regarding order status. At the end of the article you will have built the main Chocolate Dinosaur Order Process and its child Fulfill Chocolate Dinosaur Order Process. They are represented in the following diagrams:

Chocolate Dinosaur
Order Process
Fulfill Chocolate Dinosaur
Order Process
Chocolate Dinosaur Order Process Fulfill Chocolate Dinosaur Order Process

Setting up your environment

Set up Application Developer

Launch Application Developer. From the Start menu, select Programs => IBM WebSphere Studio => Application Developer Integration Edition. A dialog box will open, where you can select where you want the workspace directory to be stored. Enter <drive_letter>\chocodino\workspace for the location and click OK. Application Developer will start with an empty workspace.

Now you must enable server targeting support. Select Window => Preferences and click on J2EE in the navigation frame of the window that opens, then select Enable server targeting support and click OK.


Figure 1. Enable server targeting support
Enable server targeting support.

In the Tasks view, click Filters Filters. Select On selected resource and its children, which will limit the messages displayed in the Tasks view to the ones pertinent to your component.


Figure 2. On selected resource and its children
On selected resource and its children.

Create a new Service Project

In the Services View, right-click on Service Projects and select New => Service Project. Use the Project name ChocoDino, and leave the defaults (project location) as-is. Click Finish.


Figure 3. Create a new project named ChocoDino
Create a new project named ChocoDino.

Creating the initial business process

Create a new sequential business process

You will build the ProcessChocoDinoOrder process containing the three main steps as defined in the Overview:

  1. Track the fulfillment of the order for chocolate dinosaurs until the order is fulfilled.
  2. Ship the order of chocolate dinosaurs.
  3. Bill the customer.

Right-click on ChocoDino project and select New => Business Process. Enter com.chocodino.process for Package. Enter ProcessChocoDinoOrder> for File name. Click Next.


Figure 4. Create a new ProcessChocoDinoOrder
Create a new ProcessChocoDinoOrder.

Create a sequence-based process

The two types of business processes used in this project will be sequence and flow based. The ProcessChocoDinoOrder is a Sequence-based BPEL Process. Click Finish. The ProcessChocoDinoOrder.bpel business process will open up in the Process Editor.


Figure 5. Sequence based Process
ProcessChocoDinoOrder is a Sequence based Process.

Configure the service interface

You must define the process interface for your business process. This is the service interface for others to interact with this process. Create a new Port Type for the process.

In the Services view, double click the ProcessChocoDinoOrderInterface.wsdl file to open it. Under Port Types, right-click and select Add Child => Port Type.

Name the port ProcessOrderPortType

Enter ProcessOrderPortType for the Name and click OK.

Select the ProcessOrderPortType port type that you just created. Right-click and select Add Child => Operation. Enter processOrder and click OK.

Create the processOrderRequest message

Select the processOrder operation. Right-click and select Add Child => Input. Select the input parameter. Right-click and select Set Message. Leave the default value, processOrderRequest, and click Finish.

Repeat the steps to add the output and processOrderResponse parameters to the processOrder operation.


Figure 6. Create processOrderRequest
Create processOrderRequest message.

Under Messages, you should have two new messages, processOrderRequest and processOrderResponse.


Figure 7. Messages processOrderRequest and processOrderResponse
Two new messages processOrderRequest and processOrderResponse.

Add parts to processOrderRequest message

Select the processOrderRequest message. Right-click and select Add Child => Part. Enter customerId and click OK. Repeat and add the parts for orderId, itemId and quantity.

processOrderRequest PartsTypeWhat this field is used for by ChocoDino, Inc.
customerIdxsd:stringKwesi assigns each customer account a unique number. For example, Betsy's Sweet Shop in Long Island, is assigned the customer id of 1000-01.
orderIdxsd:stringEvery order received by ChocoDino, Inc. is assigned a unique tracking number.
itemIdxsd:stringEach of the four products is assigned a unique item number:
  • Choco-Triceratops is item number 100.
  • White Chocolate Ankylosaurus is item number 200.
  • Cherry Chocolate Dilophosaurus is item number 300.
  • Braciosaurs Brownie is item number 400.
quantityxsd:intThe quantity of one of the four products above (itemId) that will be shipped to the customer.

Change quantity to xsd:int type

To change the type of the quantity variable, select the quantity part. Right-click and choose Set Type. Set the Type to an existing one, xsd:int.


Figure 8. Set quantity to xsd:int type.
Set quantity to int type.

Add parts to processOrderResponse message

Add the following parts to the message processOrderResponse: isComplete of type xsd:boolean and comment of type xsd:string.

processOrderResponse PartsTypeWhat this field is used for by ChocoDino, Inc.
isCompletexsd:booleanWas the ordered completed? If so then the correct quantity of chocolate dinosaurs were shipped to the customer.
commentxsd:stringA message that should be included with the shipment.

Completed ProcessChocoDinoOrderInterface.wsdl

Your ProcessChocoDinoOrderInterface.wsdl should resemble the graphic below. Save your changes by clicking Ctrl-S.


Figure 9. Completed ProcessChocoDinoOrderInterface.wsdl
ProcessChocoDinoOrderInterface.wsdl should resemble this picture.

Set up the process parameters

In the Services view, open the ProcessChocoDinoOrder.bpel business process. Select the ProcessChocoDinoOrder node. In the details pane, scroll down to the Server tab. Select the Process is long-running check box. This indicates that the process is interruptible. Set the Target namespace to http://www.chocodino.com, the URL for ChocoDino, Inc. Click Ctrl-S. You will see the warning "The deployment code for this process needs to be generated." This will be resolved when you deploy your process in a later step.


Figure 10. Server tab in ProcessChocoDinoOrder.bpel
click Server tab in ProcessChocoDinoOrder.bpel.

Configure the process interface

Configure the process interface to the one you created in ProcessChocoDinoOrderInterface.wsdl. This is done by associating the process Receive and Reply activities with the interface definition of a Partner. You will create a ProcessOrder partner that uses the ProcessOrderInterface as the process port type. Setup the Partner and Partner link for the business process.

Right-click and select the default PartnerLink on the top right to rename it to ProcessOrder. In the details property pane, switch to the Description page. The Name should be set to ProcessOrder.

Still in the details pane, switch to the Implementation tab, and click New next to the Partner Link Type. The New Partner Link Type definition box will open with a new Partner Link Type of ProcessOrderPLT. Leave the Number of Roles as One Role, and enter the First Role as ProcessOrderFirstRole.


Figure 11. Enter the ProcessOrderFirstRole
Configure the process interface to the one you created in ProcessChocoDinoOrderInterface.wsdl

Click Browse next to Port Type File and navigate to ChocoDino => com => chocodino => process => ProcessChocoDinoOrderInterface.wsdl. Select ProcessOrderPortType for the Port Type. Click OK.

Your Partner Link panel should resemble the one shown below. Click OK.


Figure 12. Partner link panel
Browse to ProcessChocoDinoOrderInterface.wsdl and then select ProcessOrderPortType

Define the partner link

You are defining the interface (Port Type) into your process so you must swap the roles. The Process Role/Port Type is for those that wish to send messages into your process. As a default, the previously defined role is assigned to sending messages out to a partner. In most cases the Partner Link Type would be the right assumption.

With the ProcessOrder partner still selected on the layout area, switch to the Implementation tab. Swap the Partner's Role with the Process Role using the <---> button. Type Ctrl-S to save the changes.


Figure 13. Swap the Partner's Role with the Process Role
Swap the Partner's Role with the Process Role.

Set up the Receive to handle the correct messages

Select the Receive activity and switch to the Implementation tab. The Partner Link should be ProcessOrder and the Port Type must have ProcessOrderPortType selected. Use the drop down menu to select processOrder as the Operation.

For the Request, click New and enter ProcessOrderRequest. Click OK.

Set up the Reply to handle the correct messages

Select the Reply activity and switch to the Implementation tab. The Partner Link should again be ProcessOrder and the Port Type must be ProcessOrderPortType. Use the drop down menu to select processOrder as the Operation.

For the Response message, click New and enter ProcessOrderResponse. Click OK.

In the diagram, delete the variable placeholder, InputVariable, from the Variables list.


Figure 14. Enter a new response variable - ProcessOrderResponse
For Reply enter a new request variable, ProcessOrderResponse

Adding an activity to the business process


Add an Assign activity
Add an Assign activity

You have created the initial framework for a business process - a Receive and a Reply. Now you can add activities. Your business process accepts four parameters: customerId, orderId, itemId and quantity as the input (through the Receive activity). The business process will reply with a boolean for isCompleted and a possible comment (through the Reply activity). You will now add an Assign activity to populate the Reply message

Choose an Assign activity (the "=" sign) from the Palette and drop it in between the Receive and Reply activities in your business process.

Rename the Assign activity to prepReply

Rename the activity to prepReply. Your business process will now look like the one below.


Figure 15. Rename the activity to prepReply
Rename the activity as prepReply.

Add fixed comment to the Reply message

Select the prepReply activity that you just added. Switch to the Implementation tab. Using the From dropdown box, select Fixed Value and enter ChocoDino order completed by Kwesi as the value. Using the To dropdown, select Variable or Part. Choose ProcessOrderResponse => comment.


Figure 16. Assign "ChocoDino order completed by Kwesi" to comment
Assign ChocoDino order completed by Kwesi to comment.

Add isComplete to the Reply message

Click New. Using the From dropdown box, select Fixed Value and enter false as the value. Choose the type xsd:boolean. Using the To dropdown, select Variable or Part. Choose ProcessOrderResponse => isComplete.

Click Ctrl-S to save your changes.


Figure 17. Assign false to isComplete variable
Assign false to isComplete variable.

Generating the deployment code

Generate the deployment code for ProcessChocoDinoOrder

In the Services view, expand com.chocodino.process and right-click on ProcessChocoDinoOrder.bpel and select Enterprise Services => Generate Deploy Code.

The Generate BPEL Deploy Code wizard opens up. By default the process will be exposed through a JMS interface binding only. JMS is used for any long running business process. If you had not selected the Process is long-running check box then you would have been offered a choice of an EJB (default), JMS, SOAP/HTTP or SOAP/JMS binding. The strength of WebSphere Process Choreographer is that it can implement both long running persistent workflows and non-persistent microflows.

Click OK to generate the deployment code for your project.

Inspect the deployed code for ProcessChocoDinoOrder

After the deployed code has been generated, switch to the J2EE Hierarchy view by clicking the tab in the Navigator pane.

Expand EJB Modules = ChocoDinoEJB => Session Beans. The ProcessChocoDinoOrderBean is the EJB containing your business process.


Figure 18. Deployed ProcessChocoDinoOrderBean code
ProcessChocoDinoOrderBean is a very long name.

Using the unit test environment

Create a server and server configuration

Select the Servers tab at the bottom. This is located near the Tasks tab. Right-click in the pane and select New => Server and Server Configuration. Name the server TestServer. Make sure that Server Type is WebSphere version 5.1 => Integration Test Environment. click Finish.

Add the business process EAR to the test server. Right-click on the TestServer in the Servers view and select Add and Remove Projects. Add the ChocoDinoEAR to the Configured projects. Click Finish.


Figure 19. Add ChocoDinoEAR to list of configured projects
Add the business process EAR to the test server.

Create tables and datasources, then publish!

Create tables and datasources. Right-click on TestServer again and select Create tables and datasources. click OK on the completion dialog after checking that the tables were created successfully.

Right-click TestServer and select Publish. Click OK to dismiss the "Publishing was successful" dialog. Verify that the process was deployed. Right-click on TestServer in the Servers view. Choose Show deployed processes. This should open the Deployed Processes view and your process should be shown there. This action can only be done when the server is stopped.


Figure 20. The deployed process ProcessChocoDinoOrder
The deployed process ProcessChocoDinoOrder.

Using the business process Web client

Return to the Servers view, right-click on the TestServer. Select Start.

Once the server has started, you will test the process using the Business Process Web Client. In the Servers view, right-click TestServer and select Launch Business Process Web Client. The Business Process Web Client will open in a Web browser view window. You can also open the Web client from an external browser using the address http://localhost:9080/bpe/webclient.

Click on the My Templates link in the left column of the Web Client.

The process ProcessChocoDinoOrder should be listed, with a state icon of Running Green Arrow indicates Running process.

Click the ProcessChocoDinoOrder Template Name link. The template definition is displayed for your review. The processOrder service that you implemented is listed.


Figure 21. The processOrder service
The processOrder service is displayed.

Enter ChocoDino order data

Select the processOrder service link. The Process Input Message panel is displayed. Enter the following values. The Process Instance Name must be unique. Enter Test1. Betsy's Sweet Shop (customer id 1000-01) orders 100 Braciosaurs Brownies (item id 400). Choose orderId as 1.

Process Input MessageValue
customerId1000-01
itemId400
orderId1
quantity100

Click Start Instance. The Process Instance will execute. Select the Created By Me link in the left column of the Web Client. Click the Test1 process link. The Response value of isComplete is set to false. The comment is set to ChocoDino order completed by Kwesi.


Figure 22. Result of Test1 execution
The isComplete is set to false. The comment is set to ChocoDino order completed by Kwesi.

Close the Web Client. From the Servers view, right-click on the TestServer. Select Stop from the menu.


Developing Web services


Implementing Web services with WebSphere Process Choreographer
Cherry Chocolate Pterosaurs

Kwesi decides to use Web services to interface his business process with other software components he uses at ChocoDino, Inc. The two Web services calls that he will be implementing are for shipping and billing. Prior to the development of those Web services, you should generate a stub class. First create the Java class to implement the business logic. Then generate the Web services for the class.

In the Services view, right-click on the ChocoDino service project and select New => Package. Enter com.chocodino.model for the package name. Click Finish to create the package


Figure 23. Create the com.chocodino.model package
Enter com.chocodino.model for the package name.

Create the OrderProcessing class

Right-click on the newly created package and select New => Class. Enter OrderProcessing as the class name. Click Finish. Add the methods below to the OrderProcessing class. Save the changes using Ctrl-S.

    /**
	* Stub method for shipping order
	*/
	public boolean shipOrder(String chocoCustomerId, String dinoOrderId) {
		System.out.println(
			"ChocoDino shipping order "
				+ dinoOrderId
				+ " to customer " + chocoCustomerId);
		return true;
	}

	/**
	* Stub method for billing customer
	*/
	public boolean billCustomer(String chocoCustomerId, String dinoOrderId) {
		System.out.println(
			"ChocoDino billing customer "
				+ chocoCustomerId
				+ " for order " + dinoOrderId);
		return true;
	}

Generate the Web services for OrderProcessing

In the Services View, select OrderProcessing.java. Using the menu bar, select File => New => Service built from. The diagram shows the two choices for creating a service: Java or EJB. In this case you are using a Java class. Click Next. Check the box for OrderProcessing and click Next.


Figure 24. Generate Web services for OrderProcessing java
Generate Web services for OrderProcessing java.

Change the package name to com.chocodino.wsdl. Click Finish to generate the WSDL file.


Figure 25. Change the package name to com.chocodino.wsdl
Generate Web services for OrderProcessing java.

Developing the initial ChocoDino fulfillment business process


Fulfilling the order for chocolate dinosaurs
Fulfill Chocolate Dinosaur Order Process

Create a new milestone business process for Fulfilling Chocolate Dinosaur orders. This business process will involve a Staff activity. Kwesi must check his stock of chocolate dinosaurs to determine if a customer's order can be completed. This business process will use the OrderProcessing Web services that you just created.

Create the Fulfill ChocoDino Order process

From the menu, choose File => Close All. Right-click on ChocoDino project and select New => Business Process. In the package com.chocodino.process, create the new business process named FulfillChocoDinoOrder (note spelling). Click Next.


Figure 26. Create the FulfillChocoDinoOrder business process
Create the new business process named FulfillChocoDinoOrder.

Flow-based BPEL process

Select Flow-based BPEL Process for process type and click Finish.


Figure 27. Flow-based BPEL Process
Select Flow-based BPEL Process

Add port, messages, and parts to FulfillChocoDinoOrderInterface.wsdl

Open FulfillChocoDinoOrderInterface.wsdl. Create a new Port Type service interface, FulfillOrderPortType, for the process with the details as shown below.


Figure 28. Details of FulfillChocoDinoOrderInterface.wsdl
Details of FulfillChocoDinoOrderInterface.wsdl
fulfillOrderRequest PartsValue
orderIdxsd:string
itemIdxsd:string
quantityxsd:int

fulfillOrderResponse PartsValue
isCompletexsd:boolean
fulfilledQuantityxsd:int

Changing the part type

You can change the Parts type for entries such as quantity using the Parts menu. Select the quantity part in the Messages window and use the Part Type dropdown to select xsd:int.

Click Ctrl-S to save your changes. Close the FulfillChocoDinoOrderInterface.wsdl.


Figure 29. Set quantity as xsd:int
Select the quantity part in the Messages window and use the Part Type dropdown to select xsd:int.

Process parameters for FulfillChocoDinoOrder.bpel

Open FulfillChocoDinoOrder.bpel. Setup the Process parameters. Select the FulfillChocoDinoOrder node and choose the Server tab. Change the target namespace to http://www.chocodino.com. You must denote this process as long running because in a subsequent section you will add a Staff activity.


Figure 30. Set Process parameters in FulfillChocoDinoOrder.bpel
Set Process parameters in FulfillChocoDinoOrder.bpel

Rename partner link to FulfillOrder and configure process interface

Rename the default PartnerLink to FulfillOrder. From the Implementation tab, configure the process interface to use the new FulfillOrderPortType. Remember to browse to your new FulfillChocoDinoOrderInterface.wsdl and swap the roles so that FulfillOrderFirstRole is a Process Role.


Figure 31. Configure the process interface to use the new FulfillOrderPortType
Configure the process interface to use the new FulfillOrderPortType

Set up the Receive and Reply activities

Set up the Receive and Reply activities to correlate with the new messages. In the Receive activity you should create a FulfillOrderRequest variable. In the Reply activity you need a FulfillOrderResponse variable. Delete the default InputVariable. The operation for both Receive and Reply is fulfillOrder.

Receive FulfillOrderRequest fields
orderId
itemId
quantity

Reply FulfillOrderResponse fields
isComplete
fulfilledQuantity

Add the prepReply activity

Right-click on the Reply activity. Choose Insert Before => Assign. Rename this assignment prepReply.


Figure 32. Context menu for Insert Before => Assign
Choose Assign

Assign values to prepReply

In prepReply, select the Implementation tab. Assign a fix value true of type xsd:boolean to the isComplete part of the FulfillOrderResponse.

Assign the quantity part of the FulfillOrderRequest to the fulfilledQuantity part of the FulfillOrderResponse. Remember to remove the default InputVariable.

FromTo
true (xsd:boolean)FulfillOrderResponse > isComplete
FulfillOrderRequest > quantityFulfillOrderResponse > fulfilledQuantity

Save your business process by clicking Ctrl-S.

Two separate execution threads

In the diagram, drag the three components into three separate columns as shown below. Since this is a Flow diagram, the Assign and the Receive/Reply have separate execution threads. You want these operations to occur in sequence and you will wire them together in the next panel.


Figure 33. Assign and the Receive/Reply have separate execution threads
Two separate execution threads.

Create a sequential path through a flow diagram

Delete the line connecting the Receive and Reply activities.

Click on Receive and then the arrow Arrow next to Receive. Drag the connector to the prepReply. Repeat this step for the prepReply to Reply. This is now a sequential path through the Flow diagram.


Figure 34. Sequential path through the Flow
One execution thread.

Complete the FulfillChocoDinoOrder flow

At this point your FulfillChocoDinoOrder diagram should resemble the following figure.


Figure 35. FulfillChocoDinoOrder diagram prior to testing
FulfillChocoDinoOrder diagram prior to testing

Generate the deployment code for FulfillChocoDinoOrder

In the Services view, expand com.chocodino.process and right-click on FulfillChocoDinoOrder.bpel and select Enterprise Services => Generate Deploy Code.

The Generate BPEL Deploy Code wizard opens up. The process will be exposed through a JMS interface binding. JMS is used for any long running business process.

Click OK to generate the deployment code for your project.

Create tables and datasources and publish the project

Right-click on TestServer and select Create tables and datasources. click OK on the completion dialog after checking that the tables were created successfully.

Right-click TestServer and select Publish. Click OK to dismiss the "Publishing was successful" dialog.

Right-click on the TestServer. Select Start


Figure 36. The deployed process FulfillChocoDinoOrder and ProcessChocoDinoOrder
The deployed process FulfillChocoDinoOrder and ProcessChocoDinoOrder.

Use the Business Process Web Client to test FulfillChocoDinoOrder

Return to the Servers view, right-click on the TestServer. Select Start.

Once the server has started, you will test the process using the Business Process Web Client. In the Servers view, right-click TestServer and select Launch Business Process Web Client. The Business Process Web Client will open itself in a Web browser view window.

Click on the My Templates link in the left column of the Web Client.

The process FulfillChocoDinoOrder should be listed. Click the FulfillChocoDinoOrder Template Name link. The template definition is displayed for your review. The fulfillOrder service that you implemented is listed.


Figure 37. The fulfillOrder service
The fulfillOrder service in the Business Process Web Client

Enter ChocoDino fulfillOrder data

Select the fulfillOrder service link. Enter the following values in the Process Input Message panel. The Process Instance Name must be unique. Enter Test2. Betsy's Sweet Shop orders 100 Braciosaurs Brownies (item id 400). Choose orderId as 1.

Process Input MessageValue
itemId400
orderId1
quantity100

Figure 38. Entry of Test2 variables
Enter 400, 1 and 100.

Completed ChocoDino fulfillOrder data

Click Start Instance. The Process Instance will execute. Select Created By Me in the left column of the Web Client. Click the Test2 process instance link. The Response value of isComplete is set to true. The fulfilledQuantity is 100.


Figure 39. Result of Test2 execution
The isComplete is set to true. The fulfilledQuantity is 100.

Close the Web Client. From the Servers view, right-click on the TestServer. Select Stop.


Completing the ProcessChocoDinoOrder business process

Review of ProcessChocoDinoOrder

Continue developing the ProcessChocoDinoOrder by adding all the activities needed to complete the business process. This will include interfacing with a Web service for the Ship order of chocolate dinosaurs and Bill customer parts. The Dinosaur fulfillment process is a child business process, FulfillChocoDinoOrder. The completed ProcessChocoDinoOrder process should resemble the design diagram.


Figure 40. Chocolate Dinosaur Order Process
Chocolate Dinosaur Order Process

Add the FulfillChocoDinoOrder process

Add the FulfillChocoDinoOrder child process to the ProcessChocoDinoOrder process. From the menu, choose File => Close All. In the Services view, double click on ProcessChocoDinoOrder.bpel to open it. Select FulfillChocoDinoOrder.bpel from the Services view and drag it onto the process editor. It will relocate under the Partner Links.

Save the changes by clicking Ctrl-S.


Figure 41. Add FulfillChocoDinoOrder to Partner Links
Hello Mr. FulfillChocoDinoOrder.

Add the FulfillOrder activity

Insert the FulfillOrder activity to the ProcessChocoDinoOrder process by adding an Invoke activity below the Receive activity. Rename it to FulfillOrder.

Select the FulfillOrder activity. Right-click and choose Set Partner Link. Drag the arrow and drop it on the FulfillChocoDinoOrder Partner Link.

With the FulfillOrder Invoke activity still selected, switch to the Implementation tab. Use the dropdown list to set the Partner Link to FulfillChocoDinoOrder. Select fulfillOrder for the Operation.

Click New for the request and enter FulfillOrderRequest and click OK.

Click New for the response and enter FulfillOrderResponse and click OK.

Save the changes using Ctrl-S.


Figure 42. FulfillOrder Implementation
Select fulfillOrder for the Operation. Add FulfillOrderRequest and FulfillOrderResponse.

Add the prepFulfillOrder activity
Add the prepFulfillOrder activity.

Add an Assign activity before FulfillOrder and rename it to prepFulfillOrder.

With the prepFulfillOrder activity selected, switch to the Implementation tab. Assign from the ProcessOrderRequest to the FulfillOrderRequest the orderId, itemId and quantity variables. Click New to create a new mapping pair for each assignment.

Save the changes using Ctrl-S.

Even though FulfillOrderRequest uses the same part names as and is a subset of the ProcessOrderRequest you must create a new request variable for each invoke.

ProcessOrderRequest FulfillOrderRequest
orderIdorderId
itemIditemId
quantityquantity

Modify the prepReply activity to use the result of the FulfillOrder

Since the FulFillOrder has been implemented the prepReply activity should use the result. Assign the isComplete part from the FulfillOrderResponse to the ProcessOrderResponse. Save your changes by clicking Ctrl-S.


Figure 43. Assign the isComplete part
Modify the prepReply activity to use the result of the FulfillOrder.

Add OrderProcessing Web service

Add the OrderProcessing Web service to ProcessChocoDinoOrder. Use the OrderProcessing Web service, created from the stub Java class. This will allow you to invoke the two service calls, ShipOrder and BillCustomer from ProcessChocoDinoOrder.

Under Services, select OrderProcessingJava Service.wsdl and drag it onto the process editor.

Click OK to add the OrderProcessing to the Partner Links.

Save the changes using Ctrl-S.


Figure 44. Add OrderProcessing Web Service
Add OrderProcessing Web Service.

Add Switch statement

Insert a Switch activity after the FulfillOrder activity.


Figure 45. Add Switch
Add Switch after FulfillOrder.

Add a Case to the Switch activity.

Kwesi only wants to ship the chocolates and bill his customer if he has completed the order. If the order is not completed, then the ProcessChocoDinoOrder should return back to the calling process with isCompleted set to false. The calling process will then determine what went wrong and either resubmit the order or notify the customer that their order of delicious chocolate dinosaurs cannot be processed.

Select the Case and its Description tab. Rename the Case to FulfillOrderCompleted.

Click the Condition tab. Select Exclickion for the value and enter the following. Remember Kwesi only wants to ship the chocolate dinosaurs and bill the customer if the order was completed.

// only ship the chocolates and bill the customer if the order is completed
return getFulfillOrderResponse().getIsComplete();

Notice that the BPEL4WS variable, FulfillOrderResponse, is implemented as a Java class.

Save the changes using Ctrl-S.

Implicit in the Switch statement is that if isCompleted is set to false then the Reply activity will be invoked.

Contents of the Switch statement

Use the figure below as a guide for the next several steps.


Figure 46. The Switch statement and its contents.
Add Switch.

Add ShipOrder to invoke the Web service

Add an Invoke activity. Rename it to ShipOrder.

Select the activity. Choose the Set Partner Link icon Partner Link icon. Drag the arrow and drop it on the OrderProcessing Partner Link.

Select ShipOrder. Switch to the Implementation tab. Choose shipOrder for the Operation.

Click New to create a request variable, ShipOrderRequest, and a response variable, ShipOrderResponse.

Click Ctrl-S.


Figure 47. ShipOrder Implementation
Select shipOrder for the Operation. Add ShipOrderRequest and ShipOrderResponse.

Add prepShipOrder

Add an Assign activity and rename it to prepShipOrder.

With the prepShipOrder activity selected, switch to the Implementation tab.

Assign the fields from the ProcessOrderRequest to the ShipOrderRequest. Click New to create a new mapping pair.

ProcessOrderRequestShipOrderRequest
customerIdchocoCustomerId
orderIddinoOrderId

Add BillCustomer to invoke the Web service

Add an Invoke activity. Rename it to BillCustomer.

Select the activity. Choose the Set Partner Link icon Partner Link icon. Drag the arrow and drop it on the OrderProcessing Partner Link.


Figure 48. BillCustomer Partner Link
Add BillCustomer Partner Link.

With the BillCustomer activity still selected, switch to the Implementation tab. Choose billCustomer for the Operation.

Click New to create a request variable, BillCustomerRequest, and a response variable, BillCustomerResponse.

Click Ctrl-S to save your changes.

Add prepBillCustomer

Add an Assign activity and rename it to prepBillCustomer.

Select prepBillCustomer activity. Switch to the Implementation tab.

Assign the fields from the ProcessOrderRequest to the BillCustomerRequest. Click New to create a new mapping pair.

ProcessOrderRequestBillCustomerRequest
customerIdchocoCustomerId
orderIddinoOrderId

Create tables and datasources, then publish and use the Web client

Right-click on TestServer and select Create tables and datasources. Click OK on the completion dialog after checking that the tables were created successfully.

Right-click TestServer and select Publish. Click OK to dismiss the "Publishing was successful" dialog.

Right-click on the TestServer. Select Start

Test the ProcessChocoDinoOrder using the Business Process Web Client.


Completing the FulfillChocoDinoOrder business process


Overview of FulfillChocoDinoOrder
Fulfill Chocolate Dinosaur Order Process

Continue the development the FulfillChocoDinoOrder by adding all the activities needed to complete the business process. This will include implementing a Staff activity. The completed FulfillChocoDinoOrder process should look like the design diagram.

This portion will implement two Assign activities, a while loop, a Staff activity and a Java Snippet.

Modify the FulfillChocoDinoOrderInterface.wsdl

A Staff activity allows human interaction with your business process. Staff is an important part of workflow.

From the menu choose File => Close All. Open FulfillChocoDinoOrderInterface.wsdl.

Modify the FulfillChocoDinoOrderInterface.wsdl file by adding the StaffPortType as shown below


Figure 49. Add the StaffPortType
Add the StaffPortType.

Add the RetrieveItems Staff activity

Open FulfillChocoDinoOrder.bpel. Add a Staff activity. Since this is a flow diagram it will have a separate thread. Rename it RetrieveItems.

Select the Implementation tab.

Browse to FulfillChocoDinoOrderInterface.wsdl. Use the StaffPortType and select the retrieveItem operation.

Click New for the request and enter RetrieveItemsRequest. click OK.

Add RetrieveItemsResponse for the response.

Click the Staff tab. Modify each role so that the Verb is Everybody. This will allow all employees of ChocoDino to perform the Potential Owner, Editor and Reader staff operations. In a larger company, you would differentiate these roles to particular users.

Save the changes using Ctrl-S. You will see several errors by these will be resolved in a subsequent step.


Figure 50. RetrieveItems Implementation
retrieveItem operation. Create RetrieveItemsRequest and RetrieveItemsResponse.

Add a While Order is Not Fulfilled loop

Add a While activity. Rename it to WhileNotFulfilled. This loop will execute until the order is considered fulfilled by Kwesi. If Kwesi has the correct quantity and type of chocolate dinosaurs available then the order is considered both fulfilled and completed. If he does not have the items in stock Kwesi can either:

  1. Enter the quantity of chocolates that he does have in stock and consider the order fulfilled. The isComplete flag will be set to false and a log message will be written in the Java Snippet step below. The parent process will be responsible for notifying the ChocoDino customer that their order cannot be completed with a shipment of tasty chocolates.
  2. Set the isFulfilled flag to false. This will allow him to return to the order at a later date when he can ship the correct number of chocolates for the order.

Select the Condition tab and the Exclickion dropdown menu for the value. Enter the following exclickion.

 //	continue prompting Kwesi until the order is considered fulfilled.
 return !getRetrieveItemsResponse().getIsFulfilled();
 

Move the RetrieveItems staff activity inside of the loop.

Click Ctrl-S.


Figure 51. Add the WhileNotFulfilled
Add the WhileNotFulfilled.

Add prepNotFulfilled

Add an Assign activity and rename it to prepNotFulfilled.

With the prepNotFulfilled activity selected, switch to the Implementation tab.

Assign the fields as shown below. This has a substantial number of assignments to different variables so be careful.

From [Fixed Value]To
0 (xsd:int)FulfillOrderResponse > fulfillQuantity
0 (xsd:int)RetrieveItemsRequest > quantityRetrieved
0 (xsd:int)RetrieveItemsResponse > quantityFilled
false (xsd:boolean)RetrieveItemsResponse > isFulfilled

FromTo
FulfillOrderRequest > orderIdRetrieveItemsRequest > orderId
FulfillOrderRequest > itemIdRetrieveItemsRequest > ItemId
FulfillOrderRequest > quantityRetrieveItemsRequest > quantityNeeded

Add postRetrieveItems

Add another Assign activity. Rename it to postRetrieveItems.

Switch to the Implementation tab.

Assign the fields as shown below.

FromTo
RetrieveItemsResponse > quantityFilledRetrieveItemsRequest > quantityRetrieved
RetrieveItemsResponse > quantityFilledFulfillOrderResponse > fulfillQuantity

Move the postRetrieveItems inside of the while loop under the Staff activity.

Replace the prepReply with a Java Snippet

Delete the prepReply activity and replace it with a Java Snippet. Name it prepReply.

Select the Implementation tab. Kwesi wants to set the isCompleted flag to true if the requested number of chocolate dinosaurs is what he scan deliver to the customer. Otherwise the response isCompleted flag is set to false. If the order is not completed the process must log an audit message. This will allow him to adjust his chocolate dinosaur inventory.

// set isCompleted flag based on requested # of chocolate dinosaurs vs. what is delivered
getFulfillOrderResponse(true).setIsComplete(getFulfillOrderRequest().getQuantity() 
        <= getRetrieveItemsResponse().getQuantityFilled());
// log a audit message if the order is not completed
 if (!getFulfillOrderResponse().getIsComplete())
 {
     System.out.println("Order was not fulfilled for : " + getFulfillOrderRequest().getOrderId());
 }
 

Complete the FulfillChocoDinoOrder

Move the activities and wire them as shown in the diagram.

Configure the FulfillChocoDinoOrder process for proper Staff interaction. Select the FulfillChocoDinoOrder node at the top. Select the Staff tab. Select each role and change the verb to Everybody.

Save the changes using Ctrl-S.

Repeat the same Staff steps for the parent ProcessChocoDinoOrder business process.


Figure 52. Completed FulfillChocoDinoOrder
FulfillChocoDinoOrder

Testing the ProcessChocoDinoOrder process

Build project and start testing

Generate the deployment code for both FulfillChocoDinoOrder.bpel and ProcessChocoDinoOrder.bpel.

Create the tables and datasources.

Publish and start the TestServer.

Test the ProcessChocoDinoOrder business process using the Business Process Web Client. This business process will have a staff activity. In the Servers view, right-click TestServer and select Launch Business Process Web Client.

Click on My Templates in the left column of the Web Client. The process FulfillChocoDinoOrder and ProcessChocoDinoOrder should be listed, with a state icon of Running Running Process.

Click ProcessChocoDinoOrder Template Name. The template definition is displayed for your review. The processOrder service that you implemented is listed.


Figure 53. The processOrder service
The processOrder service is displayed for your review.

Enter test data

Click on the processOrder link. The Process Input Message panel is displayed. Enter Test3. Betsy's Sweet Shop (customer id 1000-01) orders 100 Braciosaurs Brownies (item id 400). Choose orderId as 2.

Process Input MessageValue
customerId1000-01
itemId400
orderId2
quantity100

Click Start Instance. The Process Instance will execute.

Build project and start testing

Select My To Dos link in the left column. This will list any staff activities.


Figure 54. The processOrder service
Display any Staff activities for processOrder.

Click the RetrieveItems link.


Figure 55. RetrieveItems in Ready state
RetrieveItems in Ready state

Since you need to fulfill this order, click Claim. You will be returned to My To Dos.


Figure 56. RetrieveItems in Claimed state
RetrieveItems in Claimed state

Complete the Staff activity

Click on the RetrieveItems link. You will see the following. Enter true for isFulfilled and 100 for the quantityFilled. Click Complete.


Figure 57. Enter data and then complete
Enter data and then complete.

Results of test

Select the Created By Me link in the left column of the Web Client. Click the Test3 process link. The Response value of isComplete is set to true. The comment is set to ChocoDino order completed by Kwesi.


Figure 58. Result of Test3 execution
The isComplete is set to true. The comment is set to ChocoDino order completed by Kwesi.

Execute several tests including one where the quantityFilled is less than that requested. This order should not be completed.

Close the Web Client. From the Servers view, right-click on the TestServer. Select Stop.


Conclusion
Yummy! The Choco-Triceratops

If you have reached this point in the article you have built two business processes: ProcessChocoDinoOrder and FulfillChocoDinoOrder. The first process used a sequential diagram. The second was implemented with a flow diagram. Both contained the essential BPEL4WS activities. In addition, you used the IBM extensions Staff and Java Snippet. Kwesi is now ready to use your ordering process to help him sell ChocoDino's delicious chocolate dinosaurs.


Resources

About the authors

<b>Fred Simmons</b> is a consultant for IBM Software Services for WebSphere in Research Triangle Park, North Carolina. You can contact Fred at <a href="mailto:fredsid@us.ibm.com">fredsid@us.ibm.com</a>.

<b>Jeng Yoong Tan</b> is a consultant with IBM Software Services for WebSphere in Research Triangle Park, North Carolina. Jeng has received extensive dinosaur training from his son, Nicholas Tan. You can contact Jeng at <a href="mailto:jtan@us.ibm.com">jtan@us.ibm.com</a>.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=WebSphere
ArticleID=91683
ArticleTitle=Implementing a workflow using design patterns with WebSphere Process Choreographer, Part 1
publish-date=08102005
author1-email=fredsid@us.ibm.com
author1-email-cc=
author2-email=jtan@us.ibm.com
author2-email-cc=