Pages

Thursday, August 2, 2012

Return a fault from an Asynchronous Web Service

In an asynchronous web service we can't return a soap fault like a synchronous service but that does not mean you can't report back the fault to the calling asynchronous process.

basically you got three options.

  • Off course handle the fault in the error hospital and give back the response. 
  • In the response message you can add a section ( a XSD choice with success and fault section) which can be used for faults.
  • Do a callback to a common fault operation of the calling process. This can be a JMS message with the messageId/correlationId or a Web Service invocation where we use the correlation of BPEL to match the fault message with the right process. 

In this blogpost I will show how to implement the last two options in Oracle BPEL.

First we start with returning the fault in a response message.

For this I added a status element to the response and a choice for a success and a fault .


In the catch section you can also invoke the callback response and in the Assign activity you can fill the fault section of the response message.




Do a fault callback to the calling process,  for this we need to do the following.

Create an Asynchronous BPEL process.

Define a fault response schema. The EmployeeId element is necessary, we need this for the correlation of the BPEL processes.


Then make a new WSDL with the fault callback operation and add a fake endpoint. ( we will override this endpoint from BPEL, because we don't know the endpoint of the calling process).


Add a FaultCallback reference web service based on this WSDL and add a wire to the BPEL process.


In the BPEL receive activity, we need to capture the fault callback url. We can optional use this for the fault response endpoint.  Go the properties tab and capture the value of the faultToAddress property. Put the value in the faultCallBackUrl variable.



In the Catch section of the BPEL process we can invoke the fault reference service. Off course use an assign to add the EmployeeId and provide a fault message.


Open the fault invoke activity and go to the properties tab.


We need to set the endpointURI property with the faultCallBackUrl variable value.


That is all for the Asynchronous Service.

Next step is to use this Asynchronous Fault Service in an other asynchronous BPEL process.

We need to make a WSDL ( contract first ) with a portType which also contains the fault operation, this must match with the reference WSDL of the Asynchronous Fault Process. So operationName, Message and namespace must match.

Create a new BPEL process which is based on this WSDL ( expose this BPEL as a service ) and also add wire the Asynchronous Fault process.


This is the process with InvokeEmployee activity which calls the Asynchronous Service.



Open this invoke activity and go to the properties tab where we set the faultToAddress property. This is the endpoint of this BPEL process and will be used for the fault callback.


After the invoke we need to use a pick activity and add an extra onMessage to the pick activity.
First OnMessage will be used for the normal callback situation.


The second will be used for the fault Response.


The last step is to setup correlation in this BPEL for the returning fault message.

on the receive add a correlation set and initiate this ( I got a NPE when I tried to set it on the invoke ). The Set is based on the employeeId element.



Add two Property Aliases , first is based on the employeeId element of the Fault Message and second is the employeeId of the request message.


On the fault OnMessage we need to add the same correlation set and this time we don't need to initiate it.



If everything is Ok we will see the following in the Enterprise Manager.

on the invoke we set the faultToAddress, the normal response OnMessage is cancelled and the fault OnMessage gets a response with the fault message.



On github you can download this example https://github.com/biemond/soa11g_examples/tree/master/AsynchronousFaultHandling

4 comments:

  1. Hi',

    Thanks for post.
    I tried this, for the first scenario "we start with returning the fault in a response message."
    In the screenshot you are using catch block and there you are using ns1:fault, where is this fault coming from.

    Thanks

    ReplyDelete
    Replies
    1. Hi,

      inside BPEL you can make your own fault just use the target namespace of the BPEL and make your own fault and in the catch you use the same values.

      For soap fault in sync services you can use the fault in the BPEL wsdl.

      thanks

      Delete
    2. Edwin please confirm this...

      I can only define a fault variable in the BPEL to throw a fault in a scope or whatever.. if I have defined a Standard fault in the WSDL for any operation.

      In your case if you have not defined a fault, you cannot throw explicitly a fault in the scope for your own exception handling.

      For me I fake the WSDL with a requesst/reply operation with a fault to make a fault available in the catch or throw

      Delete
  2. Would this be the same in Oracle BPM? Do you have the same problem of not being able to reply a fault asynchronously?

    ReplyDelete