This page last changed on Oct 02, 2006 by lajos@mulesource.com.
The Error handler sample demonstrates using Spring as the external container to provide the objects managed by Mule and how to publish events to multiple outbound endpoints. The sample consists of two components; ExecptionManager and BusinessErrorManager.
The BusinessErrorManager is a simple component used to log a message to the console when an event is received. In this example it is used to receive BusinessException events over JMS to simulate a real-world Exception processing application.
The ExceptionManager is a component that receives exception events 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 file on the local file system. The purpose of this sample isn't to implement an exception handler, but to demonstrate the following features -
- All the components in the error handler are configured in a Spring external container (see the src/test/conf/applicationContext.xml)
- The error manager has multiple outbound endpoints configured on it and the sample demonstrates how to dispatch to different endpoints.
- The messages in the system are Beans and need to be converted to and from XML, the sample demonstrates chaining multiple, transformers together.
Cannot resolve external resource into attachment.
Running the Application
Prerequisites
Prior to running the application, you must download several jars using the supplied build scripts with either Ant (version 1.6.5 or later) or Maven. This means you must have an internet connection available!
You should also have the MULE_HOME environment variable set and pointing to the root of your Mule distribution.
Preparation
- Open a shell*.
- From the root of the Mule distribution go to examples/ant/errorhandler or examples/maven/errorhandler
- If you are running this example for the first time and want to use Ant (version 1.6.5 or later) to set up the project:
- Make sure you are in the examples/ant/errorhandler directory
- Run the Ant script - 'ant'
- You should see output indicating that the required JARs have been download to the MULE_HOME/lib/user directory
- You can now proceed to the "Running" section below
- If you are running this example for the first time and want to use Maven to set up the project:
- Make sure you are in the examples/maven/errorhandler directory
- Run Maven - 'mvn'
- You should see output indicating that the required JARs have been download to the MULE_HOME/lib/user directory
- You can now proceed to the "Running" section below
Running
- Open a shell*.
- From the root of the Mule distribution go to examples/ant/errorhandler or examples/maven/errorhandler
- Edit the file called conf/email.properties. This file contains settings needed so that the Error Handler Example can test sending an alert email. You will need to find out and enter the required SMTP settings in this file.
- Run 'errorhandler'. This will display the Mule startup screen.
- Open another shell*
- From the root of the Mule distribution go to examples/ant/errorhandler/test-data/out or examples/maven/errorhandler/test-data/out
- This directory contains 3 Files -
- MuleException.xml
- BusinessException.xml
- FatalException.xml
- Try moving each of these files into the ../in directory 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
-
*Shell refers to a command shell in Unix or Linux and command prompt in windows.
The Error Handler sample demonstrates the use of email and JMS. As such you need to edit the conf/email.properties to use your SMTP details.
Summary
- When the Mule Model initialises the Spring container is initialised, which initialises all the components for the sample.
- When the ErrorManager and BusinessErrorManager components get initialised their implementation is resolved from the Spring container.
- When an exception file is copied to the errorhandler\test-data\in directory the default inbound endpoint for the error handler is invoked.
- The target handler does some processing of the exception.
- When ready to pass on the event, the method returns and mule invokes the outbound router on the component.
- The exception Manager gets the Message transformed to an exception bean. From this bean the exception type can be determined. There are outbound routers configured that filter on the exception type.
- The first router to match the payload type is used to route the message.
Mule Config Graph for the Error Handler Example
This is a configuration graph generated for the Error Handler example using the Mule Config Graph Tool.
(Click on the thumb image for a bigger picture) |

|
|