Service tasks are used to request out-of-process tasks or automate tasks, with 3 implementations: Java service Task/web Service/task and Shelltask,
When the process arrives at the task, the corresponding Java class or WebService or shell command is executed.
1.Java Service Task
1.1 Specifies the Java class using Activiti:class, which must be implemented javadelegate,activiti each time a new instance is created.
Public class Implements javadelegate{ publicvoidthrows Exception { System.out.println ( "Implement javadelegate this ); }}
Process file Full name limit Delete class
<id= "Servicetask1" name= "Service Task 1" <!-- Myjavadelegate must be Javadelegate implementation class--> activiti:class= " Org.crazyit.activiti.MyJavaDelegate "></servicetask>
1.2 Specifies the Java class using DelegateExpression, which must implement Javadelegate and serializable
A. Creating a Java service task class
Public class Implements Javadelegate, Serializable { publicvoidthrows Exception { System.out.println ("implement javadelegate this ); }}
B. Process file Juel expression
<id= "Servicetask1" name= "Service Task" Activiti: DelegateExpression= "${mydelegate}"></servicetask>
C. The creation of the instance is provided by the provider, and the instance is set to the process parameters:
// Deployment Process Files
Repositoryservice.createdeployment (). Addclasspathresource ("BPMN/JUELCLASS.BPMN"). deploy (); New Hashmap<string, object>(); Vars.put (new myjavadelegate ()); // START Process ProcessInstance pi = Runtimeservice.startprocessinstancebykey ("Process1", VARs);
1.3 Calling a normal Java bean using activiti:expression
A. Creating a Java bean
Public class Implements Serializable { public String getName () { return "Bestmyself" } Public void print (execution exe) { System.out.println ("Print method using Java Bean:" + Exe.getid ());} }
B. Process files combined with Juel call object methods
<ServicetaskID= "Servicetask1"name= "Service Task"<!--Execute the Mybean Print method-->activiti:expression= "${mybean.print (Execution)}" ></Servicetask> <ServicetaskID= "Servicetask2"name= "Service Task"<!--execution Mybean.getname () method-->activiti:expression= "${execution.setvariable (' MyName ', Mybean.name)}" ></Servicetask>
C. Setting up Java bean instances into the process
New Hashmap<string, object>(); Vars.put (new Myjavabean ()); // START Process ProcessInstance pi = Runtimeservice.startprocessinstancebykey ("Process1", VARs); // Query for Task parameters System.out.println ( runtimeservice.getvariable (Pi.getid (), "MyName"));
Process Tasks-service tasks (Java service Task)