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:
-
Started a local camunda docker container on my
localhost:8080
like this: Docker
(i’ve tested calls with postman and they are working) -
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>
- 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