Month: January 2016

Dropwizard, CDI and Activiti

Posted on Updated on

As I like Dropwizard and CDI and as I started to study Activiti, I wanted to see how they could work together. The idea is to deploy a test bpmn that outputs a “hello world” and run it with a simple Dropwizard REST call using only pure Activiti Java API.


Dropwizard 0.9.2 (


Activiti 6.0.0. Beta2 (

Postgresql 9.5 (

I’ve already created a Github project  on Dropwizard and CDI demonstrating how they work together. I’ve used that as a base. The sources are available here:

From the Activiti stack I’ve only taken Activiti Engine and embedded it in Dropwizard (java) app. I haven’t used neither Activiti REST (it’s a WAR file that needs to be deployed on servlet container) nor Spring to configure Activiti Engine. For the Activiti database, the Postgresql database has been used.

Creating Activiti DB

After downloading  and installing Postgresql I’ve prepared the database for Activiti. I’ve created a Role “activiti” and with it created a database “activiti”.

In a zip file of Activiti 6.0.0.Beta2 there is a folder “database” and subfolder “create”. Inside, there are three SQL scripts that create all the DB objects needed by Activiti. You can easily run them within the newly created db.

Then I’ve created a DB configuration needed by Activiti inside the Dropwizard config.yml:

   jdbcUrl: jdbc:postgresql://localhost:5432/activiti
   jdbcUsername: activiti
   jdbcPassword: activiti
   jdbcDriver: org.postgresql.Driver

POM configuration

There are the following dependencies within the POM file (for convenience I’ve left out the dependencies on CDI):


I’ve used groovy to output “Hello world” inside bpmn; hence we need its dependency.


There’s nothing special here. I’ve just registered a REST resource and stored the reference to the Dropwizard configuration:

 public void run(DwConfiguration config, Environment environment) throws Exception {

CDI producer

I’ve used a producer method for creating the Activiti Process Engine:

public class ProjectEngineFactory {
    public ProcessEngine getProcessEngine() {
       ProcessEngine processEngine = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration()
       return processEngine;

REST resource

I’ve injected Activiti Process Engine, deployed test flow, run it and returned its id:

 public class DwActivitResource {
    private ProcessEngine processEngine;
    public String justTextMessage() {
       RepositoryService repositoryService = processEngine.getRepositoryService();
       RuntimeService runtimeService = processEngine.getRuntimeService();
       Deployment deployment = repositoryService
       ProcessInstance processInstance = runtimeService
       return processInstance.getId();

Now when you call http://localhost:9999/v2/activiti/hello you should see the process instance id and “hello world” in the console.

That’s it, pretty simple. The entire code is on the Github: