Extension of https://github.com/camunda/camunda-bpm-platform/tree/master/clients/java
- easy extraction of process variables as java method arguments
- less verbosity when executing external task actions
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.ExternalTaskorg.camunda.bpm.client.task.ExternalTaskServicede.cronn.camunda.CurrentExternalTask- process variables as simple values supported by Camunda (annotated with
@SimpleVariable) - json process variables as object (annotated with
@JsonVariable; this requires passingObjectMapperin handler constructor)
Add the following Maven dependency to your project:
<dependency>
<groupId>de.cronn</groupId>
<artifactId>camunda-etc-extension</artifactId>
<version>0.4.0</version>
</dependency>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:
- for non Spring usage:
EmbeddedCamundaTestandSampleEmbeddedCamundaTest - for Spring Boot use case:
SpringEmbeddedCamundaTestandSampleSpringEmbeddedCamundaTest