Camunda Rest响应是否有Java类?

问题描述 投票:0回答:2

嗨,程序员,

我目前正在尝试使用camunda rest api建立从Spring到我的本地camunda实例的REST调用。

这是我的设置方式:

  1. 在我的localhost:8080上启动本地camunda docker容器,如下所示:https://hub.docker.com/r/camunda/camunda-bpm-platform(我已经测试了与邮递员的通话,并且可以正常工作)

  2. 在我的pom.xml中使用几个camunda构建了一个Maven项目并建立了依赖关系:

        <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. 编写了一个简单的服务以从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/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;
}

因此,我基本上使用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的响应正确匹配的类?

最好的问候,

塞巴斯蒂安

json spring rest camunda spring-webclient
2个回答
0
投票

您是否在寻找正确的包裹? Camunda代码库中有多个ProcessDefinitionDto类。您要查找的是位于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;

  ...

0
投票

]中的类>

org.camunda.bpm.engine.rest.dto.runtime

© www.soinside.com 2019 - 2024. All rights reserved.