Coverage Report - org.mule.exception.DefaultServiceExceptionStrategy
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultServiceExceptionStrategy
0%
0/35
0%
0/24
0
 
 1  
 /*
 2  
  * $Id: DefaultServiceExceptionStrategy.java 20465 2010-12-05 18:14:15Z mike.schilling $
 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.config.DefaultMuleConfiguration;
 19  
 import org.mule.config.ExceptionHelper;
 20  
 import org.mule.management.stats.FlowConstructStatistics;
 21  
 import org.mule.management.stats.ServiceStatistics;
 22  
 import org.mule.util.CollectionUtils;
 23  
 
 24  
 import java.util.List;
 25  
 
 26  
 /**
 27  
  * <code>DefaultServiceExceptionStrategy</code> is the default exception handler
 28  
  * for components. The handler logs errors and will forward the message and exception
 29  
  * to an exception endpointUri if one is set on this Exception strategy
 30  
  */
 31  
 public class DefaultServiceExceptionStrategy extends AbstractMessagingExceptionStrategy
 32  
 {
 33  
     /** 
 34  
      * For IoC only 
 35  
      * @deprecated Use DefaultServiceExceptionStrategy(MuleContext muleContext) instead
 36  
      */
 37  
     public DefaultServiceExceptionStrategy()
 38  
     {
 39  0
         super();
 40  0
     }
 41  
 
 42  
     public DefaultServiceExceptionStrategy(MuleContext muleContext)
 43  
     {
 44  0
         super();
 45  0
         setMuleContext(muleContext);
 46  0
     }
 47  
 
 48  
     @Override
 49  
     protected void defaultHandler(Throwable t)
 50  
     {
 51  0
         FlowConstructStatistics statistics = getFlowConstructStatistics();
 52  
 
 53  0
         if (statistics != null && statistics.isEnabled())
 54  
         {
 55  0
             statistics.incExecutionError();
 56  
         }
 57  
 
 58  0
         super.defaultHandler(DefaultMuleConfiguration.fullStackTraces ? t : ExceptionHelper.sanitize(t));
 59  0
     }
 60  
 
 61  
     @Override
 62  
     protected void logFatal(MuleMessage message, Throwable t)
 63  
     {
 64  0
         FlowConstructStatistics statistics = getFlowConstructStatistics();
 65  0
         if (statistics != null && statistics.isEnabled())
 66  
         {
 67  0
             statistics.incFatalError();
 68  
         }
 69  
 
 70  0
         super.logFatal(message, t);
 71  0
     }
 72  
 
 73  
     @Override
 74  
     protected void routeException(MuleMessage message, MessageProcessor target, Throwable t)
 75  
     {
 76  0
         super.routeException(message, target, t);
 77  0
         List<MessageProcessor> processors = getMessageProcessors(t);
 78  0
         if (CollectionUtils.isNotEmpty(processors) && getFlowConstructStatistics() instanceof ServiceStatistics)
 79  
         {
 80  0
             ServiceStatistics statistics = getServiceStatistics();
 81  0
             if (statistics.isEnabled())
 82  
             {
 83  0
                 for (MessageProcessor endpoint : processors)
 84  
                 {
 85  0
                     statistics.getOutboundRouterStat().incrementRoutedMessage(endpoint);
 86  
                 }
 87  
             }
 88  
         }
 89  0
     }
 90  
 
 91  
     protected FlowConstructStatistics getFlowConstructStatistics()
 92  
     {
 93  0
         MuleEvent event = RequestContext.getEvent();
 94  0
         if (event == null)
 95  
         {
 96  
             // very bad should not happen
 97  0
             logger.fatal("The Default Service Exception Strategy has been invoked but there is no current event on the context");
 98  
             //logger.fatal("The error is: " + t.getMessage(), t);
 99  0
             return null;
 100  
         }
 101  0
         else if(event.getFlowConstruct()!= null )
 102  
         {
 103  0
             return event.getFlowConstruct().getStatistics();
 104  
         }
 105  
         else
 106  
         {
 107  
             //this can happen, e.g. with event constructed to handle exceptions
 108  
             // logger.fatal("The Default Service Exception Strategy has been invoked but there is no current flow construct on the context. Please report this to dev@mule.codehaus.org");
 109  0
             return null;
 110  
         }
 111  
     }
 112  
 
 113  
     protected ServiceStatistics getServiceStatistics()
 114  
     {
 115  0
         FlowConstructStatistics stats = getFlowConstructStatistics();
 116  0
         if (!(stats instanceof ServiceStatistics))
 117  
         {
 118  
             //this should never happen, but JIC
 119  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");            
 120  0
             return null;
 121  
         }
 122  0
         return (ServiceStatistics) stats;
 123  
     }
 124  
 }