Are there Java classes for Camunda Rest responses?

Hey fellow camunda enthusiasts,

Im currently trying to set up REST calls from Spring to my local camunda instance using the camunda rest api.

Here’s how i’ve set it up:

  1. Started a local camunda docker container on my localhost:8080 like this: Docker
    (i’ve tested calls with postman and they are working)

  2. Built a maven project using a couple of camunda and rest dependencies in my pom.xml:

        <dependency>
            <groupId>org.camunda.bpm.springboot</groupId>
            <artifactId>camunda-bpm-spring-boot-starter</artifactId>
            <version>3.3.1</version>
        </dependency>

        <dependency>
            <groupId>org.camunda.bpm</groupId>
            <artifactId>camunda-engine-rest-core</artifactId>
            <version>7.11.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectreactor</groupId>
            <artifactId>reactor-spring</artifactId>
            <version>1.0.1.RELEASE</version>
        </dependency>
  1. Wrote a simple service to make rest calls from Spring (taken from Core Features):
import org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

@Service
public class MyExampleService {

    private final WebClient webClient;

    public MyExampleService (WebClient.Builder webClientBuilder) {
        this.webClient = webClientBuilder.baseUrl("http://localhost:8080").build();
    }

    @Override
    public ProcessDefinitionEntity[] getCamundaProcesses() {

        ProcessDefinitionEntity[] myResponse = this.webClient.get().uri("/engine-rest/deployment/")
                .retrieve()
                .onStatus(HttpStatus::is4xxClientError, response -> {
                    System.out.println("4xx eror");
                    return Mono.error(new RuntimeException("4xx"));
                })
                .onStatus(HttpStatus::is5xxServerError, response -> {
                    System.out.println("5xx eror");
                    return Mono.error(new RuntimeException("5xx"));
                })
                .bodyToMono(ProcessDefinitionEntity[].class)
                .block();
        
        return myResponse;
}

So I basically used Spring WebClient to make a rest call to localhost:8080/engine-rest/deployment/ which should give me a list of all processes as JSON (according to Camunda Platform REST API).

Now when I convert the response directly into a ProcessDefinitionEntity[] it won’t cast the JSON into it. I also tried other classes from the camunda Java API (Camunda BPM Javadocs 7.11.21-ee) like ProcessDefinitionDto.

None of the classes seem to properly fit the response I get from camunda. The response looks like this:

[
    {
        "id": "invoice:1:cdbc3f02-e6a1-11e9-8de8-0242ac110002",
        "key": "invoice",
        "category": "http://www.omg.org/spec/BPMN/20100524/MODEL",
        "description": null,
        "name": "Invoice Receipt",
        "version": 1,
        "resource": "invoice.v1.bpmn",
        "deploymentId": "cda115de-e6a1-11e9-8de8-0242ac110002",
        "diagram": null,
        "suspended": false,
        "tenantId": null,
        "versionTag": "V1.0",
        "historyTimeToLive": 30,
        "startableInTasklist": true
    },
    {
        "id": "invoice:2:ce03f66c-e6a1-11e9-8de8-0242ac110002",
        "key": "invoice",
        "category": "http://www.omg.org/spec/BPMN/20100524/MODEL",
        "description": null,
        "name": "Invoice Receipt",
        "version": 2,
        "resource": "invoice.v2.bpmn",
        "deploymentId": "cdfbb908-e6a1-11e9-8de8-0242ac110002",
        "diagram": null,
        "suspended": false,
        "tenantId": null,
        "versionTag": "V2.0",
        "historyTimeToLive": 45,
        "startableInTasklist": true
    }
]

(which are just the two standard processes that are in the docker container)

Are there classes in the camunda java api that properly match the responses from the camunda rest api?

Best Regards,

Sebastian

1 Like

Hi Sebastian,

I’m curently building a library to access Camunda REST API via REST. It is called camunda-bpm-feign and it uses a feign client to handle request/response magic and decorates the responses in a way that it provides a “remote” implementation of the Camunda API services.

So instead of creating a new API, you can use “remote” version of Camunda API.
Currently, I focused on implementation of the RuntimeService but it would be easy to implement the RepositoryService too. Please have a look on it, and feel free to file issues in github, if you are missing someting.

https://github.com/holunda-io/camunda-bpm-feign

Kind regards,

Simon

Hi Sebastian,

I just created issue #16 (see https://github.com/holunda-io/camunda-bpm-feign/issues/16)
and implemented a first PoC.

You are right about the types - the JSON is not matching the default Jackson serialization, but I got it working.

Cheers,

Simon

edit
I meant to call /engine-rest/process-definition in my java service. That was a copy paste mistake. However the problem remains that no java class fits the response List/Array of json objects.

Im looking for some class like
ProcessDefinitionRestResponse that actually fits the variables of the json response so I can simply cast the response into it.

Hi Simon,

I tried to get your quick start guide running. But it seems I would have to host the maven stuff locally myself. Your dependencies are not on mvnrepository.com right?

Yes.

The library is not released yet. I’m trying to finish the required stuff and will release a 0.0.1 soon, probably next week. I’m on it to discuss with Camunda if it becomes a community extension or not. Sorry for letting you wait.

The response of your method is of type List<ProcessDefinitionDto> from org.camunda.bpm.engine.rest.dto.repository package. It has a un-orthodox serialization which can be fixed by providing a Jackson Mixin. As long it is not released, you can have a look on my implementation.
It provides a Jackson Mixin and a simple module registering it for the DTO. Here is the code (in Kotlin):

You need to register the Jackson Module in your Jackson Configuration, by calling

objectMapper.registerModule(new CamundaMixinModule());

Cheers,

Simon

I was able to resolve my issues with this solution:

https://stackoverflow.com/questions/58525407/are-there-java-classes-for-camunda-rest-responses