Json 是否有用于Camunda Rest响应的Java类?
我目前正在尝试使用camunda REST api设置从Spring到本地camunda实例的REST调用 我是这样设置的:Json 是否有用于Camunda Rest响应的Java类?,json,spring,rest,camunda,spring-webclient,Json,Spring,Rest,Camunda,Spring Webclient,我目前正在尝试使用camunda REST api设置从Spring到本地camunda实例的REST调用 我是这样设置的: 在我的localhost:8080上启动了一个本地camunda docker容器,如下所示: (我已经和邮递员测试了电话,他们正在工作) 在mypom.xml中使用两个camunda和rest依赖项构建了一个maven项目: org.camunda.bpm.springboot ): import org.camunda.bpm.engine.impl.persist
localhost:8080
上启动了一个本地camunda docker容器,如下所示:
(我已经和邮递员测试了电话,他们正在工作)pom.xml
中使用两个camunda和rest依赖项构建了一个maven项目:
org.camunda.bpm.springboot
):
import org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity;
导入org.springframework.http.HttpStatus;
导入org.springframework.stereotype.Service;
导入org.springframework.web.reactive.function.client.WebClient;
导入reactor.core.publisher.Mono;
@服务
公共类MyExampleService{
私人最终网络客户网络客户;
公共MyExampleService(WebClient.Builder WebClient Builder){
this.webClient=webClientBuilder.baseUrl(“http://localhost:8080build();
}
@凌驾
PublicProcessDefinitionEntity[]GetCamundaProcesss(){
ProcessDefinitionEntity[]myResponse=this.webClient.get().uri(“/engine rest/process definition/”)
.retrieve()
.onStatus(HttpStatus::is4xxClientError,响应->{
系统输出打印项次(“4xx eror”);
返回Mono.error(新的运行时异常(“4xx”);
})
.onStatus(HttpStatus::is5xxServerError,响应->{
系统输出打印项次(“5xx eror”);
返回Mono.error(新的运行时异常(“5xx”);
})
.BodyToNo(ProcessDefinitionEntity[].class)
.block();
返回myResponse;
}
因此,我基本上使用SpringWebClient对localhost:8080/engine rest/deployment/
进行rest调用,这将为我提供所有进程的JSON列表(根据)
现在,当我将响应直接转换为ProcessDefinitionEntity[]时,它不会将JSON强制转换为它
似乎没有一个类与我从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
}
]
[
{
"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
}
]
(这只是docker容器中的两个标准流程)
camunda java api中是否有与camunda rest api的响应正确匹配的类?
附言:
我从maven依赖项(位于包org.camunda.bpm.engine.rest.dto.repository.ProcessDefinitionDto
中)获得的ProcessDefinitionDto如下所示:
[
{
"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
}
]
[
{
"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
}
]
公共类进程定义到{
受保护的字符串id;
受保护的字符串密钥;
受保护字符串类别;
保护字符串描述;
受保护的字符串名称;
受保护的int版本;
受保护的字符串资源;
受保护的字符串部署ID;
保护字符串图;
受保护的布尔暂停;
受保护的字符串租户;
受保护的字符串版本标记;
受保护的整数历史时间;
受保护的布尔值isStartableInTasklist;
...
还有我从邮递员打电话到http://localhost:8080/engine-rest/进程定义
如下所示:
[
{
"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
}
]
[
{
"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
}
]
您正在查看正确的包吗?Camunda代码库中有多个ProcessDefinitionTo类。
您要查找的是camunda-engine-rest-core.jar中的包org.camunda.bpm.engine.rest.dto.repository
该类如下所示,与您的输出完全匹配:
package org.camunda.bpm.engine.rest.dto.repository;
import org.camunda.bpm.engine.repository.ProcessDefinition;
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;
...
课堂
org.camunda.bpm.engine.rest.dto.runtime
是合适的
packageorg.camunda.bpm.engine.rest.dto.repository中的目标数据结构包含相同的字段:
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;
...}
如果反序列化失败,请确保您使用的是正确的包(例如org.camunda.bpm.caffick.impl.plugin.base.dto)这个类不完全适合我的json响应。这个响应有startableInTasklist
,而这个类调用它isStartableInTasklist
,这只是一个命名约定。如果你检查rest接口的源代码(ProcessDefinitionRestServiceImpl.java
,在camunda engine rest core中)包中,您将看到使用的是正确的类。Jax ws将在rest响应中将此属性转换为startableInTasklisthttp://localhost:8080/engine-rest/processdefinition/
结果不适用于Java类列表
我根据您的具体情况更新了答案,并添加了一个exampGithub上的le客户端项目很抱歉这么晚才回答。我正忙于处理应用程序的其他部分。因此我复制并尝试了您的RuntimeServiceImpl类中的解决方案。但是这似乎不起作用:我得到了3个结果(这是正确的,因为我在本地camunda实例中有3个进程)但是它们没有正确地转换到ProcessDefinitionDto数组中:(如果使用正确的查询,那么反序列化应该可以工作。您是否有机会共享代码,例如通过github?我无法共享我的整个项目(因为版权问题),但我创建了一个包含所有相关文件的文件夹来解决我的问题:正如您所看到的,我的服务实际上只对camunda的rest api进行了简单调用。我还注释了实际有效的代码。在那里,我创建了一个自定义ProcessDefinition类,并将JSON响应植入其中,这确实有效(但这是一个黑客解决方案imho)