AnsweredAssumed Answered

Unable to call javadelegate class

Question asked by surya on Feb 1, 2016
Latest reply on Feb 1, 2016 by surya
Hi,

I'm new to activiti. I have a created a stand-alone java application with simple process like[ Start->ServiceTask->End ]. Below are the files are using in sample application, Main.java, MyJavaDelegate.java & bpmn files. When running this application i'm getting below exception:

Exception:  [Validation set: 'activiti-executable-process' | Problem: 'activiti-servicetask-missing-implementation'] : One of the attributes 'class', 'delegateExpression', 'type', 'operation', or 'expression' is mandatory on serviceTask. - [Extra info : processDefinitionId = helloWorld | id = myServiceTask | ] ( line: 10, column: 92) ————-

I thought, i should register JavaDelegate class instance with ActivitiRuntimeEngine. Please suggest?

Below are the files:
——————————————————————————–
Main.java
——————————————————————————–
public class Main {
    public static void main(String[] args) throws ClassNotFoundException {
        try {
            // Create the Activiti engine in-memory on H2 database
            ProcessEngineConfiguration engineConfig = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration();
            ProcessEngine processEngine = engineConfig.buildProcessEngine();

            processEngine.getRepositoryService().createDeployment()
                    .addClasspathResource("hello-world.bpmn20.xml")
                    .deploy();
           
            ProcessInstance processInstance = processEngine.getRuntimeService()
                    .startProcessInstanceByKey("helloWorld");

            System.out.println("Process instance id:" + processInstance.getId());
           
            processEngine.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

——————————————————————————–
MyJavaDelegate.java . This files was placed in 'org.sample.delegates' package.
——————————————————————————–
public class MyJavaDelegate implements JavaDelegate {
   
   @Override
   public void execute(DelegateExecution execution) throws Exception {       
       System.out.println("Service task called…");
  }
}

——————————————————————————–
hello-world.bpmn20
——————————————————————————–
<?xml version="1.0" encoding="UTF-8"?>
<definitions id="definitions"
             xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
             xmlns:activiti="http://activiti.org/bpmn-extensions"
             targetNamespace="http://www.activiti.org/bpmn2.0">
 
  <process id="helloWorld"> 
    <startEvent id="theStart" />   
    <sequenceFlow id="flow1" sourceRef="theStart" targetRef="myServiceTask" />   
    <serviceTask id="myServiceTask" activiti:class="org.sample.delegates.MyJavaDelegate" />
    <sequenceFlow id="flow2" sourceRef="myServiceTask" targetRef="theEnd" />   
    <endEvent id="theEnd" />   
  </process>

</definitions>

Outcomes