It is possible to create customized SOAP Faults using the
Set Message filter. The Set Message
filter can change the contents of the message body to any arbitrary
content. When an exception occurs in a policy, it is possible to use
this filter to customize the body of the SOAP fault. The following
example demonstrates how to generate customized SOAP faults and return
them to the client.
Step 1: Create the Top-level Policy:
We will first create a very simple policy called "Main Circuit". This
policy will ensure the size of incoming messages is between 100 and 1000
bytes. Messages within this range will be echoed back to the client.
Step 2: Create the Fault Policy
Next, create a second policy called "Fault Circuit". This policy will
use the Set Message filter to customize the body of the
SOAP fault. When configuring this filter, enter the contents of the
customized SOAP fault that you want to return to clients in the text area
provided.
Step 3: Create a shortcut to the Fault Policy
Add a Policy Shortcut filter to the "Main Circuit" and
configure it to refer to the "Fault Circuit". Do
not connect this filter to the
policy. Instead, right-click on the filter and select the
Set as Fault Handler menu option. The "Main Circuit"
now appears as follows:
Main Circuit with Fault Handler
|
So how does it work? Let's assume a 2000-byte message is received by
the Enterprise Gateway and is passed to the "Main Circuit" for processing. The
message is parsed by the HTTP Parser filter and then the
size of the message is checked by the Message Size
filter. Since the message is greater than the size constraints set by
this filter, and since there is no failure path configured for this
filter, an exception will be thrown.
When an exception is thrown in a policy, it is handled by the designated
Fault Handler, if one is present. In the "Main
Circuit", we have set a Policy Shortcut filter to be
the fault handler. This filter delegates to the "Fault Circuit", meaning
that when an exception occurs, "Main Circuit" will invoke (or delegate
to) the "Fault Circuit".
The "Fault Circuit" consists of 2 filters, which play the following roles:
-
Set Message:
This filter is used to set the body of the message to the
contents of the customized SOAP fault.
-
Reflect:
Once the SOAP fault has been set to the message body, it will be
returned to the client using the Reflect filter.
|