This documentation is for WSO2 Enterprise Integrator version 6.3.0 . View documentation for the latest release in the 6.x.x family and the latest release in the 7.x.x family.
Working with BPMN Task Artifacts - Enterprise Integrator Documentation - WSO2 Documentation

All docs This doc
||
Skip to end of metadata
Go to start of metadata

You can work with the following BPMN Task artifacts in the Business Process profile of WSO2 EI.

REST Task

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

  1. Create a BPMN process and a BPMN diagram. For instructions, see Working with Service Tasks.
  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 task
  3. Go to the Properties panel of the REST Task and select the Main config tab. 
  4. Enter values for the following fields appropriately, as shown in the example below.

    Field NameString ValueRequired/Optional
    Service URL 

    URL of the target endpoint.


    Optional

    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

    You can give this instead of the Service URL.

    HTTP MethodHTTP method (GET. POST, PUT or DELETE)Required
    Input PayloadRequest payloadOptional
    Output Variable nameName of the variable to save the responseOptional
    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>

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>

SOAP Task

BPMN SOAP tasks allow you to invoke SOAP endpoints within your BPMN processes. This can be achieved by adding a SOAP Task and handling the SOAP 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 SOAP task to a process

  1. Create a BPMN process and a BPMN diagram. For instructions, see Working with Service Tasks.
  2. Drag and drop a SOAP Task from the tools palette in the place where you need to invoke the endpoint. 
    Drag and drop a SOAP task
  3. Go to the Properties panel of the SOAP Task and select the Main config tab. 
  4. Enter values for the following fields appropriately, as shown in the example below.

    Field NameString ValueRequired/Optional
    Service URL URL of the target endpoint

    Optional

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

    Service Reference (EPR)

    Registry resource path of the endpoint reference.


    Optional

    You can give this instead of the Service URL.

    Input PayloadRequest payloadOptional
    SOAP HeadersSOAP header block, which is attached to the SOAP header when creating the SOAP requestOptional
    SOAP versionSoap version to be used when creating the SOAP request (i.e., SOAP11 or SOAP12)Required
    HTTP ConnectionControl options for the current connection. ('keep-alive' is the the default value.)Optional
    HTTP Transfer EncodingThe form of encoding, which is used to safely transfer the entity to the userOptional
    Output Variable nameName of the variable to save the responseRequired
    Transport headers

    Header values in the format

    "headerName0":"headerValue0","headerName1":"header Value2"
    Optional

    SOAP task properties

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

<definitions
	xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	xmlns:activiti="http://activiti.org/bpmn"
	xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
	xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
	xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
	<process id="myProcess" name="My process" isExecutable="true">
		<serviceTask id="servicetask1" name="SOAP Task" activiti:class="org.wso2.carbon.bpmn.extensions.soap.SOAPTask" activiti:extensionId="org.wso2.developerstudio.bpmn.extensions.soapTask.SOAPTask">
			<extensionElements>
				<activiti:field name="serviceURL">
					<activiti:expression>http://10.0.3.1:9773/soapSample1_1.0.0/services/soap_sample1/${method}</activiti:expression>
				</activiti:field>
				<activiti:field name="payload">
					<activiti:string>&lt;m:getFullQuote
						xmlns:m="http://services.samples/xsd"&gt;
                                &lt;m:request&gt;
                                &lt;m:symbol&gt;IBM&lt;/m:symbol&gt;
                                &lt;/m:request&gt;
                                &lt;/m:getFullQuote&gt;
					</activiti:string>
				</activiti:field>
				<activiti:field name="headers">
					<activiti:string>&lt;headers:ServerHeader
						xmlns:headers="http://www.roguewave.com/examples/webservice/headers"
         env:mustUnderstand="0"&gt;MyValue: From the server&lt;/headers:ServerHeader&gt;
					</activiti:string>
				</activiti:field>
				<activiti:field name="soapVersion">
					<activiti:string>soap11</activiti:string>
				</activiti:field>
				<activiti:field name="httpConnection">
					<activiti:string>keep-alive</activiti:string>
				</activiti:field>
				<activiti:field name="outputVariable">
					<activiti:string>output</activiti:string>
				</activiti:field>
				<activiti:field name="soapAction">
					<activiti:string>urn:sayHello</activiti:string>
				</activiti:field>
				<activiti:field name="transportHeaders">
					<activiti:string>&lt;p1:Code
						xmlns:p1="http://www.XYZ.com/XSD"&gt;XYZ&lt;/p1:Code&gt;
					</activiti:string>
				</activiti:field>
			</extensionElements>
		</serviceTask>
	</process>
	<bpmndi:BPMNDiagram id="BPMNDiagram_myProcess">
		<bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess">
			<bpmndi:BPMNShape bpmnElement="servicetask1" id="BPMNShape_servicetask1">
				<omgdc:Bounds height="55.0" width="105.0" x="340.0" y="60.0"></omgdc:Bounds>
			</bpmndi:BPMNShape>
		</bpmndi:BPMNPlane>
	</bpmndi:BPMNDiagram>
</definitions>

Email Task

The Email Task allows you to send an email within a BPMN Process. It is configured with the following properties. 

Field NameMandatoryDescription
ToYesThe email address of the intended recipient of the email. Multiple recipients can be specified as comma-separated email addresses.
FromNoThe email address of the sender. If this field is not specified, the default email address specified in the activiti.xml file will be used.
SubjectNoSubject of the email.
CCNoThe email addresses of the carbon copy receivers of the email. Multiple recipients are separated by commas.
BccNoThe email addresses of the blind carbon copy receivers of the e-mail. Multiple recipients are separated by commas.
CharsetNoCharset of the email can be changed.
HtmlNoThe content of email is in HTML format.
TextNoContent is in non-HTML format.

Sample Email Server Configuration

The Activiti engine sends e-mails using an external mail server. The following steps guide you through a sample email server configuration for the Email task. 

  1. Set the following properties in the activiti.xml configuration file found in the <EI_HOME>/wso2/business-process/conf directory. The following code block provides a sample of these settings using the Gmail configuration settings. 

    <property name="mailServerHost" value="smtp.gmail.com"/>
    <property name="mailServerPort" value="456"/>
    <property name="mailServerDefaultFrom" value="mailtask@gmail.com"/>
    <property name="mailServerUseSSL" value="true"/>
    <property name="mailServerUsername" value="mailtask@gmail.com"/>
    <property name="mailServerPassword" value="mailtask123"/>
    PropertyDescription
    • <property name="mailServerDefaultFrom" value=”email of the sender”>
    This specifies the default address of the sender. If a sender is not specified in the sender field as a mail task property, the email address specified here will be used instead.
    • <property name="mailServerUsername" value="mailtask@gmail.com"/>
    • <property name="mailServerPassword" value="mailtask123"/>
    Specifies the credentials of the sender for authentication purposes. Here, you should include the email addressandit'scorrespondingpasswordwhich you specified in the “From” field of the mail task.
    • Port 456 (SSL required):<property name="mailServerUseSSL" value="true"/>
    • Port 587 (TLS required):<property name="mailServerUseTLS" value="true"/>
    Specifiy only one of these two properties in order to specify whether the mail server should use SSL or TLS.

    If you are using Gmail to try out this scenario, enable IMAP access for Gmail. See Enable IMAP settings in Gmail for more information.

    If you receive an authentication error, you may have to adjust your account access settings in Gmail as well. See Allowing less secure apps to access your account for more information.

  2. Copy the following jar files into the <EI_HOME>/lib directory and restart the server. 

Script Task

The Activiti engine supports script tasking via groovy and JavaScript. JavaScript gets executed via the Rhino Engine and Groovy gets executed by the Groovy Engine.

JDK comes with default support for JavaScript. On the other hand, to execute the groovy, the .jar files responsible for the Groovy Engine have to be added to the <EI_HOME>/wso2/lib/endorsed directory. The .jar file can be download from here.

Task Listeners

You can use task listeners to extend BPMN capabilities to handle events via business processes.

The Activiti API provides extension points that can be used as custom implementations that you can trigger where necessary. Task listener is one such extension point.

A task listener can be used when you need to trigger a custom implementation upon the occurrence of a particular task.

To create a task listener you need to write a java class that implements the org.activiti.engine.delegate.TaskListener interface. In the java class, you need to add the listener logic inside the notify method as follows:

package org.wso2.testbpmn;

import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;

public class FirstTaskListener implements TaskListener {
    @Override
    public void notify(DelegateTask delegateTask) {
   	 delegateTask.setDescription("First Task Listener");

    }
}

Note

For example, if you want to log the time that a task starts, you can use a logger inside the task listener to print the start time of a task. 

Once you write the Java class, you can build the project containing the class, add the built .jar file inside the <EI_HOME>/lib directory, and restart the server.

In the process definition you can point to the created class using an eventListener as follows:

<userTask id="myTask" name="My Task" >
  <extensionElements>
    <activiti:taskListener event="create" class="org.wso2.testbpmn.FirstTaskListener"/>
  </extensionElements>
</userTask>

If you look at the process definition given above, you will see that there is a parameter named event. You can use the event parameter to define the event that should trigger the task listener class.

For more information, see Task Listener in the Activiti User Guide.

For information on other event listeners that allow you to handle various events from business processes you create, see Event handlers in the Activiti User Guide.

  • No labels