KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > impl > DefaultExceptionStrategy


1 /*
2  * $Id: DefaultExceptionStrategy.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.impl;
12
13 import org.apache.commons.lang.ObjectUtils;
14 import org.mule.impl.message.ExceptionPayload;
15 import org.mule.umo.UMOMessage;
16 import org.mule.umo.endpoint.UMOImmutableEndpoint;
17 import org.mule.providers.NullPayload;
18
19 /**
20  * <code>DefaultExceptionStrategy</code> Provides a default exception handling
21  * strategy. The class final thus to change exception handling behaviour the user
22  * must reimplemented the ExceptionListener Interface
23  *
24  * @author Ross Mason
25  * @version $Revision: 3798 $
26  */

27
28 public class DefaultExceptionStrategy extends AbstractExceptionListener
29 {
30     public void handleMessagingException(UMOMessage message, Throwable JavaDoc t)
31     {
32         defaultHandler(t);
33         routeException(message, null, t);
34     }
35
36     public void handleRoutingException(UMOMessage message, UMOImmutableEndpoint endpoint, Throwable JavaDoc t)
37     {
38         defaultHandler(t);
39         routeException(message, endpoint, t);
40     }
41
42     public void handleLifecycleException(Object JavaDoc component, Throwable JavaDoc t)
43     {
44         // Do nothing special here. Overriding implmentations may want alter the
45
// behaviour
46
handleStandardException(t);
47         logger.error("The object that failed was: \n" + ObjectUtils.toString(component, "null"));
48     }
49
50     public void handleStandardException(Throwable JavaDoc t)
51     {
52         defaultHandler(t);
53         markTransactionForRollback();
54         // Attempt to send the exception details to an endpoint i one is set
55
if (RequestContext.getEventContext() != null)
56         {
57             handleMessagingException(RequestContext.getEventContext().getMessage(), t);
58         }
59         else
60         {
61             logger.info("There is no current event available, routing Null message with the exception");
62             handleMessagingException(new MuleMessage(new NullPayload()), t);
63         }
64     }
65
66     protected void defaultHandler(Throwable JavaDoc t)
67     {
68         logException(t);
69         if (RequestContext.getEvent() != null)
70         {
71             RequestContext.setExceptionPayload(new ExceptionPayload(t));
72         }
73     }
74 }
75
Popular Tags