`
猫不吃的鱼
  • 浏览: 157165 次
  • 性别: Icon_minigender_1
  • 来自: 芜湖市
社区版块
存档分类
最新评论

activiti webservice task 的一个简单执行和配置实例

 
阅读更多
一、webservice的服务端简单实现

@WebService
public interface Calculator {
	@WebMethod
	@WebResult(name = "num3")
	public int plus(@WebParam(name = "num1") int num1,
			@WebParam(name = "num2") int num2);
}


@WebService(endpointInterface = "com.first.service.Calculator",
			serviceName = "calculator")
public class CalculatorImpl implements Calculator{

	@Override
	public int plus(int num1, int num2) {
		return num1+num2;
	}

}

public static void main(String[] args) {
		Calculator calculator;
		Server server;
		calculator = new CalculatorImpl();
	        JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
	        svrFactory.setServiceClass(Calculator.class);
	        svrFactory.setAddress("http://localhost:63081/calculator");
	        svrFactory.setServiceBean(calculator);
	        svrFactory.getInInterceptors().add(new LoggingInInterceptor());
	        svrFactory.getOutInterceptors().add(new LoggingOutInterceptor());
	        server = svrFactory.create();
	        server.start();
}

java实现一个简单的webservice服务端,并且为调用方法的传入传出参数指定名称,方便activiti中引用
二、activiti


流程定义文件



<?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: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" 
			 typeLanguage="http://www.w3.org/2001/XMLSchema" 
			 expressionLanguage="http://www.w3.org/1999/XPath" 
			 targetNamespace="com.first.service"
			 xmlns:tns="com.first.service"
                         xmlns:calculator="http://webservice.activiti.org/">
             
 <import importType="http://schemas.xmlsoap.org/wsdl/"
          location="http://localhost:63081/calculator?wsdl"
          namespace="http://webservice.activiti.org/" />			 
			 
  <process id="process1" name="process1">
    <startEvent id="startevent1" name="Start"></startEvent>
    <endEvent id="endevent1" name="End"></endEvent>
    <userTask id="usertask1" name="hello"></userTask>
    <serviceTask id="servicetask1" name="calculator" implementation="##WebService"
                 operationRef="tns:plusOperation">

      <!-- activiti流程变量和webservice的输入输出参数的转换 -->            
      <dataInputAssociation>
        <sourceRef>input1</sourceRef><!-- name of an Activiti variable -->
        <targetRef>num1</targetRef><!-- name of an element of the input message -->
      </dataInputAssociation>
      <dataInputAssociation>
        <sourceRef>input2</sourceRef><!-- name of an Activiti variable -->
        <targetRef>num2</targetRef><!-- name of an element of the input message -->
      </dataInputAssociation>
      <dataOutputAssociation>
      	<sourceRef>num3</sourceRef><!-- name of an element of the output message -->
      	<targetRef>output3</targetRef><!-- name of an Activiti variable -->
      </dataOutputAssociation>
    </serviceTask>
    
    <sequenceFlow id="flow1" name="" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
    <sequenceFlow id="flow2" name="" sourceRef="usertask1" targetRef="servicetask1"></sequenceFlow>
    <sequenceFlow id="flow3" name="" sourceRef="servicetask1" targetRef="endevent1"></sequenceFlow>
  </process>
  
  <!-- webservice的传入传出参数(webservice服务端明确指出),以及activiti执行代码中传入的参数引用 -->
  <itemDefinition id="num1" structureRef="int" />
  <itemDefinition id="num2" structureRef="int" />
  <itemDefinition id="num3" structureRef="int" />
  <itemDefinition id="input1" structureRef="int" />
  <itemDefinition id="input2" structureRef="int" />
  <itemDefinition id="output3" structureRef="int" />
  
  <!-- 一个webservice方法操作调用的定义  implementationRef="calculator:Calculator" 中 Calculator 即 portType的引用 -->
  <interface name="Calculator Interface" implementationRef="calculator:Calculator">
    <!-- Operation: implementationRef = QName of WSDL Operation -->
    <operation id="plusOperation" name="plusOperation Operation" implementationRef="calculator:plus">
      <inMessageRef>tns:plusRequestMessage</inMessageRef>
      <outMessageRef>tns:plusResponseMessage</outMessageRef>
    </operation>
  </interface>
  
  <message id="plusRequestMessage" itemRef="tns:plusRequestItem" />
  <message id="plusResponseMessage" itemRef="tns:plusResponseItem" />
  
  <itemDefinition id="plusRequestItem" structureRef="calculator:plus" />
  <itemDefinition id="plusResponseItem" structureRef="calculator:plusResponse" />
  
  <bpmndi:BPMNDiagram id="BPMNDiagram_process1">
    <bpmndi:BPMNPlane bpmnElement="process1" id="BPMNPlane_process1">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35" width="35" x="60" y="160"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35" width="35" x="590" y="160"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
        <omgdc:Bounds height="55" width="105" x="170" y="150"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="servicetask1" id="BPMNShape_servicetask1">
        <omgdc:Bounds height="55" width="105" x="370" y="150"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="95" y="177"></omgdi:waypoint>
        <omgdi:waypoint x="170" y="177"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="275" y="177"></omgdi:waypoint>
        <omgdi:waypoint x="370" y="177"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
        <omgdi:waypoint x="475" y="177"></omgdi:waypoint>
        <omgdi:waypoint x="590" y="177"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

流程执行代码

ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("acitiviti.cfg.xml");
		RepositoryService repositoryService=(RepositoryService) applicationContext.getBean("repositoryService");
		RuntimeService runtimeService  = (RuntimeService) applicationContext.getBean("runtimeService");
		IdentityService identityService=(IdentityService) applicationContext.getBean("identityService");
		repositoryService.createDeployment().addClasspathResource("calculator.bpmn20.xml").deploy();
		
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("input1", 2); 
		map.put("input2", 3);
		ProcessInstance pi=runtimeService.startProcessInstanceByKey("process1", map);
		System.out.println(pi.getId());
		
		
		TaskService taskService = (TaskService) applicationContext.getBean("taskService");
		taskService.claim("12", "yuyong");
		taskService.complete("12");
		int output = (Integer) runtimeService.getVariable("5", "output3");
		System.out.println(output);





map中传入的参数即开启一个流程实例传入的流程变量。也是 流程定义文件中定义的项目item。因为webservice task 无需人工驱动,流程执行到此task时,会自动执行。所以,执行完id为12的usertask后,自动执行了此webservice task。流程结束。


1
0
分享到:
评论
1 楼 chenglinhai2010 2013-10-28  
这个有源码么?
server的代码是指哪段?十分着急,求指教。
QQ148096458

相关推荐

Global site tag (gtag.js) - Google Analytics