activiti designer源码的研究(二)wsdl与bpmn20.xml的对照关系上

<一>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);
  }
}

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

相关推荐


php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念
xml文件介绍及使用
xml编程(一)-xml语法
XML文件结构和基本语法
第2章 包装类
XML入门的常见问题(二)
Java对象的强、软、弱和虚引用
JS解析XML文件和XML字符串详解
java中枚举的详细使用介绍
了解Xml格式
XML入门的常见问题(四)
深入SQLite多线程的使用总结详解
PlayFramework完整实现一个APP(一)
XML和YAML的使用方法
XML轻松学习总节篇