您的位置:首页 > 其它

activiti designer源码的研究(四) 之servicetask调用webservice(example)

2015-02-01 21:58 627 查看
一个调用webservice的例子,webservice发布在不同的包中

CounterThree.java

<span style="font-size:14px;">package org.chen.webservice;

import javax.jws.WebService;

@WebService
public interface CounterThree {
 String prettyPrintCount(String prefix, String suffix);

}</span>


CounterThreeImpl.java

<span style="font-size:14px;">package org.chen.webservice;

public class CounterThreeImpl implements CounterThree {
@Override
public String prettyPrintCount(String prefix, String suffix) {
// TODO Auto-generated method stub
return prefix + " " + suffix;
}
}</span>
Server.java

<span style="font-size:14px;">package org.chen.webservice;

import javax.xml.ws.Endpoint;

public class Server {
public static void main(String[]args){
Endpoint.publish("http://localhost:63083/CounterThree", new CounterThreeImpl());
}
}</span>
CounterTwo.java

<span style="font-size:14px;">package org.fan.webservice;

import javax.jws.WebService;

@WebService
public interface CounterTwo {
String prettyPrintCountTwo(String suffixTwo, String prefixTwo);

void inc();
}</span>
CounterTwoImpl.java

<span style="font-size:14px;">package org.fan.webservice;

public class CounterTwoImpl implements CounterTwo{

@Override
public String prettyPrintCountTwo(String suffixTwo, String prefixTwo) {
// TODO Auto-generated method stub
return suffixTwo + " "+ prefixTwo;
}

@Override
public void inc() {
// TODO Auto-generated method stub

</span>}
}
Server.java

<span style="font-size:14px;">package org.fan.webservice;

import javax.xml.ws.Endpoint;

public class Server {
public static void main(String[]args){
Endpoint.publish("http://localhost:63082/CounterTwo", new CounterTwoImpl());
}</span>
}
WebServiceSimplisticThreeTest.testWebServiceInvocationWithSimplisticDataFlow.bpmn20.xml

<span style="font-size:14px;"><?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"
xmlns:tns="org.activiti.engine.test.bpmn.servicetask"
xmlns:counter="http://webservice.activiti.org/"
typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath"
targetNamespace="org.activiti.engine.test.bpmn.servicetask">
<import importType="http://schemas.xmlsoap.org/wsdl/" location="http://localhost:63083/CounterThree?wsdl" namespace="http://webservice.activiti.org/"></import>
<import importType="http://schemas.xmlsoap.org/wsdl/" location="http://localhost:63082/CounterTwo?wsdl" namespace="http://webservice.activiti.org/"></import>

<message id="prettyPrintCountRequestMessage" itemRef="tns:prettyPrintCountRequestItem"></message>
<message id="prettyPrintCountResponseMessage" itemRef="tns:prettyPrintCountResponseItem"></message>
<message id="incRequestMessage" itemRef="tns:incRequestItem"></message>
<message id="incResponseMessage" itemRef="tns:incResponseItem"></message>
<message id="prettyPrintCountTwoRequestMessage" itemRef="tns:prettyPrintCountTwoRequestItem"></message>
<message id="prettyPrintCountTwoResponseMessage" itemRef="tns:prettyPrintCountTwoResponseItem"></message>
<itemDefinition id="prettyPrintCountRequestItem" structureRef="counter:prettyPrintCount"></itemDefinition>
<itemDefinition id="prettyPrintCountResponseItem" structureRef="counter:prettyPrintCountResponse"></itemDefinition>
<itemDefinition id="SuffixVariable" structureRef="String"></itemDefinition>
<itemDefinition id="PrettyPrintResult" structureRef="String"></itemDefinition>
<itemDefinition id="PrefixVariable" structureRef="String"></itemDefinition>
<itemDefinition id="incRequestItem" structureRef="counter:inc"></itemDefinition>
<itemDefinition id="incResponseItem" structureRef="counter:incResponse"></itemDefinition>
<itemDefinition id="prettyPrintCountTwoRequestItem" structureRef="counter:prettyPrintCountTwo"></itemDefinition>
<itemDefinition id="prettyPrintCountTwoResponseItem" structureRef="counter:prettyPrintCountTwoResponse"></itemDefinition>
<itemDefinition id="PrettyPrintTwoResult" structureRef="String"></itemDefinition>
<itemDefinition id="PrefixTwoVariable" structureRef="String"></itemDefinition>
<interface id="CounterThree Interface" name="CounterThree Interface" implementationRef="counter:CounterThree">
<operation id="prettyPrintCountOperation" name="prettyPrintCountOperation" implementationRef="counter:prettyPrintCount">
<inMessageRef>tns:prettyPrintCountRequestMessage</inMessageRef>
<outMessageRef>tns:prettyPrintCountResponseMessage</outMessageRef>
</operation>
</interface>
<interface id="CounterTwo Interface" name="CounterTwo Interface" implementationRef="counter:CounterTwo">
<operation id="incOperation" name="incOperation" implementationRef="counter:inc">
<inMessageRef>tns:incRequestMessage</inMessageRef>
<outMessageRef>tns:incResponseMessage</outMessageRef>
</operation>
<operation id="prettyPrintCountTwoOperation" name="prettyPrintCountTwoOperation" implementationRef="counter:prettyPrintCountTwo">
<inMessageRef>tns:prettyPrintCountTwoRequestMessage</inMessageRef>
<outMessageRef>tns:prettyPrintCountTwoResponseMessage</outMessageRef>
</operation>
</interface>
<process id="webServiceInvocationWithSimplisticDataFlow" name="My process" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<serviceTask id="servicetask1" name="Service Task" resultVariableName="node-pd(211.69.207.1)#进攻#CounterThreeΨCounterThree:prettyPrintCount" implementation="##WebService" operationRef="tns:prettyPrintCountOperation">
<dataInputAssociation>
<sourceRef>SuffixVariable</sourceRef>
<targetRef>arg1</targetRef>
</dataInputAssociation>
<dataInputAssociation>
<sourceRef>PrefixVariable</sourceRef>
<targetRef>arg0</targetRef>
</dataInputAssociation>
<dataOutputAssociation>
<sourceRef>_return</sourceRef>
<targetRef>PrettyPrintResult</targetRef>
</dataOutputAssociation>
</serviceTask>
<serviceTask id="servicetask2" name="Service Task" resultVariableName="node-pd(211.69.207.1)#进攻#CounterTwoΨCounterTwo:inc" implementation="##WebService" operationRef="tns:incOperation"></serviceTask>
<serviceTask id="servicetask3" name="Service Task" resultVariableName="node-pd(211.69.207.1)#进攻#CounterTwoΨCounterTwo:prettyPrintCountTwo" implementation="##WebService" operationRef="tns:prettyPrintCountTwoOperation">
<dataInputAssociation>
<sourceRef>PrefixTwoVariable</sourceRef>
<targetRef>arg1</targetRef>
</dataInputAssociation>
<dataInputAssociation>
<sourceRef>PrettyPrintResult</sourceRef>
<targetRef>arg0</targetRef>
</dataInputAssociation>
<dataOutputAssociation>
<sourceRef>_return</sourceRef>
<targetRef>PrettyPrintTwoResult</targetRef>
</dataOutputAssociation>
</serviceTask>
<receiveTask id="receivetask1" name="Receive Task"></receiveTask>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow1" sourceRef="receivetask1" targetRef="endevent1"></sequenceFlow>
<sequenceFlow id="flow2" sourceRef="startevent1" targetRef="servicetask1"></sequenceFlow>
<sequenceFlow id="flow3" sourceRef="servicetask1" targetRef="servicetask2"></sequenceFlow>
<sequenceFlow id="flow4" sourceRef="servicetask2" targetRef="servicetask3"></sequenceFlow>
<sequenceFlow id="flow5" sourceRef="servicetask3" targetRef="receivetask1"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_myProcess">
<bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="30.0" y="250.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="servicetask1" id="BPMNShape_servicetask1">
<omgdc:Bounds height="55.0" width="105.0" x="170.0" y="240.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="servicetask2" id="BPMNShape_servicetask2">
<omgdc:Bounds height="55.0" width="105.0" x="360.0" y="240.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="servicetask3" id="BPMNShape_servicetask3">
<omgdc:Bounds height="55.0" width="105.0" x="540.0" y="240.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="receivetask1" id="BPMNShape_receivetask1">
<omgdc:Bounds height="55.0" width="105.0" x="700.0" y="240.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="850.0" y="250.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="805.0" y="267.0"></omgdi:waypoint>
<omgdi:waypoint x="850.0" y="267.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="65.0" y="267.0"></omgdi:waypoint>
<omgdi:waypoint x="170.0" y="267.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="275.0" y="267.0"></omgdi:waypoint>
<omgdi:waypoint x="360.0" y="267.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
<omgdi:waypoint x="465.0" y="267.0"></omgdi:waypoint>
<omgdi:waypoint x="540.0" y="267.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
<omgdi:waypoint x="645.0" y="267.0"></omgdi:waypoint>
<omgdi:waypoint x="700.0" y="267.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions></span>
WebServiceSimplisticThreeTest.java

<span style="font-size:14px;">
package org.activiti.engine.test.bpmn.servicetask;

import java.util.HashMap;
import java.util.Map;

import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.test.Deployment;

public class WebServiceSimplisticThreeTest extends AbstractWebServiceTaskTest {

protected boolean isValidating() {
return false;
}

@Deployment
public void testWebServiceInvocationWithSimplisticDataFlow() throws Exception {
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("PrefixVariable", "The counter has the value");
variables.put("SuffixVariable","Good news");
variables.put("PrefixTwoVariable", "append What news");

ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceByKey("webServiceInvocationWithSimplisticDataFlow", variables);
waitForJobExecutorToProcessAllJobs(10000L, 250L);

String response = (String) processEngine.getRuntimeService().getVariable(instance.getId(), "PrettyPrintResult");
System.out.println(response);
assertEquals("The counter has the value Good news", response);

String response2 = (String) processEngine.getRuntimeService().getVariable(instance.getId(), "PrettyPrintTwoResult");
System.out.println(response2);
assertEquals("The counter has the value Good news append What news", response2);
}
}
</span>
注意点:

<1>被发布的类(counterTwo.java counterThree.java)在那个目录下并不重要,但是要保持targetNamespace与tns相同,并且可以随意定

<2>默认情况下,返回值sourceRef为_return,而不是return(即使wsdl上面为return)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐