Flowable getting started series article 45 - Web services tasks

Keywords: Java Flowable oa bpm

1. Description

The Web service task is used to synchronously invoke external Web services.

2. Graphical representation

Web service tasks are visualized in the same way as Java service tasks.

3. XML representation

To use a Web service, we need to import its operations and complex types. This can be done automatically by using the import tag of the WSDL pointing to the Web service:

<import importType="http://schemas.xmlsoap.org/wsdl/"
location="http://localhost:63081/counter?wsdl"
namespace="http://webservice.flowable.org/" />

The previous declaration tells Flowable to import definitions, but it will not create project definitions and messages for you. Suppose we want to call a specific method called prettyPrint, so we need to create corresponding message and item definitions for request and response messages:

<message id="prettyPrintCountRequestMessage" itemRef="tns:prettyPrintCountRequestItem" />
<message id="prettyPrintCountResponseMessage" itemRef="tns:prettyPrintCountResponseItem" />
<itemDefinition id="prettyPrintCountRequestItem" structureRef="counter:prettyPrintCount" />
<itemDefinition id="prettyPrintCountResponseItem" structureRef="counter:prettyPrintCountResponse" />

Before declaring the service task, we must define the BPMN interface and operation that actually references the Web service. Basically, we define the interface and the required operations. For each operation, we reuse the previously defined message and neutralize it. For example, the following declaration defines the counter interface and the prettyPrintCountOperation operation:

<interface name="Counter Interface" implementationRef="counter:Counter">
	<operation id="prettyPrintCountOperation" name="prettyPrintCount Operation"
			implementationRef="counter:prettyPrintCount">
		<inMessageRef>tns:prettyPrintCountRequestMessage</inMessageRef>
		<outMessageRef>tns:prettyPrintCountResponseMessage</outMessageRef>
	</operation>
</interface>

Then, we can declare a Web service task using ## WebService implementation and reference to Web service operation.

<serviceTask id="webService"
name="Web service invocation"
implementation="##WebService"
operationRef="tns:prettyPrintCountOperation">

4. Web service task IO specification

Unless we use simple methods for data input and output correlation (see below), each Web service task needs to declare an IO specification that specifies the input and output of the task. This method is very simple. BPMN 2.0 complains that for our prettyPrint example, we define the input and output sets according to the previously declared project definition:

<ioSpecification>
<dataInput itemSubjectRef="tns:prettyPrintCountRequestItem" id="dataInputOfServiceTask" />
<dataOutput itemSubjectRef="tns:prettyPrintCountResponseItem" id="dataOutputOfServiceTask" />
<inputSet>
<dataInputRefs>dataInputOfServiceTask</dataInputRefs>
</inputSet>
<outputSet>
<dataOutputRefs>dataOutputOfServiceTask</dataOutputRefs>
</outputSet>
</ioSpecification>

5. Web service task data input Association

There are two ways to specify data input associations:

  • Use expressions
  • Use simple methods

To specify a data input association using an expression, we need to define the source project and the target project, and specify the corresponding allocation between the fields of each project. In the following example, we assigned prefix and suffix fields to the item:

<dataInputAssociation>
<sourceRef>dataInputOfProcess</sourceRef>
<targetRef>dataInputOfServiceTask</targetRef>
<assignment>
<from>${dataInputOfProcess.prefix}</from>
<to>${dataInputOfServiceTask.prefix}</to>
</assignment>
<assignment>
<from>${dataInputOfProcess.suffix}</from>
<to>${dataInputOfServiceTask.suffix}</to>
</assignment>
</dataInputAssociation>

On the other hand, we can use a simple method, which is more direct. The sourceRef element is a flowable variable name and the targetRef element is an attribute defined by an item. In the following example, we assign the value PrefixVariable of the variable in the prefix field and the value SuffixVariable of the variable in the suffix field.

<dataInputAssociation>
<sourceRef>PrefixVariable</sourceRef>
<targetRef>prefix</targetRef>
</dataInputAssociation>
<dataInputAssociation>
<sourceRef>SuffixVariable</sourceRef>
<targetRef>suffix</targetRef>
</dataInputAssociation>

6. Web service task data output Association

There are two ways to specify data output associations:
Use expressions
Use simple methods
To use expressions to specify data output associations, we need to define target variables and source expressions. This method is very simple, similar to data input Association:

<dataOutputAssociation>
<targetRef>dataOutputOfProcess</targetRef>
<transformation>${dataOutputOfServiceTask.prettyPrint}</transformation>
</dataOutputAssociation>

Alternatively, we can use a more direct and simple method. The sourceRef element is an attribute defined by an item, and the targetRef element is a flowable variable name. This method is very simple, similar to data input Association:

<dataOutputAssociation>
	<sourceRef>prettyPrint</sourceRef>
	<targetRef>OutputVariable</targetRef>
</dataOutputAssociation>

The above article is from Pangu BPM Research Institute: http://vue.pangubpm.com/
Article translation submission: https://github.com/qiudaoke/flowable-userguide
For more articles, you can focus on WeChat official account:

Posted by leocon on Thu, 04 Nov 2021 04:44:30 -0700