2008年5月7日星期三

SOA_007:BPEL 如何处理异常?

任何应用都可能出错,BPEL也不例外。那么,BPEL是如何处理异常的呢?

1.
Business faults 和Runtime faults
BPEL 异常通常由异常名称name qualified with a namespace)和异常的信息类型messageType构成。和大多数应用一样,BPEL 把异常分为两种以区别对待:
  • Business faults
  • Runtime faults 或 system faults
2. Business faults Business faults 是与应用自身相关的错误,比如无法在数据库中找到社保账号。Business faults 要么由throw activity 抛出,要么由invoke activity 接收到一个错误响应。Business faults 是可预见的,事先由开发者定义好在BPEL中(messageType定义在WSDL中)。Business faults 由faultHandler捕获并处理。如<catch faultName="ns1:faultName" faultVariable="varName">
3. Runtime faults
Runtime faults 是与BPEL运行时相关的错误,由系统抛出,不可预见,比如变量无法找到、死循环错误、SOAP调用时发生SOAP fault、BPEL Server抛出的Java异常。Runtime faults 分为以下几种:

  • Standard faults
  • remoteFault
  • bindingFault
  • replayFault
除了BPEL的标准错误,其它的错误信息类型messageType都为RuntimeFaultMessage。其定义如下:
<?xml version="1.0" encoding="UTF-8" ?>
<definitions name="RuntimeFault"
targetNamespace="http://schemas.oracle.com/bpel/extension"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<message name="RuntimeFaultMessage">
<part name="code" type="xsd:string" />
<part name="summary" type="xsd:string" />
<part name="detail" type="xsd:string" />
</message>
</definitions>
3.1 Standard faults
Standard faults的特点如下:
  • 无信息类型messageTypes定义
  • 与任何WSDL message 无关
  • 捕捉时不需要指定变量名称:<catch faultName="bpws:selectionFault">
Standard faults细分为以下几种:
(1)selectionFailure
(2)conflictingReceive
(3)conflictingRequest
(4)mismatchedAssignmentFailure
(5)joinFailure
(6)forcedTermination
(7)correlationViolation
(8)uninitializedVariable
(9)repeatedCompensation
(10)invalidReply


3.2 remoteFault
remoteFault 是调用服务的阶段抛出的异常,比如 SOAP调用时抛出SOAP fault。
remoteFault 可以重试。
remoteFault 细分为以下几种错误:
(1)ConnectionRefused Remote server is unavailable
(2)WSDLReadingError Failed to read the WSDL
(3)GenericRemoteFault Generic remote fault

3.3 bindingFault
bindingFault 是在准备调用服务的阶段抛出的异常,比如 WSDL无法装载。bindingFault 不能重试。
出现
bindingFault后,必须要人工干预来修正错误。
bindingFault 细分为以下几种错误:
(1)VersionMismatch The processing party found an invalid namespace for the SOAP envelope element.
(2)MustUnderstand An immediate child element of the SOAP header element that was either not understood or not obeyed by the processing party contained a SOAP MustUnderstand attribute with a value of 1.
(3)Client.GenericError Generic error on the client side
(4)Client.WrongNumberOfInputParts Input message part number mismatch
(5)Client.WrongNumberOfOutputParts Output message part number mismatch
(6)Client.WrongTypeOfInputPart Input message part type error
(7)Client.WrongTypeOfOutputPart Output message part type error
(8)Server.GenericError Generic error on the server side
(9)Server.NoService Server is up, but there is no service
(10)Server.NoHTTPSOAPAction Request is missing the HTTP SOAP action
(11)Server.Unauthenticated Request is not authenticated
(12)Server.Unauthorized Request is not authorized
3.4 replayFault
A replayFault replays the activity inside a scope.
At any point inside a scope, this fault is migrated up to the scope.
Oracle BPEL Server then re-executes the scope from the beginning.

4. 如何返回错误给客户端?
4.1 同步调用
<reply partnerLink="Client" portType="buy:BuyBookPT" operation="BuyBook" variable="FaultDetails" faultName="fault" />

4.2 异步调用
<invoke partnerLink="Client" portType="buy:ClientCallbackPT" operation="ClientCallbackFault" inputVariable="FaultDetails" />

没有评论: