Wednesday, June 18, 2014

Developer Studio - How to create a BPEL Process to invoke a Partner Service

In this post i will discuss on how you can use DeveloperStudio to create a BPEL process which invokes another service (partner service)

Suppose you have a already deployed service.  Lets say this service as  'WeatherService' which has a web method call getTemeprature where it will return the temperature when you provide the city as argument. make sure you have the wsdl of this service since we need this to create a Partner Link. Here is the wsdl of the service that i used. And here you can download the aar of the web service.

Create The BPEL Project
Click on BPEL Workflow in Developer Studio DashBoard



Select Create New BPEL Workflow radio button and click on next


Set the project name as WeatherServiceWorkflow and Template as Synchonous BPEL process.


Click on finish. You will then see a page like follows.


Double click and open WeatherServiceWorkflowArtifacts.wsdl file and hover the mouse on top of blue color arrow next to WeatherServiceWorkFlowResponse and you may see something like follows.


Then click on that arrow and it will open the above window in another editor. In that change the type of the result parameter of WeatherServiceWorkFlowResponseType  to double (since backend service returns temperature as a double value).
Save this editor and close. Now lets define the workflow for the invoke operation. Open WeatherServiceWorkFlow.bpel and delete the FIX_ME-Add_Business_Logic_Here component from the flow. Then add a Invoke operation from the palette to the workflow and rename it as Invoke WeatherService.



Then add a Assign action just before the InvokeWeatherService and rename it as AssignInputs. Similarly add another Assign action just after the InvokeWeatherService action and rename it as AssignOutputs.


Now we are done with the bpel flow configuration but we have to configure each element in the flow. Here we have added 3 elements called AssignInputs, InvokeWeatherService and AssignOutputs. Objective of AssignInputs is to map the inputs receiving in the bpel flow to the invoke service and AssignOutput does the other way.

First we will configure InvokeWeatherService to invoke the backend service, for this we need to have the wsdl of that service. Download it from here and import it into bpelContent folder in the project. To invoke a partner service we need to create a Partnerlink. Click on InvokeWeatherService element in the flow and select the details tab on the properties view. From the dropdown list select GlobalPartnerLink .



Then it wil prompt a dialog box to provide a name for the PartnerLink, give the name as WeatherServicePL and click OK.  Then it will open up another dialog to select partnerlink Type.


Click on Add WSDL button and browse for the WeatherService.wsdl (that we have imported to the bpelContent folder in earlier step) and add it. Then you may see that new field called WeatherServicePortType appears in the dialog. select that and click OK.



Then it will again promts a dialog to provide a partnerlink type name, Give a name as WeatherServicePLType and click next. Then in next page ask for a Role Name, give a name as TestRole and click finish.

Then again go to the properties view and from the Quick Pick section select getTemeprature be double click on getTemperature. Then that fill up the other fields automatically.


Now we are done with creating the partner link for the invoke action. Now lets map inputs and outputs with Assign actions. Click on AssignInputs and on properties view click on Details tab, there click on New button at the left bottom side. Then in 'From' side expand input : WeatherServiceWorkflowrequestMessage and select 'payload : WeatherServiceWorkflowRequest' and in 'To' side expand WeatherServicePLRequest:getTemperatureRequest and select 'parameters : getTemperature'.


Once you select both from From side and To side for the first time, it will prompt a message to ask you weather it should initialize the variables for you.

Click Yes, Once you do that you may see that another entry (Variable to Variable) automatically added in the left hand side list. Click on that 'Variable to Variable' and in 'From' side expand the payload  'payload : WeatherServiceWorkflowRequest' and select 'input : string'. Similarly select 'city : string' from 'To' side.

Do the same steps on AssignOutputs action to map 'WeatherServicePLResponse : getTemperatureResponse' to 'output : WeatherServiceWorkflowResponseMessage'

Now we are done with configuring invoke and varible assignmnet actions and lets move to configure deploy options.

Double click and open deploy.xml. In the Inbound Interfaces list you may notice that Partner Link is set to client but other fields are not set. From the dropdown menu there select WeatherServiceWorkflowPort and it will fill out the other fields for you.

In the Outbound Interfaces you may see that partner link is already set to WeatherServicePL, select the Associated Port as WeatherServiceHttpSoap11Endpoint from the dropdown menu and it will fill the other feilds.



Now we are done with all the configurations and we are ready to deploy this and test. Right click on WeatherServiceWorkflow project and click on 'Export Project as Deployable Archive' from the context menu. Give a export destination and click finish. Here i'm attaching the exported project.

Start WSO2 AS and deploy WeatherService.aar. Goto management console -> Services -> Add -> AAR service. Then test it from try it tool.



Start a WSO2 BPS server (with port offset 1 avoid port conflicts with WSO2 AS). Deploy the Exported WeatherServiceWorkflow_1.0.0 in BPS server. (Goto managment console of the server -> Process -> Add ). Then we will test this using servers inbuilt try it tool . In management console goto Services and click on list under that, you may see that WeatherServiceWorkflow is in deplyoed list. Click on the Try this service in the right hand side, bY giving a city name as colombo fro a test parameter.


You may see that you got the same output. In summary what we did was invoke the WeatherService hosted in wso2 AS via a bpel process. This is a very simple example to demonstrate the invoke function but there are many.. Upto you to try. You can refer BPS docs [1] and Developer Studio docs [2] for more information.

[1] https://docs.wso2.org/display/BPS320/WSO2+Business+Process+Server+Documentation
[2] https://docs.wso2.org/display/DVS360/WSO2+Developer+Studio+Documentation