Creating a BPMN Process

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

Creating a BPMN Process

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 WSO2 EI ZIP file from here, and then extract the ZIP file. 
    The path to this folder will be referred to as <EI_HOME> throughout this tutorial.
  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 process and service task

  1. In WSO2 EI Tooling, open the Developer Studio dashboard by clicking the Developer Studio menu and choosing Open Dashboard
  2.  Select BPMN Project and create a new project named HelloWorldBPMN.

    Click Finish.
  3. In Developer Studio Dashboard, select BPMN Diagram.
    Create a file named HelloWorld.bpmn and select the HelloWorldBPMN/src/main/resources/diagrams directory as the parent folder and click Next.
  4. Select the option to create an empty diagram and click Finish.
  5. Add a Start Event, Service Task, and End Event as shown below to create a basic process.
    Link each activity by hovering over the element, selecting the arrow sign and dragging it to the connecting element. 
  6. 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
  7. Create a Java project for HelloWorld Service Task by navigating to File > New > Other and searching for the Java Project Wizard
  8. Create a Project named HelloWorldServiceTask and click Finish.
  9. Adding external JARs:
    1. In the Project Explorer, right click on the project HelloWorldServiceTask and select Properties
    2. In the window that opens up 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, and click Finish.

       
  10. Navigate to File -> New -> Other and search for the Package wizard to create a Java package and create a package named org.wso2.bpmn.helloworld.v1
  11. Navigate to File -> New -> Class to create a Java Class for HelloWorld Service task implementation.

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

  12. Click Finish.

  13. 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 {
    
    	@Override
    	public void execute(DelegateExecution arg0) throws Exception {
    		System.out.println("Hello World ...!!!");
    
    	}
    
    }

     

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

Creating the deployable artifacts

  1. In the Package Explorer, right click on the HelloWorldBPMN project and click Create deployment artifacts
     
    This creates a HelloWorld.bar file in the deployment folder.

  2. Navigate to the <ECLIPSE-WORKSPACE>/HelloWorldServiceTask directory via the command prompt.

    Can't remember the path?

    If you are unsure of the path, right-click HelloWorldServiceTask, and click Properties. The path is listed under Location.

  3. Build the directory to create a compressed JAR file.

    mvn clean install

    The  HelloWorldServiceTask-1.0.0.jar file is created in the <eclipse-workspace>/HelloWorldServiceTask/target directory.

  4. Copy the HelloWorldServiceTask-1.0.0.jar  file to the <EI_HOME>/lib directory.

Deploying the process using EI-Business Process runtime

  1. Start the EI-Business Process runtime by going to <EI_HOME>/wso2/business-process/bin  and using the command line terminal and executing one of the following commands:
    • On Linux/Mac OS:  sh wso2server.sh
    • On Windows:  wso2server.bat --run

  2. In a new browser window or tab, open  https://localhost:9445/carbon/  and log into the EI-Business Process management console using admin for both the username and password.
  3. In the management console, navigate to the main tab, click BPMN, and upload the HelloWorld.bar file (browse it in your Eclipse workspace). 
  4. Log into the BPMN-explorer at https://localhost:9445/bpmn-explorer using admin for both the username and password.
  5. Click Start to start the Hello World Process.
     
  6. In the terminal, the "Hello World ...!!!" string is printed out.