This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.
Invoking a REST Endpoint from a BPMN Workflow
BPMN REST tasks allow you to invoke REST endpoints within your BPMN processes. This can be achieved by adding a REST Task and handling the REST invocation part in a process implementation. EI-Business Process has provided this functionality out of the box to avoid the hassle of doing implementations by process developers.
Adding a REST task to a process
- Create a BPMN process and a BPMN diagram. For instructions, see Creating a BPMN Process.
- Drag and drop a REST Task from the tools palette in the place where you need to invoke the endpoint.Â
- Go to the Properties panel of the REST Task and select the Main config tab.Â
Enter values for the following fields appropriately, as shown in the example below.
Field Name String Value Required/Optional Service URLÂ URL of the target endpoint.
Optional
You can give this instead of the Service Reference (EPR).
BasicAuth Username Username if the endpoints are secured Required BasicAuth Password Password for the username above Required Service Reference (EPR) Registry resource path of the endpoint reference.
Optional
You can give this instead of the Service URL.
HTTP Method HTTP method (GET. POST, PUT or DELETE) Required Input Payload Request payload Optional Output Variable name Name of the variable to save the response Optional Output Variable Mappings Variable mappings to map JSON response content into multiple variables .Â
var2:customer.name,var3:item.price
Optional Transport headers Header values in the format
{"headerName1":"headerValue1","headerName2":"header Value2"}
Optional
The following configuration provides an example definition to use as the REST task.
<serviceTask id="InvokeRESTEndpoint" name="REST task1" activiti:class="org.wso2.carbon.bpmn.extensions.rest.RESTTask"> <extensionElements> <activiti:field name="serviceURL"> <activiti:expression>http://10.0.3.1:9773/restSample1_1.0.0/services/rest_sample1/${method} </activiti:expression> </activiti:field> <activiti:field name="basicAuthUsername"> <activiti:expression>bobcat</activiti:expression> </activiti:field> <activiti:field name="basicAuthPassword"> <activiti:expression>bobcat</activiti:expression> </activiti:field> <activiti:field name="method"> <activiti:string> <![CDATA[POST]]> </activiti:string> </activiti:field> <activiti:field name="input"> <activiti:expression>Input for task1</activiti:expression> </activiti:field> <activiti:field name="outputVariable"> <activiti:string> <![CDATA[v1]]> </activiti:string> </activiti:field> <activiti:field name="headers"> <activiti:string> <![CDATA[{"headerName1":"headerValue1","headerName2":"header Value2"}]]> </activiti:string> </activiti:field> </extensionElements> </serviceTask>
Using JSON payloads
The following configuration provides an example with JSON input sent with the request. You can use the Output Variable Mappings field to map the JSON response to the variables.Â
<serviceTask id="servicetask2" name="Rest task2" activiti:class="org.wso2.carbon.bpmn.extensions.rest.RESTTask"> <extensionElements> <activiti:field name="serviceRef"> <activiti:expression>conf:/test1/service2</activiti:expression> </activiti:field> <activiti:field name="method"> <activiti:string> <![CDATA[POST]]> </activiti:string> </activiti:field> <activiti:field name="input"> <activiti:expression>{ "companyName":"ibm", "industry":"${industry}", "address":{ "country":"USA", "state":"${state}"} } </activiti:expression> </activiti:field> <activiti:field name="outputMappings"> <activiti:string> <![CDATA[var2:customer.name,var3:item.price]]> </activiti:string> </activiti:field> </extensionElements> </serviceTask>
Configuring the HTTP client
The above REST task is bundled with an HTTP client by default. You can edit its configurations in the <EI_HOME>/wso2/business-process/conf/activiti.xml
 file as shown in the example below.
<bean id="restClientConfiguration"> <property name="maxTotalConnections" value="200"/> <property name="maxConnectionsPerRoute" value="200"/> <property name="connectionTimeout" value="12000"/> <property name="socketTimeout" value="12000"/> </bean>