This documentation is for WSO2 Enterprise Integrator version 6.5.0 . View documentation for the latest release in the 6.x.x family and the latest release in the 7.x.x family.

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

The Activiti API provides extension points to create custom implementations that you can trigger where necessary. Task Listener is one such extension point, which you can use to trigger a custom implementation upon the occurrence of a particular task. For more information, go to Task Listener in the Activiti User Guide. Also, for information on other event listeners that allow you to handle various events in business processes, go to Event handlers in the Activiti User Guide.

The sections below demonstrate how to use Task Listeners to extend BPMN capabilities to handle events via business processes.

Before you begin,

  • Install Oracle Java SE Development Kit (JDK) version 1.8.* and set the JAVA_HOME environment variable.
  • Download the product installer from here, and run the installer.
    Let's call the installation location of your product the <EI_HOME> directory.

    If you installed the product using the installer, this is located in a place specific to your OS as shown below:

    OSHome directory
    Mac OS/Library/WSO2/EnterpriseIntegrator/6.5.0
    WindowsC:\Program Files\WSO2\EnterpriseIntegrator\6.5.0\

Creating the Task Listener implementation

In the BPMN Explorer, the default description of a Task, which is created by a Process is displayed as "Description not available".

In this guide, you create a custom Task Listener to change the description whenever a Task is created by the process you deploy. Follow the steps below to create the Task Listener implementation as a Maven Project.

Creating the Maven Project

Follow the steps below to create the Maven Project to create the Task Listener implementation.

  1. Create a new Maven Project with the below details. For instructions, see Creating a Maven Project.
    • Group Id: org.wso2.bpmn
    • Artifact Id TaskListenerMaven
    • Java Package Name: org.wso2.tasklistener
    • Java Class Name:  TaskListenerV1
    • Interface of the Java Class: org.activiti.engine.delegate.TaskListener
  2. Replace the default content with the below to implement the business logic of the Task Listener in the file as shown below.

    package org.wso2.tasklistener;
    import org.activiti.engine.delegate.DelegateTask;
    import org.activiti.engine.delegate.TaskListener;
    public class TaskListenerV1 implements TaskListener {
    	 public void notify(DelegateTask delegateTask) {
    	     delegateTask.setDescription("First Task Listener");

  3. Add the following dependency to the pom.xml file of the Service Task as shown below.


  4. Build the Maven Project and add the built JAR file to the <EI_HOME>/lib directory to deploy it. For instructions, see  Deploying artifacts of the Maven Project.

Creating the BPMN Project

Follow the steps below to create a BPMN Project with a User Task to implement the Task Listener.

  1. Create a new BPMN project named TaskListener. For instructions, see Creating a BPMN Project.
  2. Create a BPMN Diagram named TaskListener.bpmn. For instructions, see Creating the BPMN Diagram.
  3. Click anywhere on the canvas, go to the  Properties  tab, and fill in the following details:
    Id                :  helloworld
    Name          :  Hello World Process
  4. To implement the order approval process, drag and drop a StartEvent, a UserTask, and an End Event to the canvas. 
  5. Click on the  User Task  and set the Name as Change Task Description in the  General  section of the  Properties  tab.

  6. Click on the User Task and set the Assignee as admin in the Main config section of the Properties tab.

  7. Click on the User Task and click New in the Listeners section of the Properties tab.
  8. Enter the below details and click OK.
    • Event: create
    • Type: Java class
    • Class: Click Select Class, type  select org.wso2.tasklistener.TaskListenerV1 in the search bar and select it.

    This adds the Task Lister to the User Task as shown in the below configuration.

    <userTask id="myTask" name="My Task" >
        <activiti:taskListener event="create" class="org.wso2.testbpmn.FirstTaskListener"/>

     Use the event parameter of the User Task to define the event that should trigger the Task Listener class.

Deploying the artifacts

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

Testing the output

Follow the steps below to test the output.

  1. If you did not start the business process profile previously, you need to start it.

    Open a terminal and execute the following command:


    Go to Start Menu -> Programs -> WSO2 -> Enterprise Integrator 6.4.0 Business Process. This will open a terminal and start the business process profile.

  2. Log in to the BPMN-explorer at https://localhost:9445/bpmn-explorer using admin for both the username and password.
  3. Click PROCESSES in the top menu, and click the Start option of the task Listener process.

  4. Click Close in the message, which pops up.
  5. Click TASKS in the top menu, and click My Tasks.
  6.  Click on the new Change Task Description Task. You view the description changed to "First Task Listener" as shown below.
  • No labels