江山市住房和城乡建设局网站,win7做网站服务器,vps搭建网站是什么意思,wordpress 3.8漏洞web service task是BPMN2.0中的一种任务类型#xff0c;在activiti5中它并没有专门的标签表示#xff0c;而是使用了service task 来表示。而且有很多要配置的内容是无法用图形化工具来完成的。要使用web service task#xff0c;当然要先有web service。所以首先要编写一个…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 {WebMethodWebResult(name address)//返回值的名称为addressString 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的地址中发布webserviceEndpoint.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:ns1http://schemas.xmlsoap.org/soap/http xmlns:soaphttp://schemas.xmlsoap.org/wsdl/soap/ xmlns:tnshttp://webservice.activiti.mpc.org/ xmlns:wsdlhttp://schemas.xmlsoap.org/wsdl/ xmlns:xsdhttp://www.w3.org/2001/XMLSchema nameMpcService targetNamespacehttp://webservice.activiti.mpc.org/
wsdl:types
xs:schema xmlns:tnshttp://webservice.activiti.mpc.org/ xmlns:xshttp://www.w3.org/2001/XMLSchema elementFormDefaultunqualified targetNamespacehttp://webservice.activiti.mpc.org/ version1.0
xs:element namecreateMpc typetns:createMpc/
xs:element namecreateMpcResponse typetns:createMpcResponse/
xs:complexType namecreateMpc
xs:sequence
xs:element minOccurs0 namename typexs:string/
/xs:sequence
/xs:complexType
xs:complexType namecreateMpcResponse
xs:sequence
xs:element minOccurs0 nameaddress typexs:string/
/xs:sequence
/xs:complexType
/xs:schema
/wsdl:types
wsdl:message namecreateMpcResponse
wsdl:part elementtns:createMpcResponse nameparameters/wsdl:part
/wsdl:message
wsdl:message namecreateMpc
wsdl:part elementtns:createMpc nameparameters/wsdl:part
/wsdl:message
wsdl:portType nameMpcService
wsdl:operation namecreateMpc
wsdl:input messagetns:createMpc namecreateMpc/wsdl:input
wsdl:output messagetns:createMpcResponse namecreateMpcResponse/wsdl:output
/wsdl:operation
/wsdl:portType
wsdl:binding nameMpcServiceSoapBinding typetns:MpcService
soap:binding styledocument transporthttp://schemas.xmlsoap.org/soap/http/
wsdl:operation namecreateMpc
soap:operation soapAction styledocument/
wsdl:input namecreateMpc
soap:body useliteral/
/wsdl:input
wsdl:output namecreateMpcResponse
soap:body useliteral/
/wsdl:output
/wsdl:operation
/wsdl:binding
wsdl:service nameMpcService
wsdl:port bindingtns:MpcServiceSoapBinding nameMpcServiceImplPort
soap:address locationhttp://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 version1.0 encodingUTF-8?
definitions xmlnshttp://www.omg.org/spec/BPMN/20100524/MODELxmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xmlns:activitihttp://activiti.org/bpmnxmlns:bpmndihttp://www.omg.org/spec/BPMN/20100524/DI xmlns:omgdchttp://www.omg.org/spec/DD/20100524/DCxmlns:omgdihttp://www.omg.org/spec/DD/20100524/DI typeLanguagehttp://www.w3.org/2001/XMLSchemaexpressionLanguagehttp://www.w3.org/1999/XPath targetNamespacehttp://www.activiti.org/testxmlns:mpchttp://webservice.activiti.mpc.org/!-- 这里的namespace是对应于wsdl中的namespace的在这里定义一下方便后面使用 --!--引入外部的wsdl文件中存储的数据也就是我们的webservice生成的wsdl数据 --import importTypehttp://schemas.xmlsoap.org/wsdl/ locationhttp://localhost:9090/mpc?wsdlnamespacehttp://webservice.activiti.mpc.org/ /process idservice1 nameservice1startEvent idstartevent1 nameStart/startEventuserTask idusertask1 nameReady Task/userTaskserviceTask idservicetask1 nameWeb service invocationimplementation##WebService operationRefcreateMpcOper!-- 这里的 implementation##WebService 表明这是一个webservice任务 operationRefcreatePostOper指明了这个webservice要执行的操作 --dataInputAssociation!-- 要输入的参数 可以有多个 --sourceRefnameVar/sourceRef!--输入变量在流程中名称 --targetRefname/targetRef!--输入变量在wsdl中的名称 --/dataInputAssociationdataOutputAssociation!--输出的参数只可以有一个 --sourceRefaddress/sourceRef!-- 输出变量在wsdl中名称 --targetRefaddVar/targetRef!-- 输出变量在流程中的名称 --/dataOutputAssociation!-- sourceRef就是变量在来源中的名称 targetRef就是变量在目标中的名称 --/serviceTaskuserTask idusertask2 nameEndTask/userTaskendEvent idendevent1 nameEnd/endEventsequenceFlow idflow1 name sourceRefstartevent1targetRefusertask1/sequenceFlowsequenceFlow idflow2 name sourceRefusertask1targetRefservicetask1/sequenceFlowsequenceFlow idflow3 name sourceRefservicetask1targetRefusertask2/sequenceFlowsequenceFlow idflow4 name sourceRefusertask2targetRefendevent1/sequenceFlow/process!-- 所谓的message 就是activiti 和 webservice 之间的数据交流的信息 --message idcreateMpcMsg itemRefcreateMpcItem/messagemessage idcreateMpcResponseMsg itemRefcreateMpcResponseItem/message!-- 这里定义了消息itemRefcreateMpcResponseItem 定义了这个消息的类型 --itemDefinition idcreateMpcItem structureRefmpc:createMpc /itemDefinition idcreateMpcResponseItem structureRefmpc:createMpcResponse /!-- 类型对应于wsdl中的文档结构 --!--start --itemDefinition idnameVar structureRefstring /itemDefinition idname structureRefstring /itemDefinition idaddress structureRefstring /itemDefinition idaddVar structureRefstring /!-- end --!-- 指定每个变量的类型 --interface nameMpc Service implementationRefMpcServiceoperation idcreateMpcOper nameCreate Mpc OperationimplementationRefmpc:createMpcinMessageRefcreateMpcMsg/inMessageRefoutMessageRefcreateMpcResponseMsg/outMessageRef/operation/interfacebpmndi:BPMNDiagram idBPMNDiagram_process1bpmndi:BPMNPlane bpmnElementprocess1 idBPMNPlane_process1bpmndi:BPMNShape bpmnElementstartevent1idBPMNShape_startevent1omgdc:Bounds height35 width35 x190 y210/omgdc:Bounds/bpmndi:BPMNShapebpmndi:BPMNShape bpmnElementusertask1 idBPMNShape_usertask1omgdc:Bounds height55 width105 x280 y200/omgdc:Bounds/bpmndi:BPMNShapebpmndi:BPMNShape bpmnElementservicetask1idBPMNShape_servicetask1omgdc:Bounds height55 width105 x440 y200/omgdc:Bounds/bpmndi:BPMNShapebpmndi:BPMNShape bpmnElementusertask2 idBPMNShape_usertask2omgdc:Bounds height55 width105 x610 y200/omgdc:Bounds/bpmndi:BPMNShapebpmndi:BPMNShape bpmnElementendevent1 idBPMNShape_endevent1omgdc:Bounds height35 width35 x770 y210/omgdc:Bounds/bpmndi:BPMNShapebpmndi:BPMNEdge bpmnElementflow1 idBPMNEdge_flow1omgdi:waypoint x225 y227/omgdi:waypointomgdi:waypoint x280 y227/omgdi:waypoint/bpmndi:BPMNEdgebpmndi:BPMNEdge bpmnElementflow2 idBPMNEdge_flow2omgdi:waypoint x385 y227/omgdi:waypointomgdi:waypoint x440 y227/omgdi:waypoint/bpmndi:BPMNEdgebpmndi:BPMNEdge bpmnElementflow3 idBPMNEdge_flow3omgdi:waypoint x545 y227/omgdi:waypointomgdi:waypoint x610 y227/omgdi:waypoint/bpmndi:BPMNEdgebpmndi:BPMNEdge bpmnElementflow4 idBPMNEdge_flow4omgdi:waypoint x715 y227/omgdi:waypointomgdi:waypoint x770 y227/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 {TestDeployment(resources bpmn/WebService1.bpmn)public void test() {// 初始化参数MapString, Object vars new HashMapString, 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 version1.0 encodingUTF-8?
definitions xmlnshttp://www.omg.org/spec/BPMN/20100524/MODEL xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xmlns:xsdhttp://www.w3.org/2001/XMLSchema xmlns:activitihttp://activiti.org/bpmn xmlns:bpmndihttp://www.omg.org/spec/BPMN/20100524/DI xmlns:omgdchttp://www.omg.org/spec/DD/20100524/DC xmlns:omgdihttp://www.omg.org/spec/DD/20100524/DI typeLanguagehttp://www.w3.org/2001/XMLSchema expressionLanguagehttp://www.w3.org/1999/XPath targetNamespacehttp://www.activiti.org/testprocess iddelegate nameprocess1 isExecutabletruestartEvent idstartevent1 nameStart/startEventserviceTask idservicetask1 nameService Task activiti:classbpmn.WebServiceDelegateextensionElementsactiviti:field namewsdlactiviti:string![CDATA[http://localhost:9090/mpc?wsdl]]/activiti:string/activiti:fieldactiviti:field nameoperationactiviti:string![CDATA[createMpc]]/activiti:string/activiti:fieldactiviti:field namenameactiviti:string![CDATA[mpc_test]]/activiti:string/activiti:field/extensionElements/serviceTaskendEvent idendevent1 nameEnd/endEventsequenceFlow idflow1 sourceRefstartevent1 targetRefservicetask1/sequenceFlowsequenceFlow idflow2 sourceRefservicetask1 targetRefendevent1/sequenceFlow/processbpmndi:BPMNDiagram idBPMNDiagram_delegatebpmndi:BPMNPlane bpmnElementdelegate idBPMNPlane_delegatebpmndi:BPMNShape bpmnElementstartevent1 idBPMNShape_startevent1omgdc:Bounds height35.0 width35.0 x250.0 y210.0/omgdc:Bounds/bpmndi:BPMNShapebpmndi:BPMNShape bpmnElementservicetask1 idBPMNShape_servicetask1omgdc:Bounds height55.0 width105.0 x330.0 y200.0/omgdc:Bounds/bpmndi:BPMNShapebpmndi:BPMNShape bpmnElementendevent1 idBPMNShape_endevent1omgdc:Bounds height35.0 width35.0 x490.0 y210.0/omgdc:Bounds/bpmndi:BPMNShapebpmndi:BPMNEdge bpmnElementflow1 idBPMNEdge_flow1omgdi:waypoint x285.0 y227.0/omgdi:waypointomgdi:waypoint x330.0 y227.0/omgdi:waypoint/bpmndi:BPMNEdgebpmndi:BPMNEdge bpmnElementflow2 idBPMNEdge_flow2omgdi:waypoint x435.0 y227.0/omgdi:waypointomgdi:waypoint x490.0 y227.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;}Overridepublic void execute(DelegateExecution execution) throws Exception {JaxWsDynamicClientFactory dcf JaxWsDynamicClientFactory.newInstance();// 使用wsdl数据创建ClientClient 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 {TestDeployment(resources bpmn/JavaDelegateWebService1.bpmn)public void test() {runtimeService.startProcessInstanceByKey(delegate);}}测试结果
绿条没问题
web service的输出有上次的测试输出所以是两条 测试端的输出 下面是service task 的另一种变化 shell service
和以上两个测试在同一个工程下所以JAR包们是没有变化的。
流程图 流程图对应的xml ?xml version1.0 encodingUTF-8?
definitions xmlnshttp://www.omg.org/spec/BPMN/20100524/MODELxmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xmlns:xsdhttp://www.w3.org/2001/XMLSchemaxmlns:activitihttp://activiti.org/bpmn xmlns:bpmndihttp://www.omg.org/spec/BPMN/20100524/DIxmlns:omgdchttp://www.omg.org/spec/DD/20100524/DC xmlns:omgdihttp://www.omg.org/spec/DD/20100524/DItypeLanguagehttp://www.w3.org/2001/XMLSchema expressionLanguagehttp://www.w3.org/1999/XPathtargetNamespacehttp://www.activiti.org/testprocess idshellservice nameshellservice isExecutabletruestartEvent idstartevent1 nameStart/startEventserviceTask idservicetask1 nameService Taskactiviti:typeshell!-- 这里要制定这个servicetask是 activiti:typeshell --extensionElements!-- 这些属性可以在图形化界面中添加也可以在xml模式下添加这些属性是要注入给ActivitiBehaviour类的有该类实现shell任务 --activiti:field namecommandactiviti:string![CDATA[cmd]]/activiti:string/activiti:fieldactiviti:field namearg1activiti:string![CDATA[/c]]/activiti:string/activiti:fieldactiviti:field namearg2activiti:string![CDATA[echo]]/activiti:string/activiti:fieldactiviti:field namearg3activiti:string![CDATA[%TEMP%]]/activiti:string/activiti:fieldactiviti:field nameoutputVariableactiviti:string![CDATA[TEMP]]/activiti:string/activiti:field/extensionElements/serviceTasksequenceFlow idflow1 sourceRefstartevent1targetRefservicetask1/sequenceFlowuserTask idusertask1 nameUser Task/userTasksequenceFlow idflow2 sourceRefservicetask1targetRefusertask1/sequenceFlowendEvent idendevent1 nameEnd/endEventsequenceFlow idflow3 sourceRefusertask1 targetRefendevent1/sequenceFlow/processbpmndi:BPMNDiagram idBPMNDiagram_shellservicebpmndi:BPMNPlane bpmnElementshellserviceidBPMNPlane_shellservicebpmndi:BPMNShape bpmnElementstartevent1idBPMNShape_startevent1omgdc:Bounds height35.0 width35.0 x250.0 y160.0/omgdc:Bounds/bpmndi:BPMNShapebpmndi:BPMNShape bpmnElementservicetask1idBPMNShape_servicetask1omgdc:Bounds height55.0 width105.0 x330.0 y150.0/omgdc:Bounds/bpmndi:BPMNShapebpmndi:BPMNShape bpmnElementusertask1 idBPMNShape_usertask1omgdc:Bounds height55.0 width105.0 x480.0 y150.0/omgdc:Bounds/bpmndi:BPMNShapebpmndi:BPMNShape bpmnElementendevent1 idBPMNShape_endevent1omgdc:Bounds height35.0 width35.0 x630.0 y160.0/omgdc:Bounds/bpmndi:BPMNShapebpmndi:BPMNEdge bpmnElementflow1 idBPMNEdge_flow1omgdi:waypoint x285.0 y177.0/omgdi:waypointomgdi:waypoint x330.0 y177.0/omgdi:waypoint/bpmndi:BPMNEdgebpmndi:BPMNEdge bpmnElementflow2 idBPMNEdge_flow2omgdi:waypoint x435.0 y177.0/omgdi:waypointomgdi:waypoint x480.0 y177.0/omgdi:waypoint/bpmndi:BPMNEdgebpmndi:BPMNEdge bpmnElementflow3 idBPMNEdge_flow3omgdi:waypoint x585.0 y177.0/omgdi:waypointomgdi:waypoint x630.0 y177.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 {TestDeployment(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 version1.0 encodingUTF-8?beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdbeanclassorg.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfigurationidprocessEngineConfigurationproperty namejdbcUrl valuejdbc:mysql://localhost:3306/activi /property namejdbcDriver valuecom.mysql.jdbc.Driver /property namejdbcUsername valueroot /property namejdbcPassword valueroot /property namedatabaseSchemaUpdate valuetrue /property namejobExecutorActivate valuetrue /property namemailServerHost valuemail.my-corp.com /property namemailServerPort value5025 /property namehistory valuefull/property/bean/beans