How to implement Activiti REST API with Spring Boot Example

In this tutorial, we’re gonna look at an example that uses Activiti REST API with Spring Boot.

Related Articles:
Introduction to Activiti – a Java BPM Engine
How to start Activiti + Spring JPA with Spring Boot

I. Activiti REST API Overview

Activiti Engine includes a REST API that can be used by:
– deploying the activiti-rest.war file to a servlet container,
– or including the servlet and it’s mapping in the application and add all activiti-rest dependencies to the classpath.

By default the Activiti Engine will connect to an in-memory H2 database, so with Spring Boot, we just need to add dependency as below to make it run:

Activiti REST API supports:

  • Deployment: get/create/delete Deployments, get resources inside a Deployment.
  • Process Definition: get one or list of Process Definitions, get resource content or BPMN model of a Process Definition, activate/suspend, get/add/delete candidate starters.
  • Model: get/update/create/delete Models, get/set editor source for a Model.
  • Process Instance: get/delete/activate/suspend Process Instances, add/remove Users, get/create/update Variables.
  • Execution: get Executions, execute an action or get active activities, query, get/create/update Variables.
  • Task: get/update/delete Tasks, query for Tasks, get/create/update Variables, get/create/delete identity links, get Events, get/create/delete Attachments.
  • History: get/delete/query for Historic Process Instances, Task Instances, Activities Instances, Variables Intances.
  • User & Group: get/create/update/delete information.
  • Database Table, Engine, Runtime, Job

For more details, please visit: Activiti User Guide – REST API

In the example, we will test some of them to see how it works.

II. Practice

1. Technology

– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.4.RELEASE
– Spring Boot: 1.5.3.RELEASE

2. Step by step
2.1 Create Spring Boot project

Using Spring Tool Suite/Eclipse to create Project and add Dependencies to pom.xml file:

2.2 Define Process

Under src/main/resources, create processes folder and add simple-process.bpmn20.xml file:

We use ${person} expression and activiti:assignee attribute for assigning task.

2.3 Initialize User

By default, all Activiti REST resources require a valid User to be authenticated. So we should create an admin User. Open Application class, add Bean for initializing User:

Basic HTTP access authentication is used, so we always include a authorized username & password in the request url.

More about Activiti Services at: Introduction to Activiti – a Java BPM Engine

2.4 Run & Check Result

– Config maven build:
clean install
– Run project with mode Spring Boot App
– Check results:

List of Deployments:
curl -u admin:admin http://localhost:8080/repository/deployments

List resources in a deployment:
curl -u admin:admin http://localhost:8080/repository/deployments/1/resources

List of process definitions:
curl -u admin:admin http://localhost:8080/repository/process-definitions

Get BPMN model (by processId):
curl -u admin:admin http://localhost:8080/repository/process-definitions/simpleProcess:1:3/model

Start Process:
curl -u admin:admin -H "Content-Type: application/json" -d '{"processDefinitionKey":"simpleProcess", "variables": [ {"name":"person", "value":"John"}]}' http://localhost:8080/runtime/process-instances

We have also sent Variables Information {“person”:”John”}. This request returns a Process Instance:

List of variables by Process Instance ID
curl -u admin:admin http://localhost:8080/runtime/process-instances/4/variables

List of tasks:
curl -u admin:admin http://localhost:8080/runtime/tasks

Add Variables to Task (by Id):
curl -u admin:admin -H "Content-Type: application/json" -d '[{"name" : "newTaskVariable", "scope" : "local", "type" : "string", "value" : "This is variable Value"}]' http://localhost:8080/runtime/tasks/9/variables

Identity Links (by Id):
curl -u admin:admin http://localhost:8080/runtime/tasks/9/identitylinks

Complete Task (by Id):
curl -u admin:admin -H "Content-Type: application/json" -d '{"action" : "complete"}' http://localhost:8080/runtime/tasks/9

Historic process instance:
curl -u admin:admin http://localhost:8080/history/historic-process-instances/4

III. Source code


Related Posts

3 thoughts on “How to implement Activiti REST API with Spring Boot Example”

  1. Hi,
    I downloaded your code source. And it doesn’t work until I removed activiti rest – api. and by removing activit-rest-api we will not have acces to Rest api. can you suggest any solution?

    1. Hi WAJDI,

      Make sure that you didn’t deploy the activiti-rest.war file to a servlet container before.
      Then just follow step by step to make project run (all activiti-rest dependencies will be added to the classpath automatically).
      I have checked the source code again and it works well.

      If you cannot make thing done, notice us again and show your problem more clearly.

      Best Regard,

Got Something To Say:

Your email address will not be published. Required fields are marked *