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

Before you begin,

  1. Install Oracle Java SE Development Kit (JDK) version 1.8.* and set the JAVA_HOME environment variable.
  2. 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> through out this tutorial.
  3. 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> through out 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 names HelloWorld.bpmn and select the HelloWorldBPMN/src/main/resources/diagrams directory as the parent folder and click Next.

    Select the option to create an empty diagram and click Finish.
  4. Add a Start event, Service Task and End Event as seen 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. 

    Select the Properties tab and fill in the following details:
    Id               : helloworld
    Name         : Hello World Process
    Namespace: http://wso2.org/bpmn/helloworld
  5. Create a Java project for HelloWorld Service Task by navigating to File -> New -> Other and searching for the Java Project Wizard


    Create a Project named HelloWorldServiceTask and click Finish.
  6.  In the Project Explorer, r ight click on the project HelloWorldServiceTask and select Properties. In the window that opens up go to the Libraries tab and click on Add External JARs. Select    activiti-all_5.21.0.wso2v1.jar  file from  <EI_Home>/wso2/components/plugins  directory and click Finish.

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

    Click Finish.

  9. Implement HelloWorld Service Task following business logic in the HelloWorldServiceTaskV1.java file as seen 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 ...!!!");
    
    	}
    
    }

     

  10. 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. Fo the Class name field, select HelloWorldServiceTaskV1 and save all changes.

    Best Practice

    When you create a Java Service Task, ensure that you version your java package or class 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 also when you want to change the 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. Go to File -> New -> Other and search for the Java Library Project wizard to create a WSO2 Java Library project.

    Create a Project named HelloWorldServiceTask_Artifact and click Next.
  2. Add the HelloWorldServiceTask Java project from workspace and click Finish
  3. Go to File -> New -> Composite Application Project to create a new Composite Application Project. 

    Select HelloWorldServiceTask_Artifact as a dependency.

    Select Business Process Server as HelloWorldServiceTask_Artifact's server role.
  4. Right-click on the HelloWorldServiceTask_CAR project and select Export Composite Application Project. Select an export destination and click Finish.  
  5. In the Package Explorer, right click on HelloWorldBPMN project and select Create deployment artifacts. This will create a HelloWorld.bar file in the deployment folder.

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. Navigate to Home -> Manage -> Carbon Applications ->Add. Upload the .CAR file to deploy it as seen below. 
     
    You will see the following logs in the terminal after successful deployment. 
    logs of starting the server
  4. In the management console, navigate to Home -> Manage -> Processes ->Add -> BPMN and upload the HelloWorld.bar file (browse it in your Eclipse workspace) to deploy it as seen below. 
  5. Log into the BPMN-explorer at https://localhost:9445/bpmn-explorer using admin/admin credentials and start the Hello World Process.
     
  6. In the terminal you will see the "Hello World ...!!!" string printed out.