Fault Handling with Web Services
(Page 1 of 4 )
Last week, we looked at the assign and other basic activities, and studied flow. This week, we'll be examining more sturctured activities, and fault handling. This article, the fifth in a six-part series, is excerpted from chapter 12 of
Building Web Services with Java: Making sense of XML, SOAP, WSDL, and UDDI, written by Steve Graham et al. (Sams; ISBN: 0672326418).
More Structured Activities: sequence, while, switch, scope
Besides the pick and flow activities, BPEL provides several additional types of structured activities. The sequence activity lets you specify that activities are to be executed in the order in which they are provided. The following snippet shows three activities from the purchase order process. They always run in the specified order; the purchase order request is received first, then processed, and finally answered:
<sequence>
<receive partnerLink="buyer"
portType="pos:poSubmissionPortType"
operation="doSubmission"
createInstance="yes"
variable="poSubmissionRequest">
...
</receive>
<flow>
...
</flow>
<reply partnerLink="buyer"
portType="pos:poSubmissionPortType"
operation="doSubmission"
variable="poSubmissionResponse">
...
</reply>
</sequence>
The while activity has a nested activity that is repeatedly executed as long as a specified Boolean condition is evaluated as true. The condition is provided as an XPath expression. In our example, such an activity is used at the point where the local stock needs to be replenished. Additional goods are ordered from the supplier as long as the purchase order can't be processed from the local stock:
<while condition=
"bpws:getVariableData('checkLocalStockResponse',
'available')= false">
<!-- Replenish local stock ... -->
</while>
The switch activity can be compared to similar constructs in programming languages: for example, the switch statement in Java with its case and default branches. It lets you select exactly one branch out of a given set of choices. For each choice, provided as a list of case elements with a Boolean condition, a nested activity must be specified. The activity on the first branch (in the order of specification) whose condition
evaluates to true is executed. If an otherwise element is provided, then its nested activity is executed if none of the case conditions evaluate to true:
<switch>
<case condition="bpws:getVariableData(
'poSubmissionResponse','invoice','/totalCost')<100">
<!-- add shipping and handling fee -->
...
</case>
<case condition="bpws:getVariableData(
'poSubmissionResponse','invoice','/totalCost')<800">
<!-- do nothing -->
<empty/>
</case>
<otherwise>
<!-- subtract rebate for large orders -->
...
</otherwise>
</switch>
The scope activity is used to specify visibility boundaries. Scopes have the same structure as the overall process, except for partnerLinks and partners, which can only be declared globally in the process, and a compensation handler, which can only be declared in scopes:
<scope ...>
<!-- Variable definitions -->
<!-- Correlation set definitions -->
<!-- Fault handler definitions -->
<!-- Compensation handler definitions -->
<!-- Event handler definitions -->
<!-- Body of scope: activity -->
</scope>
Definitions at the scope level apply to all nested activities. The only mandatory element is the nested activity, which may be a structured activity as well. Variables and correlation sets declared in a scope are only visible to activities nested within that scope.
Fault handlers, compensation handlers, and event handlers can be declared in a scope as well. Let's now examine these handlers in detail.
Next: Fault Handling >>
More Web Services Articles
More By Sams Publishing
|
This article is excerpted from chapter 12 of Building Web Services with Java: Making Sense of XML, SOAP, WSDL, and UDDI, written by Steve Graham et al. (Sams; ISBN: 0672326418). Check it out today at your favorite bookstore. Buy this book now.
|
|