OSB: Creating meaningful SOAP exceptions

The OSB is usually used to transform and route messages. But sometimes something goes wrong and we have to return the caller an exception.

This can happen in two situations:

  • We want to create a new exception because a special situation
  • We want to create a new exception because of an exception thrown by a called service

The exceptions we want to create should be of the type soap:exception. And we want to include as much information as possible. For example information provided by the caller like user information or environment, time of the creation of the exception and id of the message the exception is a response for.

It should also be possible to create the exceptions with a few lines of code. The best solution is to create a generic XQuery constructing the exception. Because we have two use cases we create two XQuerys: FaultParameterized.xq and FaultFromFault.xq.

In a first step we add a pipeline with an assign the content of body to bodyIncoming. This is necessary because during the flow usually the content of the variable body is changed and it would not be possible to access the original incoming message.

BLOG_OSB_Exception_01

Depending on the operation called we execute a branch of the operational branch. But if caller provides a non existing operation we want to return an exception. The implementation for this situation is the FaultParameterized.xq

We insert the replace into the default branch.

BLOG_OSB_Exception_02

And provide the needed parameters.

BLOG_OSB_Exception_03

 

Now we can try to make a call to the non-existing dummyOperation with this request:

We get this error response including some information we sent with the request:

 

For the route it is possible to implement an error handler. In the error handler a correct exception should be created adding the additional information from the thrown error.  In this situation we use FaultFromFault.xq

We insert the replace into the error handler.

BLOG_OSB_Exception_04

And provide the needed parameters.

BLOG_OSB_Exception_05

 

Now we can try to make a call to the operation getServiceInfo, which makes a callout to a non existing service, with this request:

We get this error response including some information we sent with the request:

 

Bernhard Mähr @ OPITZ-CONSULTING published at http://thecattlecrew.wordpress.com/

Leave a Reply