Document generated by Confluence on Sep 30, 2009 14:02 Page 20
Error Handler Example
This page last changed on Sep 14, 2009 by jwheeler.
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.
Cannot resolve external resource into attachment.
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
1. At a command prompt/shell, navigate to the examples/errorhandler directory under the Mule
distribution root.
2. 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.
3. 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
1. At a command prompt/shell, navigate to the examples/errorhandler under the Mule distribution
root.
2. 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.
3. Run the errorhandler script. The Mule startup screen displays.
4. 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.
5. 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.
6. To stop Mule, type 'CTRL-C' in the Mule console window.