Search code examples
javadroolsjbpmbpmn

JBPM 6 - Creating a process with a "service task" like node, programmatically


JBPM 6 user guide has listed an example which allows a workflow process to be created programmatically using Process API.

I followed the example to create a service task (a task which has a class associated with, having the actual node execution code). Here's my code

//Headers
RuleFlowNodeContainerFactory rfncf = factory.name(process.getName()).version("1.0").packageName("test.package")
// Nodes
.startNode(1).name("Start").done();

rfncf.actionNode(1).name("sample-node-name")
     .action(new Action() {
            @Override
            public void execute(ProcessContext context) throws Exception {
                System.out.println("testing execution...");
            }
      })
.done();

In the above example, I am creating an action node and associating it with an anonymous inner class which implements org.jbpm.process.instance.impl.Action

When I run this code, I get the following exception

java.lang.ClassCastException: org.jbpm.workflow.core.DroolsAction cannot be cast to org.jbpm.workflow.core.impl.DroolsConsequenceAction
  at org.jbpm.bpmn2.xml.XmlBPMNProcessDumper.visitEscalations(XmlBPMNProcessDumper.java:505)
  at org.jbpm.bpmn2.xml.XmlBPMNProcessDumper.visitProcess(XmlBPMNProcessDumper.java:143)
  at org.jbpm.bpmn2.xml.XmlBPMNProcessDumper.dump(XmlBPMNProcessDumper.java:98)
  at org.jbpm.bpmn2.xml.XmlBPMNProcessDumper.dump(XmlBPMNProcessDumper.java:89)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Searching on google yielded to an open bug on JBPM side (https://issues.jboss.org/browse/JBPM-4378).

My question is, is there any alternative way of achieving the same?


Solution

  • you can checkout a Process Fluent API example by Mariano De Maio, author of the jBPM6 Developer Guide. It's a little bit different approach (not using the RuleFlowNodeContainerFactory), but I can confirm that this one is working ;-)

    Regards.