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.
Let's get started! This tutorial includes the following sections:
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.
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:HelloWorldServiceTaskClick Open Perspective on the below message, which pops up.
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.jarfile from the<EI_Home>/wso2/components/pluginsdirectory.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.JavaDelegateinterface to your class.Click Finish.
Implement the business logic of the HelloWorld Service Task in the
HelloWorldServiceTaskV1.javafile 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
HelloWorldServiceTaskV1and save all changes.
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.xmlfile 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>/HelloWorldServiceTask directory and creates a compressed JAR file. TheHelloWorldServiceTask-1.0.0.jarfile is created in the<eclipse-workspace>/HelloWorldServiceTask/targetdirectory.Copy the
HelloWorldServiceTask-1.0.0.jarfile to the<EI_HOME>/libdirectory.Restart the Business Process profile of WSO2 EI.