Monday, June 18, 2012

How to develop WS-BPEL for Apache ODE with WSO2 Developer studio 2.0.0

This Tutorial Applyes To:

WSO2 BPS 2.1.2
WSO2 Developer Studio 2.0.0
Eclipse Helios SR2 3.6.2


In this tutorial I am going to demonstrate how to develop a BPEL process using WSO2  Developer studio 2.0.0.For those who have not heard about keywords in the these might be the questions in your head now.

1. What is WS-BPEL and Apache ODE ?
WS-BPEL (Business process execution language for Web services)  is a language used for composition , orchestration and coordination of web services. It is a rich language to express the behavior of business process.
Apache ODE (Apache orchestration director engine)  is a system for executing long running process describe using the WS-BPLE standards.
2. What is WSO2 Developer Studio.
WSO2 Developer Studio is a complete tooling platform where you can develop, deploy, test and debug your SOA applications in a very user-friendly manner.
These are the Pre-Requirements for deploying the WS-BPEL process explained in this tutorial, it is required to have the following applications installed in your machine.

Java Runtime Environment 1.6.x
Eclipse Java EE IDE, Version Helios with WSO2 Developer Studio 2.0.x
Apache Axis2 server 1.6.x
WSO2 Business Process Server 2.1.x

So now its time to jump in to work  to make the way smooth we can split tutorial into several phases.

1. Deploying the axis2 service.
2. Developing the BPEL process.
3. Deploying the BPEL process.
Let’s do the the first step.

1. Deploying the axis2 services.

To maintain the simplicity of the tutorial and for the easiness I use the sample axis2 service shipped with WSO2 developer studio.For import sample in to your workspace

1.1 Go to Developer Studio -> Samples  and click on the sub menu item labeled with Axis2 Account Service as shown in the figure below.

Note :-  *To use this sample you have to build it by maven because it needs some dependencies to be fulfilled. And also make sure refresh the project in the workspace and build it (using eclipse) before try to deploy.

Download the Apache Axis2 Server from -

extract the zip file and start the axis2 server (for this tutorial  we assume axis2 server up and running on localhost port 8080)

1.2 Right click on the imported project select the menu item Export Project as Deployable Archive as shown in the below image.

1.3 Use the Browse button on the popped up wizard to point the location of the file system to save the .aar file.

If the .aar file correctly deployied on the axis2 console below will be printed.

Now we have successfully completed the first step of our tutorial.

Note :- You can use the axis2 client that shipped with the Account Service Sample to test the sample.

Traverse down the class call AccountServiceClient in the client package and just run it self explaining  console output will print.

1.4 Generate the WSDL of AccountServiceSample.

As you can see the above image of right click menu of the AccountServiceSample project selecting the Generate WSDL option you can generate WSDL and point it to any system location you want.

2.Developing the BPEL Process.

2.1 Creating BPEL Project.

Click on Open Dashboard option on Developer studio menu we have seen earlier.It will open the WSO2 Developer studio dashboard shown as below.

click on the BPEL Workflow link button under the Business Process Server category.

2.1.1 It will trigger the Create New BPEL Project wizard as below.

Select the Create New BPEL Workflow option and press Next button and give a name for the BPEL process.

we can change the maven information here if we need. WSO2 developer studio have the fully maven integration for all the project types created using it.

The project structure created by the wizard will same as below.

2.2 Developing BPEL process.

Note : - Chage the perspective to BPEL by Window - > Open Perspective -> Other -> BPEL Perspective.

Now we need the WSDL of the AccountServiceSample service .For that just right click the AccountServiceSample project and select the menu option Generate WSDL. point the generated WSDL in to AccountDemoProcess project.

Open the BPEL on BPEL editor and Remove the dummy component from the created BPEL pointed below.

Go to Control2 category in BPEL editor and select Sequence element from there and drag drop it to just after the receiveInput element.

Now we need to add invoke element to call the create account operation.For that go to Actions category select Invoke drag and drop in to the AccDemoSeq.

Click on the CretaeAccountOperationInvoke element and go to the Details tab in properties view select the combo box in front of the Partner Link filed. Select the Create Global partner Link option.

click on the Add WSDL button point the AccountService.wsdl that we added earlier to the AccountServiceDemoProcess.Click the OK button. It will popup the Create New Partner Link Type dialog give the name of Partner Link Type as


In the next pop up dialog give a name for the partner link AccountServicePLT


On the next dialog window it ask for the role for this partner link type. Give the role name as AccountServiceRole and select the the port type as AccountServicePortType as shown below.

click on the finish button.

now we have to select the operation for this invocation.Back again to the properties view and select the the createAccount operation from the combo box as below.

Note : - make sure select the operation and double click the same operation on quick pick view on the right side.It will generate the request response configurations for us otherwise when we are in the variable assignment level we will have unwanted problems.

Before go further we should rename the variables for the sake of convenience. We can select the variable from the Variables section as shown below and using properties view we can change the names.

AccountOperationsPLRequest -> createAccountRequest  (take dummy string argument)

AccountOperationsPLResponse -> createAccountResponse (account number as int)

AccountOperationsPLRequest1 -> creditAccountRequest.(account number and the amount to credit as input arg).

AccountOperationsPLResponse1 -> creditAccountResponse (operation successful or not as boolean)

As per the WSDL cretaeAccount operation take string argument (dummy) and return newly created account number as an integer value. So we have to give the dummy assignment to that operation. For that add assign element from the palette.To configure the assignment click on the assign element go to properties view select details tab click on new button.

The next step we want is add some credits to the newly created account. For that we have to invoke the creditAccount Operation.But the creditAccount operation takes the account number and the amount as arguments. Same as above we can add the creditAccount operation as an invoke element.

To take the account number and submit it to crditAccount Operation we have to add assign element from the palette after the createAccount operation as below.Give the name of the assingment as AssignAccNumTocreditAccOp.

As we discussed earlier now we need to 

   creditAccountOperation  =  output of the creteAccountOperation.

now it is very easy to do the assignment

editor will ask to initialize the variables, allow it otherwise we have to take care of the initialization.

For the easiness we are hard coding the credit amount.To do that click New button and again and change the From : combo box to Fixed Value and put  ‘12000’ to the editable text box .on the To : section traverse to creaateAccountRequest -> parameters -> amount select it. Then the credit amount will set to 12000 when the operation invoke.  

now we need to check the state of credit account operation for that we are using if element. drag and drop the If element from the palate as shown below

name it as CheckCreditState. We need to set the condition.Go the properties view and details tab click on Create New Condition button. copy and paste below expression in the editable area.

$creditAccountResponse.parameters/ns:return = true

Now it’s time to  invoke check balance service depends on the condition that we have set. drag and drop invoke element to the if block as shown in the below image and configure it to invoke the check 

balance service same as described above.

And also we need to submit the account number to this operation also to achieve that use the assign element described above.

now we need to copy the checkbalance operation out put to reply out put element for that we can add   assign element same as before. so what about if condition fails? so we need to add else element by right click on the if block and selection Add Else option. Drag and drop an assign element o n to it and configure it to assign false to reply on element.
The final Bpel configuration will look like below .

And also make sure the deploy.xml configurations set as below.

3. Deploy the BPEL artifact.

3.1 Deploy in Apache ODE.

Right click on your AccountServiceDemoProcess project and select the Export project As a Deployable Archive.

Locate the file system location that you want to save the  artifact.

it will create file.

go to apache ODE management console select deployment tab give the process name as AccountServiceDemoProcess  locate the artifact file that we have created from the system click on ok.
It will create file.
Go to apache ODE management console select deployment tab give the process name as AccountServiceDemoProcess  locate the artifact file that we have created from the system click on ok.
Put the extracted zip content in to directory call AccountServiceDemoProcess in ODE instalation diractory/WEB_INF/processes.

3.2 Deploy in WSO2 BPS (WSO2 Business Process Server)

You can download the WSO2 BPS from [1] and go to installation  directory  then go the bin directory if you are using Linux run the shell script call or otherwise in windows run the wso2server.bat file to start the server.

You can create the deployable archive via above option and  go to the management console of wso2 bps by https://localhost:9443/carbon/ and login to the management console using admin and user name and password.Management console will be shown as below.

Click on the button labeled with Add BPEL on the left panel It will lead you to below page  from there you can upload the .zip file you have created using WSO2 developer studio.

You can try out the process using try it tool on WSO2 BPS.

Source Code and the axis2 archive can be downloaded from Here