BPMN REST tasks allow you to invoke REST endpoints within your BPMN processes. This can be achieved by adding a Service Task and handling the REST invocation part in a level implementation. BPS 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
Note |
---|
|
- To add a REST task, you need to add a Java task in place within the BPMN process where you need to do the invocation. Therefore, you have to first create a BPMN process.
- This guide demonstrates adding a REST task using the Eclipse BPMN Designer. Use the update site, to add this plugin to your eclipse if you have not already done so. You can do the same in any other editor by adding the same property values.
|
...
Code Block |
---|
|
<serviceTask id="servicetask1" 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/${m ethod}
</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[key1:value1,key2:value2]]>
</activiti:string>
</activiti:field>
</extensionElements>
</serviceTask> |
Using JSON payloads
The example code block above uses the text request inputs. JSON input can also be sent with the request. To send JSON input, add a field with the name “outputMappings” and provide how to map the JSON response to the variables. The following code block provides an example definition with JSON input.
Code Block |
---|
|
<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.
...