This documentation is for WSO2 Enterprise Integrator version 6.0.0 . View documentation for the latest release in the 6.x.x family and the latest release in the 7.x.x family.

All docs This doc

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

BPMN REST tasks allow you to invoke REST endpoints within your BPMN processes. This can be achieved by adding a Service REST Task and handling the REST invocation part in a level process implementation. BPS 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

...

titlePre-requisites

...

Table of Contents
maxLevel4
minLevel3

Adding a REST task

...

to

...

a

...

process

  1. Create a BPMN process and a BPMN diagram. For instructions, see Creating a BPMN Process.
  2. Drag and drop a REST Task from the tools palette in the place where you need to invoke the endpoint. 
    Drag and drop a REST taskImage Added
  3. Go to the properties Properties panel of Service the REST Task and select the Main config tab. 
  4. Select Java Task as the Task Type.
  5. Add the following fields to the Documentation section by clicking the New buttonEnter values for the following fields appropriately, as shown in the example below.

    Field NameString Value
    ExpressionserviceURL  <REST ENDPOINT URL>method
    Required/Optional
    Service URL 

    URL of the target endpoint


    Optional

    Tip

    You can give this instead of the Service Reference (EPR).

    BasicAuth UsernameUsername if the endpoints are securedRequired
    BasicAuth PasswordPassword for the username aboveRequired
    Service Reference (EPR)

    Registry resource path of the endpoint reference


    Optional

    Tip

    You can give this instead of the Service Reference (EPR).

    HTTP MethodHTTP method (GET
    or POST only) outputVariable
    . POST, PUT or DELETE)Required
    Input PayloadRequest payloadOptional
    Output Variable nameName of the variable to save the response
     
    Optional
    basicAuthUsernameUsername if the endpoints are secured basicAuthPasswordPassword for the username above inputRequest payload headersheader values in the format "headerName1:headerValue1,headerName2:header Value2" 

...

  1. Output Variable Mappings

    Variable mappings to map JSON response content into multiple variables

    Code Block
    languagejava
    var2:customer.name,var3:item.price
    Optional
    Transport headers

    Header values in the format

    Code Block
    languagejs
    {"headerName1":"headerValue1","headerName2":"header Value2"}
    Optional

    Image Added

The following configuration provides an example definition to use as the REST task.

Code Block
languagexml
<serviceTask id="servicetask1InvokeRESTEndpoint" 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 ethodmethod}
            </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{"headerName1":"headerValue1","headerName2":"header Value2"}]]>
            </activiti:string>
        </activiti:field>
    </extensionElements>
</serviceTask>

Anchor
#json
#json
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 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. The following code block provides an example definition with JSON input. 

Code Block
languagexml
<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.

Info

To change the REST endpoint after process deployment:

On

, give the registry location of the service reference in the Service Reference (EPR) field on the  Main config  tab of the

properties

Properties panel for the

service

REST 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). 

. 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.

Code Block
<bean id="restClientConfiguration">
        <property name="maxTotalConnections" value="200"/>
        <property name="maxConnectionsPerRoute" value="200"/>
        <property name="connectionTimeout" value="12000"/>
        <property name="socketTimeout" value="12000"/>
</bean>