Skip to content

cronn/camunda-etc-extension

Repository files navigation

CI Maven Central Apache 2.0

Valid Gradle Wrapper Gradle Status

Cronn Camunda External Task Handler Extension

Extension of https://github.com/camunda/camunda-bpm-platform/tree/master/clients/java

Features

  • easy extraction of process variables as java method arguments
  • less verbosity when executing external task actions

30 seconds tutorial

Instead of

import org.camunda.bpm.client.task.ExternalTask;
import org.camunda.bpm.client.task.ExternalTaskHandler;
import org.camunda.bpm.client.task.ExternalTaskService;

class SampleHandler implements ExternalTaskHandler {
    @Override
    public void execute(ExternalTask externalTask, ExternalTaskService externalTaskService) {
        String myVariable = externalTask.getVariable("myVariable");
        // ...
        externalTaskService.complete(externalTask);
    }
}

write this

import de.cronn.camunda.CurrentExternalTask;
import de.cronn.camunda.ExternalTaskHandler;
import de.cronn.camunda.HandlerMethod;
import de.cronn.camunda.SimpleVariable;

class SampleHandler extends ExternalTaskHandler {
    public SampleHandler() {
        super(null);
    }

    @HandlerMethod
    public void handle(CurrentExternalTask currentExternalTask, 
                       @SimpleVariable("myVariable") String myVariable) {
        // ...
        currentExternalTask.complete();
    }
}

Each handler is expected to have exactly one method annotated with @HandlerMethod. This method has dynamic signature:

  • returns void
  • accepts multiple supported arguments:
    • org.camunda.bpm.client.task.ExternalTask
    • org.camunda.bpm.client.task.ExternalTaskService
    • de.cronn.camunda.CurrentExternalTask
    • process variables as simple values supported by Camunda (annotated with @SimpleVariable)
    • json process variables as object (annotated with @JsonVariable; this requires passing ObjectMapper in handler constructor)

Usage

Add the following Maven dependency to your project:

<dependency>
    <groupId>de.cronn</groupId>
    <artifactId>camunda-etc-extension</artifactId>
    <version>0.4.0</version>
</dependency>

Bonus

There are two more artifacts: de.cronn:camunda-etc-extension-test and de.cronn:camunda-etc-extension-test-spring-boot. They provide infrastructure for easy ExternalTaskHandler integration testing. See: