Flowable REST API 应用
1、按照官方文档安装REST应用
注意:(1)将下载解压的flowable文件夹中的flowable-rest.war文件复制到tomcat的webapps文件夹
(2)使用命令行程序,进入tomcat的bin文件夹,执行catalina run(Windows系统下),启动tomcat
tomcat成功启动--如下信息:
重新打开一个cmd窗口,输入命令,验证应用运行正常~~
返回如下:
2、部署流程定义
部署流程定义:进入到有holiday-request.bpmn20.xml文件的目录,shift+右键,打开cmd窗口,使用命令:curl --user rest-admin:test -F "file=@holiday-request.bpmn20.xml" http://localhost:8080/flowable-rest/service/repository/deployments,上传bpmn20.xml文件。
验证流程定义的部署:--请求流程定义列表
curl --user rest-admin:test http://localhost:8080/flowable-rest/service/repository/process-definitions
命令行成功返回流程定义列表
3、启动流程实例
使用官方文档提供命令:curl --user rest-admin:test -H "Content-Type: application/json" -X POST -d ‘{ "processDefinitionKey":"holidayRequest", "variables": [ { "name":"employee", "value": "John Doe" }, { "name":"nrOfHolidays", "value": 7 }]}‘ http://localhost:8080/flowable-rest/service/runtime/process-instances
错误:{"message":"Bad request","exception":"JSON parse error: Unexpected character (‘‘‘ (code 39)): expected a valid value (JSON String, Number, Array, Object or token ‘null‘, ‘true‘ or ‘false‘); nested exception is com.fasterxml.jackson.core.JsonParseException: Unexpected character (‘‘‘ (code 39)): expected a valid value (JSON String, Number, Array, Object or token ‘null‘, ‘true‘ or ‘false‘)\n at [Source: (PushbackInputStream); line: 1, column: 2]"}
D:\My_Files\LQW\workspace\holidayrequest\src\main\resources>curl --user rest-admin:test -H "Content-Type: application/json" -X POST -d ‘{ "processDefinitionKey":"holidayRequest", "variables": [ { "name":"employee", "value": "John Doe" }, { "name":"nrOfHolidays", "value": 7 }]}‘ http://localhost:8080/flowable-rest/service/runtime/process-instances
解决方案:单引号改成双引号+命令行中json格式中双引号使用‘\’转义
修改后命令行:curl --user rest-admin:test -H "Content-Type: application/json" -X POST -d "{ \"processDefinitionKey\":\"holidayRequest\", \"variables\": [ { \"name\":\"employee\", \"value\": \"John Doe\" }, { \"name\":\"nrOfHolidays\", \"value\": 7 }]}" http://localhost:8080/flowable-rest/service/runtime/process-instances
返回结果如下:正确响应
参考网址:https://bbs.huaweicloud.com/blogs/143206
4、任务列表与完成任务
1、任务列表:使用REST-API查询manager组的所有任务。[命令行中,json--单引号变双引号+双引号转义]
curl --user rest-admin:test -H "Content-Type: application/json" -X POST -d “{ \"candidateGroup\" : \"managers\" }" http://localhost:8080/flowable-rest/service/query/tasks
返回manager组所有任务的列表,如下:
2、完成任务:
(1)CallExternalSystemDelegate类打包成jar包,放入指定目录:D:\...\apache-tomcat-9.0.34\webapps\flowable-rest\WEB-INF\lib
(2) 重启tomcat
(3)使用命令完成任务(修改官方文档提供命令:1、单引号变双引号+双引号转义 2、task 的id修改为自己任务的id)
curl --user rest-admin:test -H "Content-Type: application/json" -X POST -d ”{ \"action\" : \"complete\", \"variables\" : [ { \"name\" : \"approved\", \"value\" : true} ] }" http://localhost:8080/flowable-rest/service/runtime/tasks/fca7230c-9685-11ea-a9a0-7266552707c1
tomcat服务器成功返回结果:
Flowable学习笔记(二)--Flowable REST API
原文:https://www.cnblogs.com/KellyW-Li/p/12896705.html