This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Java Service Task

Note that WSO2 EI is shipped with the following changes to what is mentioned in this documentation:

  • <PRODUCT_HOME>/repository/samples/ directory that includes all Business Process profile samples and their artifacts is changed to <EI_HOME>/samples/business-process/.

The .bar file relevant for this sample is the SimpleCalculator.bar found in the <BPS-HOME>/repository/samples/bpmn directory. 

Flow of the sample

In this sample scenario, a service task is executed to perform a calculation based on the user input.

  1. The clerk user is provided with a form to input two numbers.
  2. Once the user completes providing input, an addition calculation is performed by a service task (SimpleCalculator.addNumbers) and the final result is displayed.
  3. Finally, the clerk user can confirm the provided result from the 'User Task' created.

The following code block shows the content of the addNumbers.java class, that is used in this service task.

package performCalculationBPMN;
 
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
import java.lang.Long;
 
public class NumberAdder implements JavaDelegate {
 
    public void execute(DelegateExecution execution) throws Exception {
 
        int number1 = Integer.parseInt((String) execution.getVariable("number1"));
        int number2 = Integer.parseInt((String) execution.getVariable("number2"));
        int result = number1 + number2;
        execution.setVariable("result", "" + result);
 
    }
}

By implementing the ‘execute’ method of the JavaDelegate interface, the input provided by the user task (add input) can be rendered. Finally, after the calculation is performed, the result is set to variable ‘result’, which will be used in the ‘Confirm answer’ user task, to display the result.

Running the sample

  1. Follow the steps in Deploying BPMN Samples to deploy the sample using the WSO2 BPS management console. 
  2. Login to the BPMN-explorer using clerk/clerk credentials. 
  3. Select the PROCESSES tab to view the deployed sample. 
  4. Click Start and fill the form that appears with the numbers that are to be calculated. 
  5. The result will be displayed under the MY TASKS tab as seen below.Â