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
- 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:
OS Home directory Mac OS
Select and download the relevant Enterprise Integrator tooling ZIP file depending 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.
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.
- Create a new Maven Project with the below details. For instructions, see Creating a Maven Project.
- Group Id:
- Artifact Id :
- Java Package Name:
- Java Class Name:
- Interface of the Java Class:
- Group Id:
Replace the default content with the below to implement the business logic of the Task Listener in the
TaskListenerV1.javafile as shown below.
Add the following dependency to the
pom.xmlfile of the Service Task as shown below.
- Build the Maven Project and add the built JAR file to the
<EI_HOME>/libdirectory 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.
- Create a new BPMN project named TaskListener. For instructions, see Creating a BPMN Project.
- Create a BPMN Diagram named TaskListener.bpmn. For instructions, see Creating the BPMN Diagram.
- Click anywhere on the canvas, go to the Properties tab, and fill in the following details:
Hello World Process
Namespace : http://wso2.org/bpmn/helloworld
- To implement the order approval process, drag and drop a StartEvent, a UserTask, and an End Event to the canvas.
- Click on the User Task and set the Name as Change Task Description in the General section of the Properties tab.
- Click on the User Task and set the Assignee as admin in the Main config section of the Properties tab.
- Click on the User Task and click New in the Listeners section of the Properties tab.
- Enter the below details and click OK.
- Event: create
- Type: Java class
- Class: Click Select Class, type select
org.wso2.tasklistener.TaskListenerV1in the search bar and select it.
This adds the Task Lister to the User Task as shown in the below configuration.
eventparameter of the User Task to define the event that should trigger the Task Listener class.
Deploying the artifacts
- For instructions on creating the deployable artifacts, see Creating the deployable archive.
- For instructions on deploying them, see Deploying BPMN artifacts.
Testing the output
Follow the steps below to test the output.
If you did not start the business process profile previously, you need to start it.
- Log in to the BPMN-explorer at https://localhost:9445/bpmn-explorer using
adminfor both the username and password.
- Click PROCESSES in the top menu, and click the Start option of the task Listener process.
- Click Close in the message, which pops up.
- Click TASKS in the top menu, and click My Tasks.
- Click on the new Change Task Description Task. You view the description changed to
"First Task Listener"as shown below.