Search

Chapter 31. WS Task

download PDF

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.

31.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, click 3897 to open the Properties panel.
  2. Select the Variable Definitions property and create a process variable called pVar with the custom type Object[].
  3. Click the WS task in the Process Designer and click 3897 to open the Properties panel.
  4. Click getting started guide 6563 next to the Assignments property.
  5. Change the Parameter input variable from String to Custom and enter Object[]. Select pVar in the Source field. Click Ok.
  6. In the property panel of the WS task, enter the following in the On Entry Actions property:

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

31.2. Custom Objects

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

To use custom objects:

  1. Create a custom model object 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 WS 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.

31.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.
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.