一个调用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)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。