JBPM使用方法、过程记录

一、How to call Web Service Using JBPM 5, designer

https://204.12.228.236/browse.php?u=ObFK10b3HDFCQUNPNMI9E9mVwaCq3FwkaoL99tqkn%2Bip0N%2B93A%3D%3D&b=15

Accelerate your business

wtorek, 31 lipca 2012

Service Task with web service implementation

Invocation of web services as part of business process is common and most likely because of that default implementation of Service Task in BPMN2 specification is web service. Recently (5.4) jBPM5 has gotten support for such activity.

jBPM5 web service support is based on Apache CXF dynamic client. It
provides dedicated Service Task handler (that implements WorkItemHandler
interface).

org.jbpm.process.workitem.bpmn2.ServiceTaskHandler

Worth noting is that this handler is capable of invoking both web
service end points and simple Java based services as with previous
ServiceTask handler (org.jbpm.bpmn2.handler.SendTaskHandler) based on
the implementation attribute of service task node

web service implementation

<bpmn2:serviceTask id="ServiceTask_1" name="Service Task" implementation="##WebService" operationRef="_2_ServiceOperation"> </bpmn2:serviceTask>

java implementation

<bpmn2:serviceTask id="_2" name="Hello" operationRef="_2_ServiceOperation" implementation="Other" >

</bpmn2:serviceTask>

ServiceTaskHandler can invoke web service operations in three modes:

  • synchronous (sends request and waits for response before continuing)
  • asynchronous (sends request and uses callback to get response)
  • one way (sends request and does not wait for any response)

This configuration is done on service node level as parameter (data
input) so it allows to have different configuration for service nodes
and to be handled by the same service task handler.

Let‘s try to go through this implementation with example. We are going
to build a process that will get weather forecast for given zip codes in
US. So process will look like this:

This process will:

  • ask for couple of zip codes on the first human task (task is assigned to john)
  • next transform result of the user task to a collection that will be used as input for multi instance service task
  • then based on the input collection process will create several instances of service task to query the weather forecast service
  • once all service task instances are completed it will log result to the console
  • and create another human task to show the weather forecast for selected zip codes (task is assigned to john)

When process instance is started it will prompt the user to select in
what mode service task instances should be executed: async or sync. With
this particular example changing the mode from async to sync will not
make big difference as the service we use is rather fast but with
services that takes some time to respond difference will be noticeable.

But how does it know it is web service and even more important what web
service it is? This is configured as part of process definition using
few dedicated constructs:

1. first of all we need to tell the engine where is our WSDL so it can
be read and operations from it can be invoked - this is done with BPMN2
import:
 <import importType="/wsdl/" location="/WeatherWS/Weather.asmx?WSDL" namespace="/WeatherWS/"/>

2. next message, interface and operations must be defined:

<itemDefinition id="_2-2-4_InMessageType" />

<message id="_2-2-4_InMessage" itemRef="_2-2-4_InMessageType" />

<interface id="_2-2-4_ServiceInterface" name="" implementationRef="Weather">

<operation id="_2-2-4_ServiceOperation"

implementationRef="GetCityWeatherByZIP" name="hello">
      <inMessageRef>_2-2-4_InMessage</inMessageRef>
  </operation>

</interface>

Important: make sure that implementationRef for both interface and operations point to valid service and operation in WSDL.

3. Next use defined operation in your service task and set
implementation as web service (or don‘t specify that attribute at all so
default will be taken):

<serviceTask id="_2" name="Service Task" operationRef="_2-2-4_ServiceOperation" implementation="##WebService" >

........

</serviceTask>

NOTE: Unfortunately tooling does not support this yet so the bpmn2 file
needs to be edited by hand. Soon tooling will provide this as well.

Yet another important thing here is that if you plan to use request or
response object of the service in your process as variables make sure
that all of them implement java.io.Serializable interface so they can be
properly persisted. One way to do this (used in the example) is to
provide additional configuration to tell JAXB to add Serializable while
generating classes from WSDL and generate classes as part of the build:

Complete source code can be found here.
It comes with test cases that uses this example as well as local
service that can be used to illustrate difference between sync and async
modes.

This example can be executed on jbpm-console when build from master, as
it already has this service task handler configured. Here is a short
guide on how to do it:
1. clone jbpm master and build it with mvn clean install -DskipTests -Dfull (alternatively download latest build from build server)
2. clone jbpm-examples and build jbpm-ws-example project with mvn clean install
3. copy result of build in point 2 (jbpm-ws-sample-1.0-SNAPSHOT.jar) into jbpm-installer/dependencies
4. copy WeatherWSServiceProcess.bpmn2 into jbpm-installer/sample/evaluation/src/main/resource
5. copy all archives from jbpm-distribution into jbpm-installer/lib
6. use jbpm-installer to install jbpm into jboss AS7 - ant install.demo.noeclipse
7. start demo server - ant start.demo.noeclipse

then go to jbpm-console and run the process with name WeatherWSServiceProcess.

Have fun!

二、、http://duncandoyle.blogspot.com/2012/10/jbpm5-calling-webservices-from-your.html

Wednesday, October 3, 2012

jBPM5: Calling WebServices from your business processes

In one of my previous blog posts on Business Process Management (BPM) I outlined the important role that BPM plays in a Service Oriented Architecture (SOA), and how a well defined SOA is a prerequisite for successful Cloud implementations.

The
jBPM5 engine, part of the JBoss BRMS platform, is a highly flexible
and versatile BPM engine based on open standards like BPMN2 and
WS-HumanTask. This article will show how the jBPM5 platform can
integrate with WebServices by utlizing the JAX-WS API.

The
jBPM5 platform provides a simple, but very powerful, extension
mechanism to add domain specific service nodes and their
implementations to a business process. This allows us to plug our own,
custom, logic into the business process runtime system. The extension
mechanism is
based on the jBPM5 WorkItemHandler API. The WorkItemHandler interface
declares 2 methods which need to be implemented by the domain
specific WorkItemHandler implementation:

  • public
    void
    executeWorkItem(WorkItem workItem, WorkItemManager workItemManager):
    Is
    called by the process engine when a service node is executed.
  • public
    void
    abortWorkItem(WorkItem workItem, WorkItemManager workItemManager):
    Can
    be implemented to signal the workitem to be aborted.

In
this example we will utilize this WorkItemHandler API to implement
our own custom service nodes which use the JAX-WS API to call external
WebServices. This article will not cover how to define and use custom
nodes in your business process editor (i.e. the JBoss BRMS BPMN2 Web
editor, the JBoss Tools Eclipse BPMN2 editor, etc.). For inforrmation on how to define and use custom process nodes in your
BPMN2 process, please consult:

The source codes of the examples in this blogpost are available in my Github repository. The code also contains the WorktemDefinitions file
which contains the definitions of the ‘PaymentService‘ and
‘JAX-WS-Dispatcher-Service‘ workitems. These definitions can, for
example, be used in the JBoss BRMS system to add the custom service
nodes to the BPMN2 web-editor palet.

The
Process

The
process used in this example is a simple process which calls a
PaymentService to check whether a payment-type (e.g. VISA,
MasterCard, etc.) is valid and which, if the payment-type is valid,
calls an OrderService to place a specific order. The process contains
additional ScriptTask nodes which provide debug output
which is written to System.out.

The BPMN2 process definition of this specific process can be found here.

In
this example, the process runs in a simple Java client application
(the ‘Simple_jBPM_Process‘ project), which creates the jBPM5
KnowledgeBase, containing the BPMN2 process definition, creates the
StatefulKnowledgeSession, registers our custom JAX-WS WorkItemHandlers and
starts the process instance. See the
‘org.jboss.ddoyle.howtojboss.jbpm5webservices.Main‘ class for the example code.

WebServices

This example contains a WAR project (the ‘SimpleWebServicesWeb‘ project) that can be directly deployed on
a JBoss BRMS 5.3 platform (or EAP 5.1.x with the JBossWS-CXF
WebService stack) and which contains both the implementation of the
PaymentService‘ and the ‘OrderService‘. The WSDL files of these services
can either be obtained from the project‘s ‘src/main/resources‘ folder
or, at runtime, via the JBossWS console at
http://localhost:8080/jbossws/services.

JAX-WS

JAX-WS
provides two client APIs which can be used to execute WebService
calls, the Dispatch API and the Proxy API.

The
Proxy API provides a Java proxy object representing the WebService endpoint
to be called. The JAXB2 library is utilized to marshall and
unmarshall Java objects to and from XML. This client mode can be used
when one wants to operate on Java objects.

The
Dispatch API is a dynamic API in which the client code which uses
this API is responsible for the creation of the XML payload or even
the entire SOAP message that will be sent to the WebService endpoint.
This API can be used when one wants to operate on the XML message level.

In
this example we will use both client modes. We will call the
‘PaymentService‘ using a JAX-WS Proxy client and the ‘OrderService‘
via a JAX-WS Dispatch client.

JAX-WS
Proxy Client: 
PaymentServiceJaxWsProxyWorkItemHandler

JBoss
BRMS (and any other JBoss platform for that matter) provides a
utility that is able to generate the JAX-WS annotated Java code from a
given WSDL file. This utility, called ‘wsconsume‘, is located in the
‘jboss-as/bin‘ directory of your JBoss BRMS  (or EAP) platform. The utility can be used as follows:
./wsconsume.sh -kn {WSDL-file}. This will generate the JAX-WS annotated client
and server code which can be used to both implement the webservice
provider and a webservice consumer. Both the ‘Simple_jBPM_Process
(consumer) and the ‘SimpleWebServicesWeb‘ (provider) contain the
JAX-WS code generated from the ‘PaymentService‘ and ‘OrderService‘ WSDL files.

The
PaymentServiceJaxWsProxyWorkItemHandler
uses the generated JAX-WS Proxy client to call the
PaymentService. As can be seen from the code, the WorkItemHandler
is, because it directly uses the generated PaymentService proxy classes,
tightly
coupled to the PaymentService. I.e. This WorkItemHandler
implementation is specifically created to call a PaymentService
WebService. In general, a WorkItemHandler which uses a JAX-WS Proxy
client can only be used to call that specific service. This implies that
one has to define and create a WorkItemHandler per service, and thus a
domain specific process node per service.

The
jBPM5 WorkItemHandler API provides the ability to pass parameters from
the jBPM5 process instance to the WorkItemHandler via
a parameter Map. In the jBPM5 BPMN2 process definition, a mapping needs
to be defined on the ‘PaymentService‘ node which maps the process
instance data onto the parameters required by the WorkItemHandler.

In the case of the ‘PaymentServiceJaxWsProxyWorkItemHandler‘, 2 parameters
can (must) be passed to the WorkItemHandler:

  • input: a
    String object containing the input value for the PaymentService.
  • endpointAddress: the URL of the location of the PaymentService.

The service response data is
returned to the process instance via the ‘paymentServiceResponse‘
parameter in the returned parameter Map. This response can then be
mapped back onto a process instance variable.

The ‘endpointAddress‘ parameter allows us to configure the actual
location of the PaymentService endpoint. This makes it possible to
use the same WorkItemHandler to point to different endpoint
locations of the PaymentService, which is specifically useful when one has to deploy the
process in multiple environments (i.e. Development, Test,
Production).

JAX-WS
Dispatch Client: 
JaxWsDispatcherWorkItemHandler

The
JaxWsDispatcherWorkItemHandler
uses the JAX-WS Dispatch API to, in this process definition, call
the OrderService. The JAX-WS Dispatch API allows us to work on XML
structures directly. The responsibility of providing the correct XML
SOAP-message payload (or the entire SOAP-message itself, depending on
whether the Dispatch client is used in PAYLOAD or MESSAGE mode) lies
now with the code that uses the Dispatch API.

In
this example we‘ve tried to make this WorkItemHandler as generic
as possible, so it can be used to call any webservice and can be reused in
various projects. This is done by parameterizing the name and
location of the service to be called, as well as by providing a
simple ‘injection‘ mechanism to inject the RequestMapper and
ResponseMapper objects responsible for marshalling and unmarshalling
the XML payload from and to jBPM5 WorkItemHandler parameters (which are passed via the WorkItemHandler parameter Map).

The
WorkItemHandler requires the following parameters to be passed by the
process instance:

  • serviceNamespace:
    the namespace of the service to be called. I.e. The namespace
    defined in the services‘ WSDL file.
  • serviceName:
    The name of the service as defined in the services‘ WSDL file.
  • portTypeNamespace:
    The namespace of the PortType.
  • portTypeName:
    The name of the PortType.
  • soapAction:
    The soapAction value of the service operation to be called.
  • endpointAddress:
    The URL of the service endpoint.
  • requestMapper:
    The name of the request-mapper which will be used to lookup a
    RequestMapper instance via the ‘RequestMapperFactory‘.
  • responseMapper:
    The name of the response-mapper which will be used to lookup a
    ResponseMapper instance via the ‘ResponseMapperFactory‘.
  • input: The input data for the WebService call.

The service response data is returned to the process instance via the ‘response‘ parameter in the returned parameter Map.

These
parameters make this WorkItemHandler very generic. One can call
different services, inject specific RequestMappers and
ResponseMappers, etc.  The picture below shows how the mapping of jBPM5
process instance data to WorkItemHandler parameters is configured in the
JBoss BRMS BPMN2 web editor:

If required, the WorkItemHandler can be extended to support additional WS-* features like WS-Security, WS-Addressing, etc.

Running
the example.

To
run the example, first the project containing the OrderService and
PaymentService implementations needs to be build using Maven. To do
this, execute the command ‘mvn clean install‘ in the
‘SimpleWebServicesWeb‘ directory. This will build the WAR file and
add it to your local Maven repository. Deploy this WAR file on a JBoss
BRMS 5.3 platform (or any JBoss platform with a JBossWS-CXF
WebServices stack) of which the HTTP connector is bound to
‘localhost:8080‘. The WSDL files of the WebServices can now be
accessed at:

Next,
build the ‘Simple_jBPM_Process‘ client project by again executing
‘mvn clean install‘ in the ‘Simple_jBPM_Process‘ directory. This will
produce a JAR file which contains all the jBPM5 and Drools
dependencies required to run the process instance.

To
run the client, simply execute the command ‘java -jar Simple_jBPM_Process-0.0.1-SNAPSHOT.jar JBoss_T-Shirt VISA‘ from a terminal. If
everything exectutes correctly, this will produce the following output:

Loading StatefulKnowledgeSession.

Starting Process Instance.

Payment type: VISA

PaymentService response: VALID

Payment approved!

Oct 4, 2012 12:39:43 AM
org.jboss.ddoyle.howtojboss.jbpm5webservices.workitemhandlers.JaxWsDispatcherWorkItemHandler
executeWorkItem

INFO: Calling Service: http://impl.orderservice.howtojboss.ddoyle.jboss.org/:SimpleOrderServiceService

Oct 4, 2012 12:39:43 AM
org.jboss.ddoyle.howtojboss.jbpm5webservices.workitemhandlers.JaxWsDispatcherWorkItemHandler
executeWorkItem

INFO: Received response from Service: http://impl.orderservice.howtojboss.ddoyle.jboss.org/:SimpleOrderServiceService

Order ‘JBoss_T-Shirt‘ submitted successfully

Finished Process Instance with id: 1

If
another payment-type then VISA is entered, the process will show the
following output.

Loading StatefulKnowledgeSession.
Starting Process Instance.
Payment type: MasterCard
PaymentService response: INVALID
Payment not approved. Order cancelled.
Finished Process Instance with id: 1

Conclusion

jBPM5
is a highly versatile and flexible Business Process Management
platform which can be easily extended, customized and integrated with
a vast array of external systems. In this example we combined the
JAX-WS API and the jBPM5 WorkItemHandler API to integrate
WebServices with our business processes. The WorkItemHandler API is a
simple, yet powerful, construct that can be used to integrate business processes with
almost any (external) system, as long as that system provides a Java
client API (or as long as a Java client can be written for it). This implies
that we can use the same mechanism to, from our  business process,
call RESTful services, send JMS messages to message queues (e.g.
JBoss HornetQ), etc. As such, the jBPM5 platform can be easily integrated in almost any IT landscape.

时间: 2024-10-03 09:40:16

JBPM使用方法、过程记录的相关文章

[转]Caffe安装过程记录(CentOS,无独立显卡,无GPU)

Caffe安装过程记录(CentOS,无独立显卡,无GPU) 原文地址:http://www.aiuxian.com/article/p-2410195.html 参考资料: http://www.tuicool.com/articles/uiuA3e Caffe 安装配置(CentOS + 无GPU) http://blog.sina.com.cn/s/blog_990865340102vewt.html caffe 安装配置(CentOS 6.5 + 无GPU) http://www.cnb

Windows7 + Ubuntu双系统安装过程记录

Windows7 + Ubuntu双系统安装过程记录 时间: 2014-11-05 22:00:00 本文为在已安装Windows7系统的前提下安装Ubuntu Kylin 14.10系统的过程以及期间出现的各种问题的记录. p{text-indent:2em} Ubuntu系统下载 Ubuntu Kylin中文官方网站:http://www.ubuntu-china.cn/ Ubuntu Kylin 14.10 64位下载地址:http://cdimage.ubuntu.com/ubuntuk

MAPR 开发环境搭建过程记录

我下载了MAPR 官方提供的virtualbox 和 vmware版本的sandbox进行试用. 开始试用了一会vmware版的,因为不太熟悉vmware的操作,而且vmplayer经常没有反应,后来改用了virtualbox版. 因为sandbox是单机版的,所以必须把网络设置设为host only,否则服务是无法正常启动的. 即使是这样,服务时常因为超时无法正常启动,这时我们可以在按alt+F2进入系统后重启服务即可.可能需要多尝试几次. 我想在sandbox中使用eclipse开发mapr

戴尔笔记本win8.1+UEFI下安装Ubuntu14.04过程记录

瞎扯:笔记本刚买不久就想装ubuntu来着,但结果发现BIOS启动方式为UEFI,网上一搜索发现跟以前的双系统安装方法不一样,看具体教程感觉相当复杂,而且也有点担心折腾跪了这新本本所以一直没有动手.但昨天又心血来潮,看了几个教程后于是决定开搞!虽然中间不是很顺利,但最后结果发现也没有多复杂. 环境:我的笔记本型号是戴尔Insprion 14R-5437,系统为原装Win8.1,BIOS启动方式为UEFI.用事先制作的启动U盘,安装的是Ubuntu14.04 64位. 本文不是完整教程,所以建议参

升级Windows 10 正式版过程记录与经验

升级Windows 10 正式版过程记录与经验 [多图预警]共50张,约4.6MB 系统概要: 预装Windows 8.1中文版 C盘Users 文件夹已经挪动到D盘,并在原处建立了符号链接.(我怀疑这是系统升级失败的原因) 本次升级目标: 保持正版Windows身份 尽量保留程序和设置 使用工具: Windows PE UltraISO等 注: 文中图片序号不连续.小数序号一般为照片.整数一般为截图. 本文为原创,URL:http://www.cnblogs.com/go2bed/p/4695

某过期不给用一例逆向过程记录

? 某过期不给用一例逆向过程记录 目录 某过期不给用一例逆向过程记录????1 1.目标功能受限????1 2.看看PE信息:????1 3.查看未注册或受限时显示方式.????1 4.直接载入,看看入口点.????1 5.接下来,首选字符串查找法.????1 6.看看过期后会咋样????1 7.同步骤5查找字符串????1 8.暂停程序回溯堆栈????1 9.以上就是去掉时间检测的逆向.????1 10.后记????1 11.其他????1 ? ? SQL浏览器3.5.7 1.目标功能受限 如

mercurial(Hg) Server 搭建 过程记录

mercurial(Hg) Server 搭建 过程记录 1.  环境说明 只是测试搭建,环境为本机开发环境:win 8.1 + IIS8.5 软件准备: 2.  软件安装 先安装Python2.7, 然后安装Mercurial的Python package, 然后安装TortoiseHg, 最后安装url rewrite组件. 3. 在D盘建一个数据仓库总目录, 例如D:\Mercurial\ hgweb, 所有的repositories都将位于这个目录之下. (Repositories是仓库

改造一个JS插件的过程记录

最近做一个合作项目,对方要求我们做一个web应用程序,然后嵌入到他们的总的wen应用中,风格要求保持一致,于是乎就发了一个html文件过来,大概列举了一下各种控件,对话框的效果. 好了,重点说其中的一个弹出插件,其源码为: (function($) { $('a[data-reveal-id]').live('click', function(e) { e.preventDefault(); var modalLocation = $(this).attr('data-reveal-id');

在Docker下搭建Apache+PHP+mysql环境的过程记录

在Docker下搭建Apache+PHP+mysql环境的过程记录 这是一篇搭建Docker环境的过程记录,方便以后查看.主要记录了搭建所用到的工具,使用的命令和遇到的坑. 1. 安装Docker 第一步肯定是到Docker的官网(https://www.docker.com)上去下载安装包,目前有CE和EE两个版本,简单来说,CE就是免费版,EE就是收费版.因为我用的是Windows系统,这里就只讲在Windows系统上怎么安装. 也可以点这里直接下载Windows版.下好之后运行安装. 因为

实体服务器安装centos7过程记录

一次在实体服务器安装centos 7的过程记录 第一次在实体服务器上面安装服务器(centos 7),在此记录安装过程中遇到的一些坑. 系统版本:CentOS Linux release 7.6.1810 (Core) 设置Bios 将引导设置为U盘优先启动,不同电脑型号进入bios方法不同,调整引导顺序的方式也略有差异,故不做具体介绍. 编辑优盘卷标 在设置过bios为优盘优先启动后,重启,无需按任何键.将会进入如下grub菜单引导界面. Install CentOS 7 Test this