JBoss 系列九十九:Rest WebService jBPM 6 整合樣本

來源:互聯網
上載者:User

標籤:jboss bpm suite 6   jboss   bpm   

概述

jBPM 6 提供 Rest API 供第三方應用整合使用 jBPM 6,本文示範如果通過 Rest API:

  • 啟動流程
  • 擷取流程執行個體資訊
  • 啟動 User Task
  • 完成 User Task
 jBPM 6 中使用 RestEasy 實現 Rest WebService ,所以我們通過 Rest 用戶端 API 與 jBPM 6 所提供的 Rest API 互動。

本文所使用的流程如下


如上流程只有一個 User Task 節點,User Task 執行開始和執行結束都輸出相關提示。流程 ID為 org.brms.test,節點名字為 Test,執行節點需要的 userID 為 kylin,角色為 IT。

為方便觀察,我們需要 jBPM 6 使用 Mysql 替換預設的 H2 資料庫。

啟動流程

啟動流程 Rest API 如下:

/runtime/{id: [a-zA-Z0-9-:\\.]+}")/process/{id: [a-zA-Z0-9-:\\.]+}/start

運行 RestEasyClientProcessStart.java 啟動流程,啟動流程後我們到資料庫中查看:

mysql> select id, duration, start_date, end_date, processId, processInstanceId, processName, status from ProcessInstanceLog;+----+----------+---------------------+---------------------+---------------+-------------------+-------------+--------+| id | duration | start_date          | end_date            | processId     | processInstanceId | processName | status |+----+----------+---------------------+---------------------+---------------+-------------------+-------------+--------+|  1 |    51569 | 2014-05-10 21:17:20 | 2014-05-10 21:18:11 | org.brms.test |                 1 | test        |      2 ||  2 |  3770025 | 2014-05-10 21:24:57 | 2014-05-10 22:27:47 | org.brms.test |                 2 | test        |      2 ||  3 |  4060507 | 2014-05-10 21:25:33 | 2014-05-10 22:33:13 | org.brms.test |                 3 | test        |      2 ||  4 |  2620216 | 2014-05-10 21:49:41 | 2014-05-10 22:33:21 | org.brms.test |                 4 | test        |      2 ||  5 |  2561315 | 2014-05-10 21:50:49 | 2014-05-10 22:33:30 | org.brms.test |                 5 | test        |      2 ||  6 |  2557182 | 2014-05-10 21:51:01 | 2014-05-10 22:33:38 | org.brms.test |                 6 | test        |      2 ||  7 |  2558504 | 2014-05-10 21:51:07 | 2014-05-10 22:33:45 | org.brms.test |                 7 | test        |      2 ||  8 |     NULL | 2014-05-11 13:21:05 | NULL                | org.brms.test |                 1 | test        |      1 |+----+----------+---------------------+---------------------+---------------+-------------------+-------------+--------+

如上ProcessInstanceLog表中 ID 為 8 的;流程樣本為我們通過 Rest API 啟動的流程執行個體,注意,status列為1表示流程未被執行。

擷取流程執行個體

擷取流程執行個體 Rest API 如下:

/runtime/{id: [a-zA-Z0-9-:\\.]+}")/process/instance/{id: [0-9]+}

運行 RestEasyClientGetProcessInstance.java 擷取流程執行個體 ,我們運行結果會有如下輸出

ProcessInstance 1 [processId=org.brms.test,state=1]

注意,我們測試流程的ID 為 org.brms.test,資料庫中 processInstanceId 為 1,所以我們的 Rest Path如下:

http://localhost:8080/business-central/rest/runtime/org.kie.example:project1:1.0.0-SNAPSHOT/process/instance/1
開始 User Task

開始 User Task Rest API 如下:

/task/execute{id: \\d+}/start

運行 RestEasyClientTaskStart.java 開始執行 User Task ,開始執行之前我們首先到資料庫中看當前 User Task  的資訊:

mysql> select id, createdOn, deploymentId, processInstanceId, processId, status, createdBy_id from Task;+----+---------------------+-----------------------------------------+-------------------+---------------+----------+--------------+| id | createdOn           | deploymentId                            | processInstanceId | processId     | status   | createdBy_id |+----+---------------------+-----------------------------------------+-------------------+---------------+----------+--------------+|  1 | 2014-05-11 13:21:05 | org.kie.example:project1:1.0.0-SNAPSHOT |                 1 | org.brms.test | Reserved | kylin        |+----+---------------------+-----------------------------------------+-------------------+---------------+----------+--------------+

注意,此 Task 與 processInstanceId 為 1 的流程樣本關聯,目前狀態沒有開始。

運行 RestEasyClientTaskStart.java 開始執行 User Task ,執行之後我們同樣到資料庫查看當前 User Task  的資訊:

mysql> select id, createdOn, deploymentId, processInstanceId, processId, status, createdBy_id from Task;+----+---------------------+-----------------------------------------+-------------------+---------------+------------+--------------+| id | createdOn           | deploymentId                            | processInstanceId | processId     | status     | createdBy_id |+----+---------------------+-----------------------------------------+-------------------+---------------+------------+--------------+|  1 | 2014-05-11 13:21:05 | org.kie.example:project1:1.0.0-SNAPSHOT |                 1 | org.brms.test | InProgress | kylin        |+----+---------------------+-----------------------------------------+-------------------+---------------+------------+--------------+

主要當前 Task 的狀態改變為 InProgress。

完成User Task

完成User Task Rest API 如下:

/task/execute{id: \\d+}/complete

運行 RestEasyClientTaskComplete.java 可以完成 User Task ,執行完成後去資料庫查看當前 User Task  的資訊:

mysql> select id, createdOn, deploymentId, processInstanceId, processId, status, createdBy_id from Task;Empty set (0.00 sec)

如上資料庫中沒有Task資訊,即jBPM 中當某一 Task 執行完成後會將其的資訊刪除,如果我們接著去查看流程執行個體的資訊:

mysql> select id, duration, start_date, end_date, processId, processInstanceId, processName, status from ProcessInstanceLog;+----+----------+---------------------+---------------------+---------------+-------------------+-------------+--------+| id | duration | start_date          | end_date            | processId     | processInstanceId | processName | status |+----+----------+---------------------+---------------------+---------------+-------------------+-------------+--------+|  1 |    51569 | 2014-05-10 21:17:20 | 2014-05-10 21:18:11 | org.brms.test |                 1 | test        |      2 ||  2 |  3770025 | 2014-05-10 21:24:57 | 2014-05-10 22:27:47 | org.brms.test |                 2 | test        |      2 ||  3 |  4060507 | 2014-05-10 21:25:33 | 2014-05-10 22:33:13 | org.brms.test |                 3 | test        |      2 ||  4 |  2620216 | 2014-05-10 21:49:41 | 2014-05-10 22:33:21 | org.brms.test |                 4 | test        |      2 ||  5 |  2561315 | 2014-05-10 21:50:49 | 2014-05-10 22:33:30 | org.brms.test |                 5 | test        |      2 ||  6 |  2557182 | 2014-05-10 21:51:01 | 2014-05-10 22:33:38 | org.brms.test |                 6 | test        |      2 ||  7 |  2558504 | 2014-05-10 21:51:07 | 2014-05-10 22:33:45 | org.brms.test |                 7 | test        |      2 ||  8 |  1069981 | 2014-05-11 13:21:05 | 2014-05-11 13:38:54 | org.brms.test |                 1 | test        |      2 |+----+----------+---------------------+---------------------+---------------+-------------------+-------------+--------+

我們可以發現 ID 為 8,processInstanceId 為 1的流程 status欄變為 2,這表明流程已經執行完成,我們也可以發現流程開始時間為 2014-05-11 13:21:05,結束時間為 2014-05-11 13:38:54,執行的周期(duration)為 1069981 毫秒。


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.