You can use BPMN Service Task and configure it as following to invoke a REST API
Example with text input and text output:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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/${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[key1:value1,key2:value2]]></activiti:string> | |
</activiti:field> | |
</extensionElements> | |
</serviceTask> |
Example with JSON input and JSON output mapping and registry based URL: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
https://github.com/wso2/carbon-business-process/blob/master/components/bpmn/org.wso2.carbon.bpmn/src/main/java/org/wso2/carbon/bpmn/extensions/rest/RESTTask.java
Currently it supports GET and POST only. If you need support for other HTTP methods you have to implement custom java service task similar to REST Task implementation that supports rest of REST API functionalities.
Comments