Activiti用户界面Spring App集成

问题描述 投票:1回答:1

我从官方提供的.WAR文件运行以下Activiti 6应用程序。已成功将这些部署到我的localhost

到目前为止,我可以使用activiti-app生成BPMN文件并使用该界面启动应用程序。到现在为止还挺好。

然而,我想要做的是编写我自己的Spring应用程序,但能够使用activiti UI应用程序查看它们的运行情况。

所以看看baeldung-activiti教程。您可以启动该应用程序。

@GetMapping("/start-process")
public String startProcess() {
    runtimeService.startProcessInstanceByKey("my-process");
    return "Process started. Number of currently running process instances = " + runtimeService.createProcessInstanceQuery().count();
}

每次命中端点时,上面都会返回一个增量值。

我的问题是这个。

使用activiti工具(在localhost:8008上运行)如何查看进程。如何链接独立的Java应用程序。 (使用Activiti ui接口在localhost:8081上运行)?

java spring activiti
1个回答
1
投票

如果你配置并运行activity-rest,这很容易。 REST API记录在here中。

因此,您只需要对正确的API端点进行Web Service调用。例如,列出为GET端点执行repository/process-definitions请求所需的所有进程。

注意:Rest API使用Basic Auth。

public void loadProcesses(){
    // the username and password to access the rest API (same as for UI)
    String plainCreds = "username:p@ssword";
    byte[] plainCredsBytes = plainCreds.getBytes();
    byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes);
    String base64Creds = new String(base64CredsBytes);

    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "Basic " + base64Creds);
    RestTemplate restTemplate = new RestTemplate();
    HttpEntity<String> request = new HttpEntity<>(headers);
    ResponseEntity<String> responseAsJson = restTemplate.exchange("http://localhost:8080/activiti-rest/repository/process-definitions", HttpMethod.GET, request, String.class);
}

以下API调用的响应将是JSON之类的

{
  "data": [
  {
    "id" : "oneTaskProcess:1:4",
    "url" : "http://localhost:8182/repository/process-definitions/oneTaskProcess%3A1%3A4",
    "version" : 1,
    "key" : "oneTaskProcess",
    "category" : "Examples",
    "suspended" : false,
    "name" : "The One Task Process",
    "description" : "This is a process for testing purposes",
    "deploymentId" : "2",
    "deploymentUrl" : "http://localhost:8081/repository/deployments/2",
    "graphicalNotationDefined" : true,
    "resource" : "http://localhost:8182/repository/deployments/2/resources/testProcess.xml",
    "diagramResource" : "http://localhost:8182/repository/deployments/2/resources/testProcess.png",
    "startFormDefined" : false
  }
  ],
  "total": 1,
  "start": 0,
  "sort": "name",
  "order": "asc",
  "size": 1
 }
© www.soinside.com 2019 - 2024. All rights reserved.