一、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。流程结束。
分享到:
相关推荐
Activiti 学习笔记六:流程执行历史记录
《Activiti实战》 一共四个部分:准备篇(1~2章)介绍了Activiti的概念、特点、应用、...高级篇(15~21)通过集成WebService、规则引擎、JPA、ESB等各种服务和中间件来阐述了Activiti不仅仅是引擎,实际上是一个BPM平台
activiti学习-使用activiti多实例任务实现会签
Activiti多实例任务实现会签.
Activiti 学习笔记四:流程实例、任务的执行
4. TaskService: 在Activiti中业务流程定义中的每一个执行节点被称为一个Task,对流程中的数据存取,状态变更等操作均需要在Task中完成。TaskService提供了对用户Task 和Form相关的操作。它提供了运行时任务查询、...
activiti工作流实例,实例化、获取任务、完成任务、任务跟踪、历史任务
activiti7
这是一个activiti的简单入门web示例,下载后启动项目,直接访问首页,点击“开始执行activiti流程任务”,如果页面正常运行,会有“activiti流程任务执行完毕,请查看后台输出!”的提示。本示例的主要作用是对...
activiti和springboot整合只使用application.properties配置文件,解决了jdbc长时间待机连接被收回报错。使用springProcessEngineConfiguration对activiti管理
定时器作业在新的版本存储于单独的表中,一个线程会定时轮训需要执行的作业,快到期的作业会被添加到suspended jobs表中。重试的作业已经被干掉了,需要重试的作业会被添加到deadletter jobs表中。这样的重构意义...
activiti工作流详细讲解和实例,适合初学者学习,很有用,有收获。
springboot2+activiti 7 整合-- 创建activiti数据库 (一)创建工程,贴出maven配置 (二)创建 activiti.cfg.xml文件 (三)建表程序
时间:2015年6月30日17:19:45 ...我深知刚刚学习activiti的心情,什么都不懂,都不知道如何创建一个activiti项目,所以我写了这个web项目供大家参考,这仅仅只是个demo,大家可以在这上面进行扩展。
activiti工作流实例,网上activiti的实例很少最近本人做了一个例子供大家参考
共四个部分:准备篇(1~2章)介绍...高级篇(15~21)通过集成WebService、规则引擎、JPA、ESB等各种服务和中间件来阐述了Activiti不仅仅是引擎,实际上是一个BPM平台,最后还通过源代码对它的设计模式及PVM进行了分析。
这个是Activiti6汉化版eclipse项目的源码(包括前后台的源码),其中有很多个人改动的地方,大部分改动的地方都有标注update by Asy及蹩脚的释义。 数据库配置文件是:workflow-designer\src\META-INF\activiti-app\...
activiti入门小demo,带你快速了解activiti,10分钟带你了解activiti,activiti实战,activiti请假实例
activiti流程图高亮显示配置,为了方便别人快速配置,特此编辑此贴,盼同行们多多支持小编,原创不容易!
activiti 安装 实例