我目前正在尝试使用 camunda rest api 设置从 Spring 到我本地 camunda 实例的 REST 调用。
这是我的设置方式:
localhost:8080
在我这样的地方启动了一个本地 camunda docker 容器: https ://hub.docker.com/r/camunda/camunda-bpm-platform (我已经用邮递员测试了电话,他们正在工作)使用我的几个 camunda 和 rest 依赖项构建了一个 maven 项目
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>
- 编写了一个简单的服务来从 Spring 进行休息调用(取自https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-webclient):
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/process-definition/")
.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;
}
所以我基本上使用 Spring WebClient 进行休息调用,localhost:8080/engine-rest/deployment/
它应该给我一个 JSON 格式的所有进程列表(根据https://docs.camunda.org/manual/latest/reference/rest/deployment/get-query/)。
现在,当我将响应直接转换为 ProcessDefinitionEntity[] 时,它不会将 JSON 转换为它。我还尝试了来自 camunda Java API ( https://docs.camunda.org/javadoc/camunda-bpm-platform/7.11/ ) 的其他类,例如ProcessDefinitionDto
。
似乎没有一个课程适合我从 camunda 得到的回应。响应如下所示:
[
{
"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
}
]
(这只是 docker 容器中的两个标准进程)
camunda java api 中是否有正确匹配来自 camunda rest api 的响应的类?
PS:我从 maven 依赖项(位于package org.camunda.bpm.engine.rest.dto.repository.ProcessDefinitionDto
)中获得的 ProcessDefinitionDto 看起来像这样:
public class ProcessDefinitionDto {
protected String id;
protected String key;
protected String category;
protected String description;
protected String name;
protected int version;
protected String resource;
protected String deploymentId;
protected String diagram;
protected boolean suspended;
protected String tenantId;
protected String versionTag;
protected Integer historyTimeToLive;
protected boolean isStartableInTasklist;
...
我从邮递员电话中得到的响应http://localhost:8080/engine-rest/process-definition
如下所示:
[
{
"id": "b506eb34-e6b1-11e9-8de8-0242ac110002",
"key": "example_workflow",
"category": "http://bpmn.io/schema/bpmn",
"description": null,
"name": "Just an Example",
"version": 1,
"resource": "example_workflow.bpmn",
"deploymentId": "b503b6e2-e6b1-11e9-8de8-0242ac110002",
"diagram": null,
"suspended": false,
"tenantId": null,
"versionTag": null,
"historyTimeToLive": null,
"startableInTasklist": true
},
{
"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
}
]