Sample 5: Creating SOAP Faults and Changing the Direction of Messages

<definitions xmlns=""> <sequence name="myFaultHandler"> <makefault response="true"> <code xmlns:tns="" value="tns:Receiver"/> <reason expression="get-property('ERROR_MESSAGE')"/> </makefault> <send/> </sequence> <sequence name="main" onError="myFaultHandler"> <in> <switch xmlns:m0="http://services.samples" source="//m0:getQuote/m0:request/m0:symbol"> <case regex="MSFT"> <send> <endpoint> <address uri="http://bogus:9000/services/NonExistentStockQuoteService"/> </endpoint> </send> </case> <case regex="SUN"> <send> <endpoint> <address uri="http://localhost:9009/services/NonExistentStockQuoteService"/> </endpoint> </send> </case> </switch> <drop/> </in> <out> <send/> </out> </sequence> </definitions>


Demonstrating how makefault mediator can be used to construct custom SOAP faults and change the direction (in/out) of messages.


  • Start Synapse using the configuration numbered 5 (repository/conf/sample/synapse_sample_5.xml)
    Unix/Linux: sh -sample 5
    Windows: synapse.bat -sample 5

Executing the Client

When the MSFT stock quote is requested, an unknown host exception would be generated. A connection refused exception would be generated for the SUN stock request. These errors are captured and returned to the original client as a SOAP fault in this example.

ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=MSFT


<soapenv:Fault xmlns:soapenv=""> <faultcode>soapenv:Client</faultcode> <faultstring> bogus</faultstring> <detail /> </soapenv:Fault>


ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=SUN


<soapenv:Fault xmlns:soapenv=""> <faultcode>soapenv:Client</faultcode> <faultstring> Connection refused</faultstring> <detail /> </soapenv:Fault>

Note that the response attribute is set to 'true' on the makefault mediator. This instructs the mediator to change the direction of messages to 'response' as messages are transformed into SOAP faults.

Back to Catalog