Exception Filter
The Exception Filter enables you to filter messages according to the type of an exception.
Prerequisites: You need a Catch Exception Strategy configured in your flow.
Minimum Configuration: The class that indicates the type of the exception.
An Exception Filter matches the type of exception you configure in the Expected Type field in the Global Element properties in Studio, or in the expectedType
property in the Configuration XML.
The Exception Filter expects an exception; this means that you need to add it within a Catch Exception Strategy processor. The exception is passed to the next processor in the exception handler only if it matches the Exception Filter’s configured expectedType
.
Use the Exception Filter to check whether your Catch Exception Strategy needs to handle an exception or not, based on the type of the exception. When the Exception Filter receives an exception that does not match its configured expectedType
, it returns a null
value, and the processing of that message stops.
Configure the Filter
-
In Anypoint Studio, search for "filter" in the Mule Palette and drag the Filter Reference component to the Catch Exception Strategy:
-
Click the Filter Reference processor to open the properties editor:
-
Click the green plus sign to the right of Global Reference.
-
Click the arrow next to Filters to show the filter selections:
-
Click Exception and OK.
-
Configure the class that indicates the type of the exception in the Expected Type field:
For example, for a runtime exception type, you set Expected Type to java.lang.RuntimeException
. You can enter the class name or browse to it.
XML Example
XML example for creating an Exception Filter:
<exception-type-filter expectedType="java.lang.RuntimeException" name="Exception" doc:name="Exception"/>
<flow name="myFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<catch-exception-strategy doc:name="Catch Exception Strategy">
<filter ref="Exception" doc:name="Filter Reference"/>
</catch-exception-strategy>
</flow>