<一>activiti的源码中activiti-cxf支持bpmn20.xml对webservice的调用,下面是一个例子
wsdl与activiti的规则对照
package org.activiti.engine.impl.webservice; import javax.jws.WebParam; import javax.jws.WebResult; import javax.jws.WebService; /** * A simple Counter WS that starts the counter in -1 * * @author Esteban Robles Luna */ @WebService public interface Counter { /** * Increase the counter in 1 */ void inc(); /** * Returns the current count * * @return the count */ @WebResult(name="count") int getCount(); /** * Resets the counter to 0 */ void reset(); /** * Sets the counter to value * * @param value the value of the new counter */ void setTo(@WebParam(name="value") int value); /** * Returns a formated string composed of prefix + current count + suffix * * @param prefix the prefix * @param suffix the suffix * @return the formated string */ @WebResult(name="prettyPrint") String prettyPrintCount(@WebParam(name="prefix") String prefix,@WebParam(name="suffix") String suffix); /** * * @param input1 * @param input2 * @return the formated string */ @WebResult(name="prettyPrintTwo") String prettyPrintCountTwo(@WebParam(name="suffixTwo") String suffixTwo,@WebParam(name="prefixTwo") String prefixTwo); }
<?xml version="1.0" encoding="UTF-8"?> <definitions id="definitions" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://java.sun.com/products/jsp/" targetNamespace="org.activiti.engine.test.bpmn.servicetask" xmlns:tns="org.activiti.engine.test.bpmn.servicetask" xmlns:counter="http://webservice.activiti.org/"> <!-- XML Schema is used as type language for the model whereas the Java Unified Expression Language serves as language for Expressions. --> <import importType="http://schemas.xmlsoap.org/wsdl/" location="http://localhost:63081/Counter?wsdl" namespace="http://webservice.activiti.org/" /> <process id="webServiceInvocationWithSimplisticDataFlow"> <startEvent id="theStart" /> <sequenceFlow id="flow1" sourceRef="theStart" targetRef="webService" /> <serviceTask id="webService" name="Web service invocation" implementation="##WebService" operationRef="tns:prettyPrintCountOperation"> <!-- Warning: The following code abuses the Syntax of Data Associations for a radical shortcut. --> <dataInputAssociation> <sourceRef>PrefixVariable</sourceRef><!-- name of an Activiti variable --> <targetRef>prefix</targetRef><!-- name of an element of the input message --> </dataInputAssociation> <dataInputAssociation> <sourceRef>SuffixVariable</sourceRef><!-- name of an Activiti variable --> <targetRef>suffix</targetRef><!-- name of an element of the input message --> </dataInputAssociation> <dataOutputAssociation> <sourceRef>prettyPrint</sourceRef><!-- name of an element of the output message --> <targetRef>OutputVariable</targetRef><!-- name of an Activiti variable --> </dataOutputAssociation> </serviceTask> <sequenceFlow id="flow2" sourceRef="webService" targetRef="waitState" /> <receiveTask id="waitState" /> <sequenceFlow id="flow3" sourceRef="waitState" targetRef="theEnd" /> <endEvent id="theEnd" /> </process> <itemDefinition id="PrefixVariable" structureRef="string" /> <itemDefinition id="prefix" structureRef="string" /> <itemDefinition id="SuffixVariable" structureRef="string" /> <itemDefinition id="suffix" structureRef="string" /> <itemDefinition id="prettyPrint" structureRef="string" /> <itemDefinition id="OutputVariable" structureRef="string" /> <!-- Interface: implementationRef = QName of WSDL Port Type --> <interface name="Counter Interface" implementationRef="counter:Counter"> <!-- Operation: implementationRef = QName of WSDL Operation --> <operation id="prettyPrintCountOperation" name="prettyPrintCount Operation" implementationRef="counter:prettyPrintCount"> <inMessageRef>tns:prettyPrintCountRequestMessage</inMessageRef> <outMessageRef>tns:prettyPrintCountResponseMessage</outMessageRef> </operation> </interface> <message id="prettyPrintCountRequestMessage" itemRef="tns:prettyPrintCountRequestItem" /> <message id="prettyPrintCountResponseMessage" itemRef="tns:prettyPrintCountResponseItem" /> <itemDefinition id="prettyPrintCountRequestItem" structureRef="counter:prettyPrintCount" /><!-- QName of input element --> <itemDefinition id="prettyPrintCountResponseItem" structureRef="counter:prettyPrintCountResponse" /><!-- QName of output element --> </definitions>
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; /** * @author Esteban Robles Luna */ public class WebServiceSimplisticTest 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"); ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceByKey("webServiceInvocationWithSimplisticDataFlow",variables); waitForJobExecutorToProcessAllJobs(10000L,250L); String response = (String) processEngine.getRuntimeService().getVariable(instance.getId(),"OutputVariable"); assertEquals("The counter has the value -1. Good news",response); } }