JBPM 6 - 1.6 - Triggering Process via REST
Jump to navigation
Jump to search
JBPM 6 - 1.6 - Triggering Process via REST 通过REST触发流程
The workbench contains an execution server (for executing processes and tasks), which also allows you to invoke various process and task related operations through a remote API. As a result, you can setup your process engine "as a service" and integrate this into your applications easily by doing remote requests and/or sending the necessary triggers to the execution server whenever necessary (without the need to embed or manage this as part of your application).
- workbench包括一个执行服务区(用于执行流程和任务),它也允许你启动各种通过远程接口进行的操作的流程和任务。这样做的结果就是,你能把你的流程引擎设置为“服务”,轻松地集成到你的应用里面,实现起来是通过进行远程请求,并且/或者在必要时向执行服务器发送必要的触发指令(triggers)(这样做可以避免将它们作为你的应用的一部分,而必然要嵌入或者管理它们。)
Scenario 场景
- You want to execute your process stored in Workbench externaly injecting process variables
- ??
- In our case we want to start recruitment process when a new person applies
- 我们的情况是,我们需要在新人应聘时启动招聘流程
Documentation 文档
- http://docs.jboss.org/drools/release/6.2.0.CR4/drools-docs/html/ch.commands.html#d0e11625
- http://docs.jboss.org/jbpm/v6.1/userguide/jBPMRemoteAPI.html
Getting deploymentId
- Via REST service
POST:http://localhost:8080/jbpm-console/rest/deployment Accept: application/json
- Using Workbench
- Authoring / Project Authoring
- Tools / Project Editor
Java Remote API
URL baseUrl = new URL("http://localhost:8080/jbpm-console");
String user = "krisv";
String password = "krisv";
String deploymentId = "hrproj:hrproj:1.0";
RemoteRestRuntimeFactory restSessionFactory = new RemoteRestRuntimeFactory(deploymentId, baseUrl, user, password);
RuntimeEngine engine = restSessionFactory.newRuntimeEngine();
KieSession ksession = engine.getKieSession();
ProcessInstance processInstance = ksession.startProcess("hrproj.emp_recruitmen2");
long procId = processInstance.getId();
String taskUserId = user;
TaskService taskService = engine.getTaskService();
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("krisv", "en-UK");
long taskId = -1;
for (TaskSummary task : tasks) {
if (task.getProcessInstanceId() == procId) {
taskId = task.getId();
}
}
if (taskId == -1) {
throw new IllegalStateException("Unable to find task for " + user
+ " in process instance " + procId);
}
taskService.start(taskId, taskUserId);