Friday, February 12, 2016

BPMN REST tasks with WSO2 BPS

WSO2 BPS supports invoking rest endpoints out of the box. Follow the following steps to add a RESTTask to your workflow using Activity BPMN 2.0 designer.

  1. Add the BPMN designer to your Eclipse installation using the update site here. 
  2. Start a new BPMN project.
  3. Add a new service task from the tasks palette.
  4. Go to the task properties panel and open main config tab.
  5. Select "Java class" as task type.
  6. Give "" as the Class name.
  7. Now add fields with following names, and values in String value field, under documentation section.
    • serviceURL - rest service endpoint
    • method - http method to use
    • basicAuthUsername - username if the endpoints are secured
    • basicAuthPassword - password for the username above
    • input - payload to be sent
    • outputVariable - process variable to save the response
    • headers - header values in the format "key1:value1,key2:value2"
Now you can retrieve the response from the variable specified above in the succession steps of the workflow.

Refer the screenshot below to find out the important places you require inside eclipse designer.

Changing the endpoint after process deployment

The REST endpoint could not change after deploying the process in above method. If you want to change the endpoint after deploying the process also, pointing to a registry location which contains an endpoint reference as mentioned in Endpoint+References. For this add a field with name "serviceRef" instead of the "serviceURL" field and give the registry location of the service reference as the value.

Using json payloads

You can send json as the payload also.

Give the json payload to the input field. This time use the expression box in add field dialog to give the json value instead of string value box. Add new field called "outputMappings" and mention the mapping format from response json, similar to ",var3:item.price" format.

EDIT on 14/05/2016

REST task sample

I have added a sample at BPMNRESTSample. This sample  make a REST call to a endpoint and display the response in a user task. Deploy the sample in WSO2 BPS and start a new process instance from BPMN Explorer shipped with BPS.

Enjoy with REST!!

WSO2 BPS - Customizing web apps

Wso2 BPS 3.5.0 is shipped with two web applications, the Humantask Explorer and BPMN Explorer.
By default it is configured to be used in a standalone BPS server. But they can be configured to other setups also. For this, you need to edit the config.json file. The web apps are located in the <Wso2Server_Home>/repository/deployments/server/jaggeryApps/ folder. I'll refer this as jaggery apps folder, now on. config.json is inside the <webapp_home>/configs folder.

Now, let me explain different configurations one by one.

  1. Use the explorers in a different tenant domain other than the super tenant.
    • Copy the relevant web app from jaggery apps folder into to the <WSO2_Home>/repository/tenants/<tenanat_id>/jaggeryapps folder.
    • Give the tenant name in the config.json.
  2. Run BPS in a separate server other than the web app container.
    • Fill the bpsHost and bpsPort parameters in the config.json
These are the only two configurations I can remember write now. There could me more!