web service task是BPMN2.0中的一种任务类型,在activiti5中它并没有专门的标签表示,而是使用了service task 来表示。而且有很多要配置的内容是无法用图形化工具来完成的。要使用web service task,当然要先有web service。所以首先要编写一个web service。
首先是JAR包:
编写webservice的接口:
package org.mpc.activiti.webservice;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
@WebService
public interface MpcService {
@WebMethod
@WebResult(name = "address")//返回值的名称为address
String createMpc(@WebParam(name = "name") String name);//定义了一个名称为name的String类型的参数
}
编写webservice的实现类:
package org.mpc.activiti.webservice;
import javax.jws.WebService;
@WebService(endpointInterface = "org.mpc.activiti.webservice.MpcService", serviceName = "MpcService")
public class MpcServiceImpl implements MpcService {
public String createMpc(String name) {
System.out.println("创建人:" + name);
Mpc mpc = new Mpc();
mpc.setAdd("香格里拉");
return mpc.getAdd();
}
}
实体类Mpc
package org.mpc.activiti.webservice;
public class Mpc {
private String name;
private String add;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAdd() {
return add;
}
public void setAdd(String add) {
this.add = add;
}
}
在主程序中发布web service:
package org.mpc.activiti.webservice;
import javax.xml.ws.Endpoint;
public class Main {
public static void main(String args[]) throws Exception {
//实例化一个MpcServiceImpl的对象,并在http://localhost:9090/mpc的地址中发布webservice
Endpoint.publish("http://localhost:9090/mpc", new MpcServiceImpl());
System.out.println("服务启动...");
Thread.sleep(100 * 60 * 1000);//随意设个时间,不要立马退出程序,最好长一点
System.exit(0);
}
}
运行main以后在浏览器中输入http://localhost:9090/mpc?wsdl会看到如下内容:
<wsdl:definitions xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://webservice.activiti.mpc.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="MpcService" targetNamespace="http://webservice.activiti.mpc.org/">
<wsdl:types>
<xs:schema xmlns:tns="http://webservice.activiti.mpc.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" targetNamespace="http://webservice.activiti.mpc.org/" version="1.0">
<xs:element name="createMpc" type="tns:createMpc"/>
<xs:element name="createMpcResponse" type="tns:createMpcResponse"/>
<xs:complexType name="createMpc">
<xs:sequence>
<xs:element minOccurs="0" name="name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="createMpcResponse">
<xs:sequence>
<xs:element minOccurs="0" name="address" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="createMpcResponse">
<wsdl:part element="tns:createMpcResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="createMpc">
<wsdl:part element="tns:createMpc" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:portType name="MpcService">
<wsdl:operation name="createMpc">
<wsdl:input message="tns:createMpc" name="createMpc"></wsdl:input>
<wsdl:output message="tns:createMpcResponse" name="createMpcResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="MpcServiceSoapBinding" type="tns:MpcService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="createMpc">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="createMpc">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="createMpcResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="MpcService">
<wsdl:port binding="tns:MpcServiceSoapBinding" name="MpcServiceImplPort">
<soap:address location="http://localhost:9090/mpc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
在这份wsdl文档结构中,我们可以得到如下信息:
有name 和 address 两个string类型的变量;有两个消息,分别是createMpc和createMpcResponse,两者都是用来和activiti交互的消息,前者接受参数,后者返回信息; 还有MpcService中的creatreMpc方法,供activiti调用。
在activiti5中访问webservice
方式一 直接的、纯粹的webservice
JAR包:
流程图:
该流程对应的xml
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test"
xmlns:mpc="http://webservice.activiti.mpc.org/"><!-- 这里的namespace是对应于wsdl中的namespace的,在这里定义一下方便后面使用 -->
<!--引入外部的wsdl文件中存储的数据,也就是我们的webservice生成的wsdl数据 -->
<import importType="http://schemas.xmlsoap.org/wsdl/" location="http://localhost:9090/mpc?wsdl"
namespace="http://webservice.activiti.mpc.org/" />
<process id="service1" name="service1">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="Ready Task"></userTask>
<serviceTask id="servicetask1" name="Web service invocation"
implementation="##WebService" operationRef="createMpcOper"><!-- 这里的 implementation="##WebService"
表明这是一个webservice任务 operationRef="createPostOper"指明了这个webservice要执行的操作 -->
<dataInputAssociation><!-- 要输入的参数 ,可以有多个 -->
<sourceRef>nameVar</sourceRef><!--输入变量在流程中名称 -->
<targetRef>name</targetRef><!--输入变量在wsdl中的名称 -->
</dataInputAssociation>
<dataOutputAssociation><!--输出的参数,只可以有一个 -->
<sourceRef>address</sourceRef><!-- 输出变量在wsdl中名称 -->
<targetRef>addVar</targetRef><!-- 输出变量在流程中的名称 -->
</dataOutputAssociation>
<!-- sourceRef就是变量在来源中的名称 targetRef就是变量在目标中的名称 -->
</serviceTask>
<userTask id="usertask2" name="EndTask"></userTask>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow1" name="" sourceRef="startevent1"
targetRef="usertask1"></sequenceFlow>
<sequenceFlow id="flow2" name="" sourceRef="usertask1"
targetRef="servicetask1"></sequenceFlow>
<sequenceFlow id="flow3" name="" sourceRef="servicetask1"
targetRef="usertask2"></sequenceFlow>
<sequenceFlow id="flow4" name="" sourceRef="usertask2"
targetRef="endevent1"></sequenceFlow>
</process>
<!-- 所谓的message 就是activiti 和 webservice 之间的数据交流的信息 -->
<message id="createMpcMsg" itemRef="createMpcItem"></message>
<message id="createMpcResponseMsg" itemRef="createMpcResponseItem"></message><!-- 这里定义了消息,itemRef="createMpcResponseItem"
定义了这个消息的类型 -->
<itemDefinition id="createMpcItem" structureRef="mpc:createMpc" />
<itemDefinition id="createMpcResponseItem" structureRef="mpc:createMpcResponse" /><!--
类型对应于wsdl中的文档结构 -->
<!--start -->
<itemDefinition id="nameVar" structureRef="string" />
<itemDefinition id="name" structureRef="string" />
<itemDefinition id="address" structureRef="string" />
<itemDefinition id="addVar" structureRef="string" />
<!-- end --><!-- 指定每个变量的类型 -->
<interface name="Mpc Service" implementationRef="MpcService">
<operation id="createMpcOper" name="Create Mpc Operation"
implementationRef="mpc:createMpc">
<inMessageRef>createMpcMsg</inMessageRef>
<outMessageRef>createMpcResponseMsg</outMessageRef>
</operation>
</interface>
<bpmndi:BPMNDiagram id="BPMNDiagram_process1">
<bpmndi:BPMNPlane bpmnElement="process1" id="BPMNPlane_process1">
<bpmndi:BPMNShape bpmnElement="startevent1"
id="BPMNShape_startevent1">
<omgdc:Bounds height="35" width="35" x="190" y="210"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55" width="105" x="280" y="200"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="servicetask1"
id="BPMNShape_servicetask1">
<omgdc:Bounds height="55" width="105" x="440" y="200"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
<omgdc:Bounds height="55" width="105" x="610" y="200"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35" width="35" x="770" y="210"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="225" y="227"></omgdi:waypoint>
<omgdi:waypoint x="280" y="227"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="385" y="227"></omgdi:waypoint>
<omgdi:waypoint x="440" y="227"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="545" y="227"></omgdi:waypoint>
<omgdi:waypoint x="610" y="227"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
<omgdi:waypoint x="715" y="227"></omgdi:waypoint>
<omgdi:waypoint x="770" y="227"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
测试方法:
package bpmn;
import java.util.HashMap;
import java.util.Map;
import org.activiti.engine.impl.test.PluggableActivitiTestCase;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.activiti.engine.test.Deployment;
import org.junit.Test;
public class WebServiceTest extends PluggableActivitiTestCase {
@Test
@Deployment(resources = "bpmn/WebService1.bpmn")
public void test() {
// 初始化参数
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("nameVar", "mpc_test");
ProcessInstance pi = runtimeService.startProcessInstanceByKey(
"service1", vars);
// 完成第一个任务
Task task = taskService.createTaskQuery().singleResult();
taskService.complete(task.getId());
// 输出调用Web Service后的参数
String add = (String) runtimeService.getVariable(pi.getId(), "addVar");
System.out.println("↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓");
System.out.println();
System.out.println();
System.out.println("mpc_test现在居住的地点是—————————————————————————>" + add);
System.out.println();
System.out.println();
System.out.println("↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑");
}
}
测试的结果是绿条,输出结果如下:
在webservice端的输出为:
在测试端的输出为:
方式二 使用 java delegate来实现web service任务
上面的方式太复杂,而且没有图形化的设计界面,容易出错,下面这种就好多了。
使用的jar包和方式一是一样的。
流程图:
然后可以利用图形化的工具来编辑我们的service task
当然也可以用xml的方式编辑,这是完成后的xml
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="delegate" name="process1" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<serviceTask id="servicetask1" name="Service Task" activiti:class="bpmn.WebServiceDelegate">
<extensionElements>
<activiti:field name="wsdl">
<activiti:string><![CDATA[http://localhost:9090/mpc?wsdl]]></activiti:string>
</activiti:field>
<activiti:field name="operation">
<activiti:string><![CDATA[createMpc]]></activiti:string>
</activiti:field>
<activiti:field name="name">
<activiti:string><![CDATA[mpc_test]]></activiti:string>
</activiti:field>
</extensionElements>
</serviceTask>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="servicetask1"></sequenceFlow>
<sequenceFlow id="flow2" sourceRef="servicetask1" targetRef="endevent1"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_delegate">
<bpmndi:BPMNPlane bpmnElement="delegate" id="BPMNPlane_delegate">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="250.0" y="210.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="servicetask1" id="BPMNShape_servicetask1">
<omgdc:Bounds height="55.0" width="105.0" x="330.0" y="200.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="490.0" y="210.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="285.0" y="227.0"></omgdi:waypoint>
<omgdi:waypoint x="330.0" y="227.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="435.0" y="227.0"></omgdi:waypoint>
<omgdi:waypoint x="490.0" y="227.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
代理类:
package bpmn;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.Expression;
import org.activiti.engine.delegate.JavaDelegate;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
public class WebServiceDelegate implements JavaDelegate {
/*
* 这些变量我们都在流程中进行了定义,
* 也就是说通过流程注入到了这个代理类中,当然要用activiti流程注入,
* 就要使用activiti的数据类型Expression
* */
private Expression wsdl;
private Expression operation;
private Expression name;
// 要注入当然要有set方法
public void setWsdl(Expression wsdl) {
this.wsdl = wsdl;
}
public void setOperation(Expression operation) {
this.operation = operation;
}
public void setName(Expression name) {
this.name = name;
}
@Override
public void execute(DelegateExecution execution) throws Exception {
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
// 使用wsdl数据创建Client
Client client = dcf.createClient((String) wsdl.getValue(execution));
//创建请求的参数
Object [] vars = new Object[] {name.getValue(execution)};
//发出请求
Object [] results = client.invoke((String)operation.getValue(execution), vars);
String result=(String)results[0];
System.out.println("↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓");
System.out.println();
System.out.println();
System.out.println("mpc_test现在居住的地点是—————————————————————————>" + result);
System.out.println();
System.out.println();
System.out.println("↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑");
}
}
测试类:
package bpmn;
import org.activiti.engine.impl.test.PluggableActivitiTestCase;
import org.activiti.engine.test.Deployment;
import org.junit.Test;
public class JavaDelegateWebServiceTest extends PluggableActivitiTestCase {
@Test
@Deployment(resources = "bpmn/JavaDelegateWebService1.bpmn")
public void test() {
runtimeService.startProcessInstanceByKey("delegate");
}
}
测试结果:
绿条没问题
web service的输出:(有上次的测试输出,所以是两条)
测试端的输出:
下面是service task 的另一种变化 shell service
和以上两个测试在同一个工程下,所以JAR包们是没有变化的。
流程图:
流程图对应的xml:
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI"
typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath"
targetNamespace="http://www.activiti.org/test">
<process id="shellservice" name="shellservice" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<serviceTask id="servicetask1" name="Service Task"
activiti:type="shell"><!-- 这里要制定这个servicetask是 activiti:type="shell" -->
<extensionElements>
<!-- 这些属性可以在图形化界面中添加,也可以在xml模式下添加,这些属性是要注入给ActivitiBehaviour类的,有该类实现shell任务 -->
<activiti:field name="command">
<activiti:string><![CDATA[cmd]]></activiti:string>
</activiti:field>
<activiti:field name="arg1">
<activiti:string><![CDATA[/c]]></activiti:string>
</activiti:field>
<activiti:field name="arg2">
<activiti:string><![CDATA[echo]]></activiti:string>
</activiti:field>
<activiti:field name="arg3">
<activiti:string><![CDATA[%TEMP%]]></activiti:string>
</activiti:field>
<activiti:field name="outputVariable">
<activiti:string><![CDATA[TEMP]]></activiti:string>
</activiti:field>
</extensionElements>
</serviceTask>
<sequenceFlow id="flow1" sourceRef="startevent1"
targetRef="servicetask1"></sequenceFlow>
<userTask id="usertask1" name="User Task"></userTask>
<sequenceFlow id="flow2" sourceRef="servicetask1"
targetRef="usertask1"></sequenceFlow>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow3" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_shellservice">
<bpmndi:BPMNPlane bpmnElement="shellservice"
id="BPMNPlane_shellservice">
<bpmndi:BPMNShape bpmnElement="startevent1"
id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="250.0" y="160.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="servicetask1"
id="BPMNShape_servicetask1">
<omgdc:Bounds height="55.0" width="105.0" x="330.0" y="150.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="480.0" y="150.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="630.0" y="160.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="285.0" y="177.0"></omgdi:waypoint>
<omgdi:waypoint x="330.0" y="177.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="435.0" y="177.0"></omgdi:waypoint>
<omgdi:waypoint x="480.0" y="177.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="585.0" y="177.0"></omgdi:waypoint>
<omgdi:waypoint x="630.0" y="177.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
测试类:
package bpmn;
import org.activiti.engine.impl.test.PluggableActivitiTestCase;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.test.Deployment;
import org.junit.Test;
public class ShellTaskTest extends PluggableActivitiTestCase {
@Test
@Deployment(resources = "bpmn/shellTask.bpmn")
public void test() {
ProcessInstance pi = runtimeService
.startProcessInstanceByKey("shellservice");
String result = (String) runtimeService.getVariable(pi.getId(), "TEMP");
System.out.println(result);
}
}
这里我在测试类中通过shell命令获得了我的计算机的TEMP变量的值并输出了
测试结果如下:
啊,所有的测试案例中的activiti.cfg.xml都是如下定义的:
<?xml version="1.0" encoding="UTF-8"?>
<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
class="org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration"
id="processEngineConfiguration">
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activi" />
<property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
<property name="jdbcUsername" value="root" />
<property name="jdbcPassword" value="root" />
<property name="databaseSchemaUpdate" value="true" />
<property name="jobExecutorActivate" value="true" />
<property name="mailServerHost" value="mail.my-corp.com" />
<property name="mailServerPort" value="5025" />
<property name="history" value="full"></property>
</bean>
</beans>