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 Reference (EPR).
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>
Changing the endpoint after process deployment
The REST endpoint can not be changed after deploying the process using the above method. If you want to change the endpoint after deploying the process, you need to point to a registry location, which contains an endpoint reference. For more information on how to do this, see Endpoint References.
To change the REST endpoint after process deployment, give the registry location of the service reference in the Service Reference (EPR) field on the Main config tab of the Properties panel for the REST task. For an example, see the above example Using JSON payloads.
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>