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
- 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.
- 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 Service Task and select the Main config tab.
- Select Java Task as the Task Type.
Add the following fields to the Documentation section by clicking the New button.
Field Name String Value Expression serviceURL <REST ENDPOINT URL> method HTTP method (GET or POST only) outputVariable Name of the variable to save response basicAuthUsername Username if the endpoints are secured basicAuthPassword Password for the username above input Request payload headers header values in the format "headerName1:headerValue1,headerName2:header Value2"
The following code block provides an example service task definition to use as the REST task.
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.
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:
- On the Main config tab of the properties panel for the service task, add a field with the name "serviceRef" instead of the "serviceURL" field mentioned in step 4 above.
- Give the registry location of the service reference as the String Value (this kind of configuration has been used in the above example with the JSON payload).