Error Handler Example
The error handler example demonstrates using Spring beans as Mule ESB service component implementations and how to publish messages to multiple outbound endpoints. The sample consists of two services: ExceptionManager and BusinessErrorManager. The BusinessErrorManager is a simple service used to log a message to the console when a message is received. In this example, it is used to receive BusinessException message over JMS to simulate a real-world exception processing application.
The ExceptionManager is a service that receives exception messages and performs some action depending on the type of exception. For example, if a fatal exception is received, an email is sent to the system administrator. If a standard system exception is received, it is logged to a file on the local file system. The purpose of this example isn't to implement an exception handler, but to demonstrate the following features:
- All the service components in the error handler are configured as Spring beans in the same Mule configuration file.
- The error manager has multiple outbound endpoints configured on it, and the example demonstrates how to dispatch to different endpoints.
- The messages in the system are Java objects and need to be converted to and from XML. The example demonstrates chaining multiple transformers together.

Running the Application
Prerequisites
Prior to running the example, you must download several JARs using the supplied build scripts with either Ant (version 1.6.5 or later) or Maven (version 2.0.9 or later). This means you must have an Internet connection available and have set up your environment correctly as described in Installing Mule.
Preparation
- At a command prompt/shell, navigate to the examples/errorhandler directory under the Mule distribution root.
- If you are running this example for the first time, run either the Ant command ant or the Maven command mvn, depending on which tool you want to use.
- When you see output indicating that the required JARs have been downloaded to the MULE_HOME/lib/user directory, proceed with the "Running" section below.
Running the Example
- At a command prompt/shell, navigate to the examples/errorhandler under the Mule distribution root.
- Edit the conf/email.properties file with the SMTP settings for your environment. These settings are required for the Error Handler example to send an alert email.
- Run the errorhandler script. The Mule startup screen displays.
- Open another console window and navigate to the examples/errorhandler/test-data/out directory. This directory contains three files : MuleException.xml, BusinessException.xml, and FatalException.xml.
- Move each of these files into the ../in directory one by one to see what happens. Each exception type will trigger a different endpoint. Note that the FatalException.xml file will cause Mule to send an email using the properties you specified in conf/email.properties.
- To stop Mule, type 'CTRL-C' in the Mule console window.
Summary
- The ErrorManager and BusinessErrorManager components are created as Spring beans when Mule starts and are used as the service component implementations.
- When an exception file is copied to the errorhandler\test-data\in directory, the default inbound endpoint for the error handler is invoked, and the target handler does some processing of the exception.
- When ready to pass on the message, the method returns, and Mule invokes the outbound router on the service.
- The exception manager gets the message transformed to an exception bean, from which the exception type is determined. The outbound routers filter based on the exception type.
- The first router to match the payload type is used to route the message.