- When a BPEL process invokes a synchronous web service operation, the operation might return a WSDL fault message, which results in a BPEL fault.
- A BPEL process can explicitly signal (throw) a fault.
- A fault can be thrown automatically, for example, selectionFailure or uninitializedVariable; these typically indicate a problem in your process where you've not implemented something correctly.
- The BPEL server might encounter error conditions in the run-time environment, network communications, or any other such reason. This kind of faults are called "Failures".
Here is an example of how to catch and access WSDL faults thrown by an External Web Service. This is the scenario:
- You have an external web service named "fault". This WS generates a fault because something in it fails.
- Then, you have a BPEL process named "faultCaller" that calls the "fault" service, so you must catch the fault thrown.
- Also, if a network failure appears while calling the "fault" service, then your BPEL process should handle that error.
Let's create the scenario, first the "fault" service
- Declare a fault message:
<element name=" MyFault">
<element name="myError" type="string"></element>
<part name=" payload" element="tns:MyFault"></part>
<fault name=" fault"message=" tns:FaultMessage"></fault>
- Then, inside your BPEL process throw an arbitrary fault:
< bpws:throw faultName=" someFault"/>
- Finally, build your fault message:
<bpws:literal>Error from External WebService </bpws:literal>
<bpws:to part=" payload" variable=" myFault">
<bpws:query queryLanguage=" urn:oasis:names:tc:wsbpel:2.0:sublang:xpath1.0"> <![CDATA[/tns:myError ]]> </bpws:query>
- Deploy it as
<soap:address location=" http://localhost:8080/ode/processes/fault">
Now, create "faultCaller" service
- First, add the namespace for the failure handling.
- Declare the variable that will hold the error comming from the "fault" service.
<bpws:variable messageType=" ns0:FaultMessage" name=" faultMaker" />
- Inside the invoke activity that calls the "fault" service put the fault handling activities. First lets put the failureHandling structure.
- Now, Catch run-time environment faults, like network communications issues:
<bpws:catch faultName="ext:activityFailure" >
- And finally, catch your own faults comming from the "fault" service.
<bpws:catch faultName="ns0:fault" faultVariable="faultMaker" faultMessageType="ns0:FaultMessage">
- Your BPEL process should be like the following diagram:
While calling "faultCaller", you should catch your fault message error comming from "fault" service, and if you undeploy the "fault" service, then if you call again the "faultCaller" you should catch the failure.
Download the whole example from here.