Coverage Report - org.mule.impl.DefaultComponentExceptionStrategy
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultComponentExceptionStrategy
0%
0/31
0%
0/8
2.143
 
 1  
 /*
 2  
  * $Id: DefaultComponentExceptionStrategy.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 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 CPAL v1.0
 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.mule.impl.model.AbstractComponent;
 14  
 import org.mule.management.stats.ComponentStatistics;
 15  
 import org.mule.umo.UMOComponent;
 16  
 import org.mule.umo.UMOEvent;
 17  
 import org.mule.umo.UMOMessage;
 18  
 import org.mule.umo.endpoint.UMOEndpoint;
 19  
 import org.mule.umo.endpoint.UMOImmutableEndpoint;
 20  
 
 21  
 /**
 22  
  * <code>DefaultComponentExceptionStrategy</code> is the default exception handler
 23  
  * for components. The handler logs errors and will forward the message and exception
 24  
  * to an exception endpointUri if one is set on this Exception strategy
 25  
  */
 26  
 public class DefaultComponentExceptionStrategy extends DefaultExceptionStrategy
 27  
 {
 28  
     /**
 29  
      * The component to which the Exception handler belongs
 30  
      */
 31  
     protected UMOComponent component;
 32  
 
 33  
     protected ComponentStatistics statistics;
 34  
 
 35  
     public DefaultComponentExceptionStrategy()
 36  
     {
 37  0
         super();
 38  0
     }
 39  
 
 40  
     /**
 41  
      * Constructor
 42  
      * 
 43  
      * @param component the owner of this exception strategy
 44  
      * @see DefaultLifecycleAdapter
 45  
      */
 46  
     public DefaultComponentExceptionStrategy(UMOComponent component)
 47  
     {
 48  0
         super();
 49  0
         setComponent(component);
 50  0
     }
 51  
 
 52  
     /**
 53  
      * @return the UniversalMessageObject to which this handler is attached
 54  
      */
 55  
     public UMOComponent getComponent()
 56  
     {
 57  0
         return component;
 58  
     }
 59  
 
 60  
     protected void defaultHandler(Throwable t)
 61  
     {
 62  
         // Lazy initialisation of the component
 63  
         // This strategy should be associated with only one component
 64  
         // and thus there is no concurrency problem
 65  0
         if (component == null)
 66  
         {
 67  0
             UMOEvent event = RequestContext.getEvent();
 68  0
             if (event == null)
 69  
             {
 70  
                 // very bad should not happen
 71  0
                 logger.fatal("The Default Component Exception Strategy has been invoked but there is no current event on the context");
 72  0
                 logger.fatal("The error is: " + t.getMessage(), t);
 73  
             }
 74  
             else
 75  
             {
 76  0
                 setComponent(event.getComponent());
 77  
             }
 78  
         }
 79  
 
 80  0
         if (statistics != null)
 81  
         {
 82  0
             statistics.incExecutionError();
 83  
         }
 84  
         
 85  0
         super.defaultHandler(t);
 86  0
     }
 87  
 
 88  
     protected void logFatal(UMOMessage message, Throwable t)
 89  
     {
 90  0
         super.logFatal(message, t);
 91  0
         if (statistics != null)
 92  
         {
 93  0
             statistics.incFatalError();
 94  
         }
 95  0
     }
 96  
 
 97  
     protected void routeException(UMOMessage message, UMOImmutableEndpoint failedEndpoint, Throwable t)
 98  
     {
 99  0
         UMOEndpoint ep = getEndpoint(t);
 100  0
         if (ep != null)
 101  
         {
 102  0
             super.routeException(message, failedEndpoint, t);
 103  0
             if (statistics != null)
 104  
             {
 105  0
                 statistics.getOutboundRouterStat().incrementRoutedMessage(ep);
 106  
             }
 107  
         }
 108  0
     }
 109  
 
 110  
     public void setComponent(UMOComponent component)
 111  
     {
 112  0
         this.component = component;
 113  0
         if (component instanceof AbstractComponent)
 114  
         {
 115  0
             if (statistics != null)
 116  
             {
 117  0
                 this.statistics = ((AbstractComponent) component).getStatistics();
 118  
             }
 119  
         }
 120  0
     }
 121  
 }