BPEL Samples
BPEL
例子
As of this writing, there is one sample BPEL process that comes with the ActiveBPEL™ engine. This document comes from the README.txt file included with the sample code.
就标题所写
,
这是一个使用
ActiveBPEL™
引擎的
BPEL
流程样例。本文来自在例子代码中的
README.txt
。
The
samples/loan_approval
directory contains the files that make up the example loan approval BPEL process, two auxiliary Web services upon which it depends, two command-line test clients, and a BPEL process client JSP page. The loan approval process is the same as the one used in the BPEL spe
期
cification Business Process Execution Language for Web Services Version 1.1.
samples/load_approval
目录下包括拼凑借货
BPEL
流程例子的文件,两个依赖的辅助性
Web service
,两个命令行测试客户端,和一个
BPEL
客气端
JSP
网页。这个借货流程和
BPEL
规范中的
Business Process Execution Language for Web Services Version 1.1
是一样的。
The values sent to the BPEL process and returned by the assessor and approver are read from a configuration file. See The Config File below.
把值传送到
BPEL
流程并返回从配置文件中的assessor和approver,请看下面的配置文件。
Dependencies
依赖
You must have a working ActiveBPEL engine. See Installing and Configuring the ActiveBPEL Engine.
你必须有一个正在运行的
ActiveBPEL
引擎。查看《
ActiveBPEL
引擎的安装与配置》。
You need Ant in order to run the targets in the
build.xml
file. You could do everything manually, but the rest of this document assumes you have Ant.
你需用到
Ant
来运行
build.xml
文件中的
target
。一切你都可以手动来做,但本文假定你使用
Ant
。
The environment variable
CATALINA_HOME
must be defined so the Ant script knows where to deploy everything.
必须正确定义环境变量
CATALINA_HOME
,以便
Ant
脚本知道要分发到哪。
Setup
配置
If your ActiveBPEL engine installation is not running on "localhost:8080", change that string in the three files containing it:
如果你的
ActiveBPEL
引擎不是运行在
”localhost:8080”
,修改下面三个文件中对应的字串:
- bpel_example_config.xml
- bpel_process/wsdl/loanapprover.wsdl
- bpel_process/wsdl/loanassessor.wsdl
Deploying the BPEL Process
配置
BPEL
流程
From the command line, navigate to the directory
<installdir>/activebpel-version/ samples/loan_approval
(where "version" is a version number like 0.9.5. All subsequent commands will be run from this directory.
在命令行下,转到
<installdir>/activebpel-version/ samples/loan_approval
目录。所有后来的命令都会在这目录运行。
To deploy the BPEL process, type
要分配置
BPEL
流程,输入
ant deploy
|
If the ActiveBPEL engine is running, soon after you deploy your BPEL process the ActiveBPEL engine will notice the .bpr file and read it. Your BPEL process is ready to use.
如果
ActiveBPEL
在运行,配置
BPEL
流程后不久,
ActiveBPEL
引擎会注意到这个
bpr
文件,并读取它。
BPEL
流程准备好使用了。
See Starting the ActiveBPEL Engine for instructions on starting and stopping the engine.
参阅《开启
ActiveBPEL Engine
》来了解关于开启与关闭引擎。
The deploy target calls three other targets: deploy-bpel, deploy-ws, and deploy-jsp. deploy-bpel creates and installs a .bpr archive file that contains the BPEL process information. deploy-ws creates and installs a .bpr file that contains the Web services. deploy-jsp creates and installs a .wsr file that contains the JSP page and supporting classes.
deploy
这个
target
调用另外三个
target:deploy-bpel
、
deploy-ws
和
deploy-jsp
。
deploy-bpel
建立与安装一个包括
BPEL
流程信息的
bpr
文件。
deploy-ws
新建与安装包含
Web service
的
BPR
文件。
deploy-jsp
新建与安装一个包含
JSP
网页和所需类的
wsr
文件。
The Web services don't need to be in a .bpr file to be deployed, but doing so lets the ActiveBPEL engine find the file and hand the Web services over to Axis (a SOAP implementation). Using a .bpr file is only a convenience that simplifies deployment. The Web services are independent of the ActiveBPEL engine.
这个
Web service
并不一定要配置到
BPR
文件中,但这样可让
ActiveBPEL
引擎找到这文件来,并把这个
Web Service
交给
Axis
(一个
SOAP
实现)来处理。使用
BPR
文件只是为了简化部署(步骤)。
Web service
是独立于
ActiveBPEL
引擎的。
Testing the Web Services
测试
Web service
There is a simple command line client that tests the "assessor" and "approver" Web services. These services are used by the BPEL loan approval process. The test client calls each Web service and compares the returned result with the expected value found in the config file. To run the test client, type
这里有一些测试“
assessor
”和“
approver
”
Web service
的命令。这些服务被
BPEL
借货流程所使用。测试客户端调节器用每个
Web service
和比较返回值与配置文件中预设的值。运行测试客户端,输入:
ant ws-test-client
|
(The Web services themselves are deployed by the target deploy-ws as discussed above. However, the target ws-test-client does NOT depend upon the deploy-ws target. Why not? Because things happens too fast: if you deploy the Web services then immediately use the client the server may not have time to notice and (re)initialize the Web services. You must use either the deploy-ws or deploy targets before running the test client.)
(
Web services
他们上面说那样由
deploy-ws
这个
target
配置。然而,
ws-test-client
并不依赖于
deploy-ws
。为什么呢,因为事情发生得太快:如果你配置
Web service
就立即使用客户端端,服务端可能没有时间注意到或重初始化
Web service
。你必须在运行
ws-test-client
前,使用
deploy-ws
或
deoloy target
)
The output is similar to JUnit output; if all is well, you will see
输出有点象
Junit
;如果一切正常,你会看到:
..
OK 2 tests; 0 errors
|
If one fails you will see something like
如果有错误,你会看到象下面的东西:
E.
assessor expected result "low" does not match returned result "foo"
ERROR 2 tests; 1 error
|
Web Services and the ActiveBPEL Engine
Web Service
和
ActiveBPEL
引擎
The Web services are deployed inside a .bpr file, the archive format used for deploying BPEL processes. This is not necessary; it is only a convenience. The ActiveBPEL engine will "notice" the .bpr file and hand our Web services to the Axis SOAP implementation. The engine does not "know" about the Web services directory and does not use any shortcuts to call the Web services.
Web Service
被分发到一个
BPR
文件(分发
BPEL
流程的存档格式)中。这不是必须的;这只是为了文便。
ActiveBPEL
引擎会“注意”到这个
BPR
文件,并把
Web service
交给
Axis SOAP
执行。引擎并不“知道”
Web service
的路径也不使用任何
shortcut
来调用
Web service
。
Running the BPEL Process Client
运行
BPEL
流程客户端
To run a command-line client that calls the BPEL process Web service, type
运行命令行客户端来调用
BPEL
流程
Web service
,输入:
ant client
|
The client compares the value returned by the BPEL process with the config file value /rundata/bpel-expected-response and prints either an OK or an ERROR message.
客户端比较
BPEL
流程的返回值和配置文件的
value
、
rundata
、
bepl-expected-respones
并打印是
OK
还是
ERROR
消息。
As discussed above in Testing the Web Services, you must deploy everything before using this client.
就如上面
Testing the Web Services
所说,你必须在使用这
client
前配置好所有东西。
Using the BPEL Process JSP Client Page
使用
BPEL
流程
JSP
客户端页面
Instead of running the command line clients, you can use the JSP page at http://localhost:8080/bpel_example_client_page/index.jsp. (Again, if your Tomcat installation is not running at localhost:8080, modify the URL accordingly.)
你可以运行命令行客户端不同,你可以使用
http://localhost:8080/bpel_example_client_page/index.jsp
这个页面(重复,如果
Tomcat
没有运行于
localhost:8080
,修改相应的
URL
)。
The page displays many of the values from the config file and lets you edit them. Clicking the "Apply for a Loan" button saves the values you entered to the deployed copy of the config file, sends the loan application request to the BPEL process, and displays the response.
这页面显示很多配置文件中的值,并可以编辑。点击“
Apply for a Loan
”按钮,保存你输入的值到已分发的配置文件副本,传送借应用需求到
BPEL
流程,并显示响应(信息)。
The Config File
配置文件
The file
bpel_example_config.xml
contains values used by the test client, the two auxiliary Web services, and the Web services test client.
bpel_example_config.xml
中
test
客户端用到的值,两个辅助的
Web service
和
Web service
的客户端。
To deploy the config file manually, type
手动分发配置文件,输入:
ant deploy-config
|
The Ant targets that compile the clients and deploy the Web services all make sure the config file is deployed.
Ant target
编译客户端并分发已在配置的
Web service
。
BPEL process expected response
BPEL
流程预定回应
In order to properly set the value /rundata/bpel-expected-response, you have to understand the example loan approval BPEL process. Here it is, in pseudo-code:
为了合理设置
value /rundata/bpel-expected-response
,你必须理解借货
BPEL
流程例子,这是“假冒”的代码。
if (amount < 10000) {
if (assessor returns "low")
return "yes"
else
return approver response
}
else
return approver response
|
If the assessor Web service encounters an error, it returns "high". If the approver encounters an error, it returns "no".
如果
assessor Web service
遇到错误,则返回“
high
”。如果
approver
遇到错误,返回“
no
”。
Config file changes
配置文件的变更
Instances of
RuntimeParams
are responsible for reading the
config
file. They do so in the constructor. This means that each time a
RuntimeParams
object is created the
config
file is re-parsed, allowing the config file changes to be recognized immediately. For example, Web services create a
RuntimeParams
object each time they are called. That means you can change the
config
file and deploy it and the next time a Web service is called it will use the new values.
RuntimeParams
实例在构建的时候负责读取配置文件。这意味着每一次
RuntimeParams
对象被建立时配置文件会初再度分析,让配置文件的变更立即被验证。如,
Web service
在每次被调用时建立
RuntimeParams
对象。也就是说,你可以改变并分发配置文件,且在下一次
Web Service
被调用时会使用新的值。