Coverage Report - org.mule.exception.DefaultServiceExceptionStrategy
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultServiceExceptionStrategy
0%
0/30
0%
0/16
0
 
 1  
 /*
 2  
  * $Id: DefaultServiceExceptionStrategy.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.exception;
 12  
 
 13  
 import org.mule.RequestContext;
 14  
 import org.mule.api.MuleContext;
 15  
 import org.mule.api.MuleEvent;
 16  
 import org.mule.api.MuleMessage;
 17  
 import org.mule.api.processor.MessageProcessor;
 18  
 import org.mule.api.service.Service;
 19  
 import org.mule.management.stats.ServiceStatistics;
 20  
 import org.mule.util.CollectionUtils;
 21  
 
 22  
 import java.util.List;
 23  
 
 24  
 /**
 25  
  * <code>DefaultServiceExceptionStrategy</code> is the default exception handler
 26  
  * for components. The handler logs errors and will forward the message and exception
 27  
  * to an exception endpointUri if one is set on this Exception strategy
 28  
  */
 29  
 public class DefaultServiceExceptionStrategy extends AbstractMessagingExceptionStrategy
 30  
 {
 31  
     /** 
 32  
      * For IoC only 
 33  
      * @deprecated Use DefaultServiceExceptionStrategy(MuleContext muleContext) instead
 34  
      */
 35  
     public DefaultServiceExceptionStrategy()
 36  
     {
 37  0
         super();
 38  0
     }
 39  
 
 40  
     public DefaultServiceExceptionStrategy(MuleContext muleContext)
 41  
     {
 42  0
         super();
 43  0
         setMuleContext(muleContext);
 44  0
     }
 45  
 
 46  
     @Override
 47  
     protected void defaultHandler(Throwable t)
 48  
     {
 49  0
         ServiceStatistics statistics = getServiceStatistics();
 50  
 
 51  0
         if (statistics != null)
 52  
         {
 53  0
             statistics.incExecutionError();
 54  
         }
 55  
 
 56  0
         super.defaultHandler(t);
 57  0
     }
 58  
 
 59  
     @Override
 60  
     protected void logFatal(MuleMessage message, Throwable t)
 61  
     {
 62  0
         ServiceStatistics statistics = getServiceStatistics();
 63  0
         if (statistics != null)
 64  
         {
 65  0
             statistics.incFatalError();
 66  
         }
 67  
 
 68  0
         super.logFatal(message, t);
 69  0
     }
 70  
 
 71  
     @Override
 72  
     protected void routeException(MuleMessage message, MessageProcessor target, Throwable t)
 73  
     {
 74  0
         super.routeException(message, target, t);
 75  0
         List<MessageProcessor> processors = getMessageProcessors(t);
 76  0
         if (CollectionUtils.isNotEmpty(processors) && getServiceStatistics() != null)
 77  
         {
 78  0
             ServiceStatistics statistics = getServiceStatistics();
 79  0
             for (MessageProcessor endpoint : processors)
 80  
             {
 81  0
                 statistics.getOutboundRouterStat().incrementRoutedMessage(endpoint);
 82  
             }
 83  
         }
 84  0
     }
 85  
 
 86  
     protected ServiceStatistics getServiceStatistics()
 87  
     {
 88  0
         MuleEvent event = RequestContext.getEvent();
 89  0
         if (event == null)
 90  
         {
 91  
             // very bad should not happen
 92  0
             logger.fatal("The Default Service Exception Strategy has been invoked but there is no current event on the context");
 93  
             //logger.fatal("The error is: " + t.getMessage(), t);
 94  0
             return null;
 95  
         }
 96  0
         else if(event.getFlowConstruct()!=null && event.getFlowConstruct() instanceof Service)
 97  
         {
 98  0
             return ((Service) event.getFlowConstruct()).getStatistics();
 99  
         }
 100  
         else
 101  
         {
 102  
             //this will ever happen, but JIC
 103  0
             logger.fatal("The Default Service Exception Strategy has been invoked but there is no current service on the context. Please report this to dev@mule.codehaus.org");            
 104  0
             return null;
 105  
         }
 106  
     }
 107  
 }