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服務器成功返回結果: