Fault Mediator¶
The Fault Mediator (also called the Makefault Mediator) transforms the current message into a fault message. However, this mediator does not send the converted message. The Send Mediator needs to be invoked to send a fault message created via the Fault mediator. The fault message's To
header is set to the Fault-To
of the original message (if such a header exists in the original message). You can create the fault message as a SOAP 1.1, SOAP 1.2, or plain-old XML (POX) fault.
For more information on faults and errors, see Error Handling.
Syntax¶
<makefault [description="string"] [version="soap11|soap12|pox"]>
<code (value="literal" | expression="xpath")/>
<reason (value="literal" | expression="xpath")/>
<node>?
<role>?
<detail>?
</makefault>
Configuration¶
The parameters available to configure the Fault mediator to create a SOAP 1.1 fault are as follows.
Parameter Name | Description |
---|---|
Code | This parameter is used to select the fault code for which the fault string should be defined. Possible values are as follows.
|
Reason | The detailed fault string of the fault code. The following options are available.
You can click NameSpaces to add namespaces if you are providing an expression. Then the Namespace Editor panel would appear where you can provide any number of namespace prefixes and URLs used in the XPath expression. |
Role | The element of the SOAP fault message which is used to capture the party that the fault. |
Detail | This parameter is used to enter a custom description of the error. The following options are available.
|
The parameters available to configure the Fault mediator to create a SOAP 1.2 fault are as follows.
Parameter Name | Description |
---|---|
Code | This parameter is used to select the fault code for which the reason should be defined. Possible values are as follows.
|
Reason |
This parameter is used to specify the reason for the error code selected in the Code parameter. The following options are available.
You can click NameSpaces to add namespaces if you are providing an expression. Then the Namespace Editor panel would appear where you can provide any number of namespace prefixes and URLs used in the XPath expression. |
Role | The SOAP 1.2 role name. |
Node | The SOAP 1.2 node name. |
Detail | This parameter is used to enter a custom description of the error. The following options are available.
|
The parameters available to configure the Fault mediator to create a plain-old XML (POX) fault are as follows.
Parameter Name | Description |
---|---|
Reason | This parameter is used to enter a custom fault message. The following options are available.
You can click NameSpaces to add namespaces if you are providing an expression. Then the Namespace Editor panel would appear where you can provide any number of namespace prefixes and URLs used in the XPath expression. |
Detail | This parameter is used to enter details for the fault message. The following options are available.
You can click NameSpaces to add namespaces if you are providing an expression. Then the Namespace Editor panel would appear where you can provide any number of namespace prefixes and URLs used in the XPath expression. |
Examples¶
Following are examples of different usages of the Fault Mediator.
Example 1¶
In the following example, the test message
string value is given as the reason for the SOAP error versionMismatch
.
<makefault version="soap11">
<code value="soap11Env:VersionMismatch" xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/"/>
<reason value="test message"/>
</makefault>
Example 2¶
The following sample proxy validates the content type using the Filter Mediator based on the Content-Type
header property. If the result is true, it sends an exception back to the client using the Fault Mediator. Otherwise, if the result is false, it continues the flow.
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="CheckContentType" startOnLoad="true" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<filter regex="application/json" source="get-property('transport','Content-Type')">
<then>
<log category="INFO" level="simple">
<property name="CONTENT-TYPE" expression="get-property('transport','Content-Type')"/>
<property name="DECISION" value="Exception, due to unexpected Content-Type."/>
</log>
<makefault description="" version="soap11">
<code value="soap11Env:Client" xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/"/>
<reason value="Content-Type Error"/>
<detail>Content-Type: application/json is not a valid content type.</detail>
</makefault>
</then>
<else>
<log category="INFO" level="simple">
<property name="CONTENT-TYPE" expression="get-property('transport','Content-Type')"/>
<property name="DECISION" value="Continue the mediation flow..."/>
</log>
</else>
</filter>
<respond/>
</inSequence>
<faultSequence/>
</target>
</proxy>