本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长


+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

Activiti 用户界面 Spring App 集成

发布于2023-02-04 22:50     阅读(1122)     评论(0)     点赞(20)     收藏(2)


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

到目前为止,我可以使用 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 应用程序。(在 localhost:8081 上运行)与 Activiti ui 界面?


解决方案


activity-rest如果您已配置并正在运行,那将非常容易。REST API在此处记录。

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

注意:Rest API 使用基本身份验证。

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
 }


所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:http://www.javaheidong.com/blog/article/641614/5a9ebd7302255f638998/

来源:java黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

20 0
收藏该文
已收藏

评论内容:(最多支持255个字符)