AnsweredAssumed Answered

Adding task completion listener for Service task

Question asked by malintha on Jul 8, 2016

My requirement is adding task completion handler for a service task. I have written following Service task parse handler and . If I use this parse handler for a user task it is working fine. But when I deploy a BPMN (my server run this parse handler), this gives me null pointer exceptions as there is no taskdefinition for service tasks.

(TaskDefinition) bpmnParse.getCurrentActivity().getProperty("taskDefinition")

What is the correct way of doing this ?

public class MyServiceTaskParseHandler extends AbstractBpmnParseHandler {

private static final Log log =


    protected Class<? extends BaseElement> getHandledType() {return ServiceTask.class;

    protected void executeParse(BpmnParse bpmnParse, BaseElement element) {

        TaskDefinition taskDefinition = (TaskDefinition) bpmnParse.getCurrentActivity().getProperty("taskDefinition");

        // We have to check if data publishing listener has already been associated at server startup
        TaskListener taskCompletionListener = null;
        List<TaskListener> completionListeners = taskDefinition.getTaskListener(TaskListener.EVENTNAME_COMPLETE);
        if (completionListeners != null) {
            for (TaskListener listener : completionListeners) {
                if (listener instanceof TaskCompletionListener) {
                    taskCompletionListener = listener;
        if (taskCompletionListener == null) {
            if (log.isDebugEnabled()) {
                log.debug("Adding data publishing listener to task: " + taskDefinition.getKey());
            taskDefinition.addTaskListener(TaskListener.EVENTNAME_COMPLETE, new TaskCompletionListener());