首先,我想说我已经看到了这个问题:camunda Cannot find task with id task is null而这个问题不是我的问题。
我使用了球衣建立了一个休息api,我使用了camunda工作流引擎。
我使用了jersey-quickstart-grizzly maven archtype,然后像这样定义了Process资源:
@Path("process")
public class Process {
/**
* Method handling HTTP GET requests. The returned object will be sent
* to the client as "text/plain" media type.
*
*/
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("start")
public void start(){
ProcessEngineManager.getEngine().getRuntimeService().startProcessInstanceByKey("test");
}
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("next")
public void next(@FormParam("name") String name){
Map<String,Object> formParams = new HashMap<>();
formParams.put("name",name);
ProcessEngineManager.getEngine().getFormService().submitTaskForm("testtask",formParams);
}
}
这是ProcessEngineManager.java:
import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.engine.ProcessEngines;
public class ProcessEngineManager {
private static ProcessEngine engine;
public static ProcessEngine getEngine(){
if(engine==null) {
engine = ProcessEngines.getDefaultProcessEngine();
engine.getRepositoryService().createDeployment()
.addClasspathResource("workflowtest/test.bpmn")
.deploy();
}
return engine;
}
}
我在src / main / resources / workflowtest下定义了test.bpmn,如下所示:
在Xml中:
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.11.3">
<bpmn:process id="test" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>SequenceFlow_1v6clcy</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="SequenceFlow_1v6clcy" sourceRef="StartEvent_1" targetRef="testtask" />
<bpmn:userTask id="testtask" name="testtask" camunda:formKey="testform">
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="name" label="name" type="string" />
</camunda:formData>
</bpmn:extensionElements>
<bpmn:incoming>SequenceFlow_1v6clcy</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_07kdfp4</bpmn:outgoing>
</bpmn:userTask>
<bpmn:endEvent id="EndEvent_0vm605w">
<bpmn:incoming>SequenceFlow_07kdfp4</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="SequenceFlow_07kdfp4" sourceRef="testtask" targetRef="EndEvent_0vm605w" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="test">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="173" y="102" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_1v6clcy_di" bpmnElement="SequenceFlow_1v6clcy">
<di:waypoint xsi:type="dc:Point" x="209" y="120" />
<di:waypoint xsi:type="dc:Point" x="275" y="120" />
<bpmndi:BPMNLabel>
<dc:Bounds x="242" y="99" width="0" height="12" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="UserTask_1s01hea_di" bpmnElement="testtask">
<dc:Bounds x="275" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="EndEvent_0vm605w_di" bpmnElement="EndEvent_0vm605w">
<dc:Bounds x="437" y="101" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="455" y="141" width="0" height="12" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_07kdfp4_di" bpmnElement="SequenceFlow_07kdfp4">
<di:waypoint xsi:type="dc:Point" x="375" y="120" />
<di:waypoint xsi:type="dc:Point" x="403" y="120" />
<di:waypoint xsi:type="dc:Point" x="403" y="119" />
<di:waypoint xsi:type="dc:Point" x="437" y="119" />
<bpmndi:BPMNLabel>
<dc:Bounds x="418" y="113.5" width="0" height="12" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
我在src / main / resources下面有camunda.cfg.xml,如下所示:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="processEngineConfiguration"
class="org.camunda.bpm.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<property name="jdbcUrl" value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000" />
<property name="jdbcDriver" value="org.h2.Driver" />
<property name="jdbcUsername" value="sa" />
<property name="jdbcPassword" value="" />
<property name="databaseSchemaUpdate" value="true" />
</bean>
</beans>
我正在使用curl测试我的api,我确认curl -X POST http://localhost:8080/process/start
正常工作并启动了一个进程,之后我执行curl -X POST -d '{name: "John"}' http://localhost:8080/process/next
并在服务器控制台中看到此异常:
org.camunda.bpm.engine.exception.NullValueException:无法找到任务 使用id testtask:task为null at sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法) 〜[?:1.8.0_151] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 〜[?:1.8.0_151] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 〜[?:1.8.0_151] at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 〜[?:1.8.0_151] at org.camunda.bpm.engine.impl.util.EnsureUtil.generateException(EnsureUtil.java:344) 〜[camunda-engine-7.8.0.jar:7.8.0] at org.camunda.bpm.engine.impl.util.EnsureUtil.ensureNotNull(EnsureUtil.java:49) 〜[camunda-engine-7.8.0.jar:7.8.0] at org.camunda.bpm.engine.impl.util.EnsureUtil.ensureNotNull(EnsureUtil.java:44) 〜[camunda-engine-7.8.0.jar:7.8.0] at org.camunda.bpm.engine.impl.cmd.SubmitTaskFormCmd.execute(SubmitTaskFormCmd.java:54) 〜[camunda-engine-7.8.0.jar:7.8.0] at org.camunda.bpm.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24) 〜[camunda-engine-7.8.0.jar:7.8.0] at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:104) 〜[camunda-engine-7.8.0.jar:7.8.0] at org.camunda.bpm.engine.impl.interceptor.ProcessApplicationContextInterceptor.execute(ProcessApplicationContextInterceptor.java:66) 〜[camunda-engine-7.8.0.jar:7.8.0] at org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30) 〜[camunda-engine-7.8.0.jar:7.8.0] at org.camunda.bpm.engine.impl.FormServiceImpl.submitTaskForm(FormServiceImpl.java:88) 〜[camunda-engine-7.8.0.jar:7.8.0] at workflowtest.Process.next(Process.java:37)〜[classes /:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(原生方法) 〜[?:1.8.0_151] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 〜[?:1.8.0_151] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 〜[?:1.8.0_151]在java.lang.reflect.Method.invoke(Method.java:498) 〜[?:1.8.0_151] at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda $静态$ 0(ResourceMethodInvocationHandlerFactory.java:76) 〜[jersey-server-2.26.jar:?] at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher $ 1.run(AbstractJavaResourceMethodDispatcher.java:148) [jersey-server-2.26.jar:?] at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:191) [jersey-server-2.26.jar:?] at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider $ VoidOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:183) [jersey-server-2.26.jar:?] at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:103) [jersey-server-2.26.jar:?] at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:493) [jersey-server-2.26.jar:?] at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:415) [jersey-server-2.26.jar:?] at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:104) [jersey-server-2.26.jar:?] at org.glassfish.jersey.server.ServerRuntime $ 1.run(ServerRuntime.java:277) [jersey-server-2.26.jar:?] at org.glassfish.jersey.internal.Errors $ 1.call(Errors.java:272) [jersey-common-2.26.jar:?] at org.glassfish.jersey.internal.Errors $ 1.call(Errors.java:268) [jersey-common-2.26.jar:?] at org.glassfish.jersey.internal.Errors.process(Errors.java:316) [jersey-common-2.26.jar:?] at org.glassfish.jersey.internal.Errors.process(Errors.java:298) [jersey-common-2.26.jar:?] at org.glassfish.jersey.internal.Errors.process(Errors.java:268) [jersey-common-2.26.jar:?] at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:289) [jersey-common-2.26.jar:?] at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:256) [jersey-server-2.26.jar:?] at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:703) [jersey-server-2.26.jar:?] at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.service(GrizzlyHttpContainer.java:377) [jersey-container-grizzly2-http-2.26.jar:?] at org.glassfish.grizzly.http.server.HttpHandler $ 1.run(HttpHandler.java:224) [grizzly-http-server-2.4.0.jar:2.4.0] at org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.doWork(AbstractThreadPool.java:593) [grizzly-framework-2.4.0.jar:2.4.0] at org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.run(AbstractThreadPool.java:573) [grizzly-framework-2.4.0.jar:2.4.0] at java.lang.Thread.run(Thread.java:748)[?:1.8.0_151]
我不明白为什么?它确实启动了流程,因此它找到了流程&#34; test&#34;但不是任务&#34; testtask&#34;,为什么会这样,以及如何解决这个问题?
这个项目只是对我们想要构建的工作流管理系统的想法的测试,我们想要测试的想法是我们可以以我们自己的方式构建表单,从我们的选择输入中获取选项自己的数据库,仍然使用camunda作为工作流引擎。
答案 0 :(得分:1)
testTask
是进程中用户任务的id,但不是Camunda在执行流程到达活动时在运行时创建的任务的id。您可以通过TaskService#createTaskQuery
获取任务。这应该在您的示例中返回一个结果。然后通过Task#getId
获取ID,并将其用作调用FormService#submitTaskForm
的参数。
为什么会这样?您可以拥有多个流程实例,因此每个BPMN活动可以有多个实例。然后,活动ID无法唯一标识单个任务实例。
为什么在test
是流程模型中的ID时,使用test
启动流程实例?这在Camunda术语中称为process key
,当您以这种方式启动流程实例时,它始终引用具有该密钥的流程定义的最新版本。