Appendix B. Service Tasks

Service task is a task that uses a service, such as a mail service, web service, or another service.

For the convenience of the user, Red Hat JBoss BPM Suite comes with predefined types of service tasks:

  • Web Service task for invoking a web service from a BPMN2 process.
  • Email task for sending emails through the setup mail server.
  • Log task that calls the SystemOutWorkItemHandler class.
  • REST task for sending REST calls.

Note that since the tasks extend the service task, their attributes are implemented as Assignments, DataInputSet, and DataOutputSet, not as separate properties.

In Process Designer, you can find these service tasks in the expanded Object Library on the left.

  1. In Business Central, go to AuthoringProject Authoring.
  2. In Project Explorer, locate the project and the respective process under BUSINESS PROCESSES.
  3. Open the process in Process Designer and expand the Object Library.
  4. Drag and drop the selected service task to the required position on the canvas.

    user guide service tasks

For more information about service task attributes, see Section B.1, “WS Task Attributes”, Section B.2, “Email Task Attributes”, and Section B.3, “REST Task Attributes”.

If you require other task types, implement your task as instructed in Section 4.15, “Domain-Specific Tasks”.

B.1. WS Task Attributes

The Web Service task implements the WebServiceWorkItemHandler class. The Web Service task serves as a web service client with the web service response stored as String. To invoke a Web Service task from a BPMN process, the correct task type must be used.

B.1.1. Use Cases

B.1.1.1. Multiple Parameters

The Web Service task can be used to invoke a web service method with multiple parameters. To do so, the following changes must be made to the BPMN2 process definitions:

  1. In the Process Designer, open the Properties panel and select the Variable Definitions property to create a process variable called pVar with the type Object[].
  2. Select the WS task in the Process Designer and modify the WS Data I/O table by editing Assignments in the Properties panel, or by clicking the Edit Data I/O icon. Change WS Data Input from Parameter:String to Parameter:Object[].
  3. Change the Data Inputs and Assignments section to map pVar to Parameter.
  4. Define an array of WS parameters by selecting the WS task in the Process Designer and adding the following to the On Entry Actions in the Properties panel:

    Object[] params = {"firstParam", "secondParam"}; kcontext.setVariable("pVar",params);
    user guide ws3

    This will allow the web service to be invoked with two parameters.

B.1.1.2. Custom Objects

In addition to primitive object types, the WebService task can use more complex objects, such as Person or Employee.

To use custom objects, the following steps are required:

  1. Create Custom Model objects using either the Data Modeler in Business Central or using an external tool, like Red Hat JBoss Developer Studio.
  2. Use this Custom Model class in one of the WebService tasks.
  3. Generate WSDL for this web service.
  4. Use Red Hat JBoss Developer Studio to generate Java classes from the WSDL.
  5. Create a .jar file that includes the model class generated from the WSDL file. Add kmodule.xml under the META-INF of the .jar.
  6. Upload the .jar to the Artifact Repository. In Business Central, add it to the list of project’s dependencies that includes the configured Web Service task. This Web Service task must have new classes generated, and cannot rely on the original ones.
  7. Modify the project configuration using the Deployment descriptor as follows:

    <kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <kbase name="defaultKieBase" default="true" eventProcessingMode="stream" equalsBehavior="identity" packages="*">
        <ksession name="defaultKieSession" type="stateful" default="true" clockType="realtime">
          <workItemHandlers>
            <workItemHandler type="new org.jbpm.process.workitem.webservice.WebServiceWorkItemHandler(ksession, runtimeManager.getEnvironment().getClassLoader())" name="WebService"/>
          </workItemHandlers>
        </ksession>
      </kbase>
    </kmodule>

    The above configuration utilizes the WebServiceWorkItemHandler.

B.1.1.3. Web Service Task Example

This example demonstrates a process that obtains a weather forecast for given ZIP codes. The process looks as follows:

user guide ws process
  1. In the first human task, the process asks for ZIP codes.
  2. Next, the result of the first human task is transformed into a collection that is used as an input for the service task with multiple instances.
  3. Based on the input collection, the process creates several service task instances for querying the weather forecast service.
  4. Once all the service task instances are completed, the result is logged to the console.
  5. Another human task then shows the weather forecast for the chosen ZIP codes.

After the process instance is started, the user is prompted to select the mode of the service task: synchronous or asynchronous. Note that the difference between the two can be noticeable depending on the particular service.

Input Attributes

Endpoint
The endpoint location of the web service you want to invoke.
Parameter
The object or array to be sent for the operation.
Mode
Can be SYNC, ASYNC, or ONEWAY.
Interface
The name of a service, for example Weather.
Namespace
The namespace of the web service, such as http://ws.cdyne.com/WeatherWS/.
URL
The web service URL, such as http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL.
Operation
The method name to call.

Output Attributes

Result
An object with the result.