Reputation: 2673
First I'd like to say that I've seen this question: camunda Cannot find task with id task is null and that question is just not my issue here.
I've built a rest api using jersey and I'm using camunda workflow engine.
I've used jersey-quickstart-grizzly maven archtype and then defined Process resource like this :
@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);
}
}
and this is 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;
}
}
I have test.bpmn under src/main/resources/workflowtest defined like this:
In 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>
I have camunda.cfg.xml under src/main/resources defined like this :
<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>
I'm testing my api using curl, I verified that curl -X POST http://localhost:8080/process/start
works and a process is started, after that I do curl -X POST -d '{name: "John"}' http://localhost:8080/process/next
and I see this exception in server console:
org.camunda.bpm.engine.exception.NullValueException: Cannot find task with id testtask: task is null at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?: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(Native Method) ~[?: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] at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_151] at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$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]
I don't understand why ? it does start the process so it finds process "test" but not task "testtask", why is that and how to solve the issue ?
This project is just a test of an idea for a workflow management system we'd like to build, the idea we want to test is that we can build the form our own way getting its options for select input from our own database and still use camunda as workflow engine.
Upvotes: 1
Views: 4153
Reputation: 1587
testTask
is the id of the user task in the process but not the id of the task Camunda creates at runtime when execution flow reaches the activity. You can obtain tasks via TaskService#createTaskQuery
. This should return one result in your example. Then get the ID via Task#getId
and use that as the parameter for calling FormService#submitTaskForm
.
Why is that so? You can have more then one instance of a process and therefore more than one instance per BPMN activity. Then, the activity ID cannot uniquely identify a single task instance.
Why does starting the process instance with test
work when test
is the ID in the process model? This is called in Camunda terms the process key
and when you start a process instance that way, it always refers to the latest version of a process definition with that key.
Upvotes: 3