Working with Service Tasks
Let's take a simple HelloWorld scenario where there is a BPMN process that prints out a 'Hello World!' message when a process instance is initiated. In this tutorial, you create a BPMN process using the WSO2 Enterprise Integrator (WSO2 EI) Tooling.
Before you begin,
- Download the product installer from here, and run the installer.
Let's call the installation location of your product the<EI_HOME>
directory.Note that if you used the product installer to install your product, the
<EI_HOME>
is located in a place specific to your OS as shown below:OS Home directory Mac OS /Library/WSO2/EnterpriseIntegrator/6.3.0
Windows C:\Program Files\WSO2\EnterpriseIntegrator\6.3.0\
Ubuntu /usr/lib/wso2/EnterpriseIntegrator/6.3.0
CentOS /usr/lib64/EnterpriseIntegrator/6.3.0
Select and download the relevant WSO2 EI tooling ZIP file based on your operating system from here and then extract the ZIP file.
The path to this folder is referred to as<EI_TOOLING>
throughout this tutorial.Getting an error message? See the troubleshooting tips given under Installing Enterprise Integrator Tooling.
Creating the artifacts
Follow the steps below to create the requires artifacts.
Creating the BPMN project
- Create a new BPMN project named HelloWorldBPMN. For instructions, see Creating a BPMN Project.
- Create a BPMN Diagram named HelloWorld.bpmn. For instructions, see Creating the BPMN Diagram.
Add a Start Event, Service Task, and End Event and connect them as shown below to create a basic process.
You view the Create connection option when you hover the mouse pointer on an artifact. Click on the arrow, drag it and drop it on the artifact to which you want to connect it.
- Click anywhere on the canvas, go to the Properties tab, and fill in the following details:
Id :helloworld
Name :Hello World Process
Namespace:http://wso2.org/bpmn/helloworld
Creating the Maven project
The BPMN Project includes only the model of the Service Task. You need to create the implementation of it separately in a Maven Project. Follow the steps below to create the Maven Project for the Service Task.
- Create a Maven project for the HelloWorld Service Task by navigating to File > New > Other and searching for the Maven Project Wizard. Click Next.
- Select Create a simple project (skip archetype section) option and click Next.
- Enter the following details and click Finish.
Group Id:org.wso2.bpmn
Artifact Id:HelloWorldServiceTask
Click Open Perspective on the below message, which pops up.
You will not get this message if you are already in the Activiti perspective. You can view the current perspective from the below tab.
- Adding external JARs to the Service Task:
- In the Project Explorer, right click on the project HelloWorldServiceTask and select Properties.
- In the window that opens up click, Java Build Path, go to the Libraries tab and click on Add External JARs.
- Select the
activiti-all_5.21.0.wso2v1.jar
file from the<EI_Home>/wso2/components/plugins
directory. - Click Open and then click Apply and Close.
Creating the Java Package for the Maven Project
- Navigate to File -> New -> Other and search for the Package wizard to create a Java package and click Next.
- Create a package named
org.wso2.bpmn.helloworld.v1
, and click Finish.
Creating the Java Class for the Maven Project
Navigate to File -> New -> Class to create a Java Class for HelloWorld Service task implementation.
Create a class named HelloWorldServiceTaskV1 and add
org.activiti.engine.delegate.JavaDelegate
interface to your class.Click Finish.
Implement the business logic of the HelloWorld Service Task in the
HelloWorldServiceTaskV1.java
file as shown below.package org.wso2.bpmn.helloworld.v1; import org.activiti.engine.delegate.DelegateExecution; import org.activiti.engine.delegate.JavaDelegate; /** * Hello World Service Task- V1. */ public class HelloWorldServiceTaskV1 implements JavaDelegate { public void execute(DelegateExecution arg0) throws Exception { System.out.println("Hello World ...!!!"); } }
Configure HelloWorld Service Task Class name.
To do this go to your HelloWorld BPMN diagram and select the Hello World Service Task box in the diagram.
- Access the Properties tab and select the Main Config tab.
For the Class name field, select
HelloWorldServiceTaskV1
and save all changes.Best Practice
Note
If you want to use business rules in a BPMN process, you can create a /wiki/spaces/EI6xx/pages/49612916 with the /wiki/spaces/EI6xx/pages/49612751 via the ESB Profile, expose it as a service, and then use the BPMN REST task or BPMN SOAP task to invoke the service.
Alternatively, you can use a BPMN service task to perform business rule validations.
Press Ctrl+S to save all your artifacts.
Deploying the artifacts
Follow the steps below to deploy the artifacts.
Deploying artifacts of the BPMN Project
- For instructions on creating the deployable artifacts, see Creating the deployable archive.
- For instructions on deploying them, see Deploying BPMN artifacts.
Deploying artifacts of the Maven Project
Add the following dependency to the
pom.xml
file of the Service Task as shown below.<packaging>jar</packaging> <dependencies> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-engine</artifactId> <version>5.17.0</version> </dependency> </dependencies>
In the Package Explorer, right click on the HelloWorldServiceTask, and click Run as → 7 Maven install.
This builds the
<ECLIPSE-WORKSPACE>/HelloWorldService
Task directory and creates a compressed JAR file. TheHelloWorldServiceTask-1.0.0.jar
file is created in the<eclipse-workspace>/HelloWorldServiceTask/target
directory.If you are unsure of the path, right-click
HelloWorldServiceTask
, and click Properties. The path is listed under Location.
You can view is the build is successful in the logs printed on the
pom.xml
tab.- Copy the
HelloWorldServiceTask-1.0.0.jar
file to the<EI_HOME>/lib
directory. - Restart the Business Process profile of WSO2 EI.
Testing the output
Follow the steps below to test the output.
- Log into the BPMN-explorer at https://localhost:9445/bpmn-explorer using
admin
for both the username and password. - Click Start to start the Hello World Process.
- In the terminal, the
"Hello World ...!!!"
string is printed out.