This documentation is for WSO2 Enterprise Integrator version 6.4.0 . View documentation for the latest release.
Working with Service Tasks - WSO2 Enterprise Integrator 6.4.0 - WSO2 Documentation

All docs This doc
||
Skip to end of metadata
Go to start of metadata

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,

  1. Install Oracle Java SE Development Kit (JDK) version 1.8.* and set the JAVA_HOME environment variable.
  2. Install Maven. For more information, see Installation Prerequisites.
  3. Download the product installer from here, and run the installer.
    Let's call the installation location of your product the <EI_HOME> directory. This is located in a place specific to your OS as shown below:
    OSHome directory
    Mac OS/Library/WSO2/EnterpriseIntegrator/6.4.0
    WindowsC:\Program Files\WSO2\EnterpriseIntegrator\6.4.0\
    Ubuntu/usr/lib/wso2/EnterpriseIntegrator/6.4.0
    CentOS/usr/lib64/EnterpriseIntegrator/6.4.0
  4. Select and download the relevant EI tooling ZIP file based on your operating system from here and then extract the ZIP file.
    The path to this folder will be referred to as <EI_TOOLING> throughout this tutorial.

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

  1. Create a new BPMN project named HelloWorldBPMN. For instructions, see Creating a BPMN Project.
  2. Create a BPMN Diagram named HelloWorld.bpmn. For instructions, see Creating the BPMN Diagram.
  3. 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.

  4. 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.

  1. Create a Maven project for the HelloWorld Service Task by navigating to File > New > Other and searching for the Maven Project Wizard. Click Next.
  2. Select Create a simple project (skip archetype section) option and click Next.
  3. Enter the following details and click Finish.
    Group Id:org.wso2.bpmn
    Artifact IdHelloWorldServiceTask

  4. 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.


  5. Adding external JARs to the Service Task:
    1. In the Project Explorer, right click on the project HelloWorldServiceTask and select Properties
    2. In the window that opens up click, Java Build Path, go to the Libraries tab and click on Add External JARs
    3. Select the activiti-all_5.21.0.wso2v1.jar file from the <EI_Home>/wso2/components/plugins directory.
    4. Click Open and then click Apply and Close.
Creating the Java Package for the Maven Project
  1. Navigate to File -> New -> Other and search for the Package wizard to create a Java package and click Next.
  2. Create a package named org.wso2.bpmn.helloworld.v1, and click Finish.
Creating the Java Class for the Maven Project
  1. Navigate to File -> New -> Class to create a Java Class for HelloWorld Service task implementation.

  2. Create a class named HelloWorldServiceTaskV1 and add org.activiti.engine.delegate.JavaDelegate interface to your class.

  3. Click Finish.

  4. 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 ...!!!");
    
    	}
    
    } 
  5. Configure HelloWorld Service Task Class name. 

    1. To do this go to your HelloWorld BPMN diagram and select the Hello World Service Task box in the diagram.

    2. Access the Properties tab and select the Main Config tab.
    3. For the Class name field, select HelloWorldServiceTaskV1 and save all changes.

      Best Practice

       Click here for best practices...

      When you create a Java Service Task, ensure that you version your Java package or classes by adding a version number in the Java Package path or Class name. This is useful when you have multiple versions of the same workflow, and when you want to change Service task business logic in each process version. Having versions avoids business logic changes in service tasks from affecting new or running process instances that are created from old process versions. 

      The following example demonstrates why it is important to version your Java package:

      Version 1
      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 {
      
      	@Override
      	public void execute(DelegateExecution arg0) throws Exception {
      		System.out.println("Hello World ...!!!");
      
      	}
      
      }
      Version 2
      package org.wso2.bpmn.helloworld.v2;
      
      import org.activiti.engine.delegate.DelegateExecution;
      import org.activiti.engine.delegate.JavaDelegate;
      
      /**
      * Hello World Service Task - Version 2.
      */
      
      public class HelloWorldServiceTaskV2 implements JavaDelegate {
      
      @Override
        public void execute(DelegateExecution arg0) throws Exception {
        // In version 2, Hello World string is improved.
        System.out.println("Hello World ...!!! This is Second version of HelloWorld BPMN process.");
        }
      
      } 

      Note

      If you want to use business rules in a BPMN process, you can create a sequence with the Rule Mediator 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.
  6. 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

  1. For instructions on creating the deployable artifacts, see Creating the deployable archive.
  2. For instructions on deploying them, see Deploying BPMN artifacts.

Deploying artifacts of the Maven Project

  1. 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>

  2. 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. The  HelloWorldServiceTask-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.

  3. Copy the HelloWorldServiceTask-1.0.0.jar file to the <EI_HOME>/lib directory.
  4. Restart the Business Process profile of WSO2 EI.

Testing the output

Follow the steps below to test the output.

  1. Log into the BPMN-explorer at https://localhost:9445/bpmn-explorer using admin for both the username and password.
  2. Click Start to start the Hello World Process.
  3. In the terminal, the "Hello World ...!!!" string is printed out. 
  • No labels