Coverage Report - org.mule.service.DefaultServiceExceptionStrategy
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultServiceExceptionStrategy
7%
2/27
0%
0/14
2.6
 
 1  
 /*
 2  
  * $Id: DefaultServiceExceptionStrategy.java 11893 2008-06-02 13:39:57Z dfeist $
 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.service;
 12  
 
 13  
 import org.mule.DefaultExceptionStrategy;
 14  
 import org.mule.RequestContext;
 15  
 import org.mule.api.MuleEvent;
 16  
 import org.mule.api.MuleMessage;
 17  
 import org.mule.api.endpoint.ImmutableEndpoint;
 18  
 import org.mule.management.stats.ServiceStatistics;
 19  
 import org.mule.util.CollectionUtils;
 20  
 
 21  
 import java.util.List;
 22  
 
 23  
 /**
 24  
  * <code>DefaultServiceExceptionStrategy</code> is the default exception handler
 25  
  * for components. The handler logs errors and will forward the message and exception
 26  
  * to an exception endpointUri if one is set on this Exception strategy
 27  
  */
 28  
 public class DefaultServiceExceptionStrategy extends DefaultExceptionStrategy
 29  
 {
 30  
     public DefaultServiceExceptionStrategy()
 31  
     {
 32  1552
         super();
 33  1552
     }
 34  
 
 35  
     protected void defaultHandler(Throwable t)
 36  
     {
 37  0
         ServiceStatistics statistics = getServiceStatistics();
 38  
 
 39  0
         if (statistics != null)
 40  
         {
 41  0
             statistics.incExecutionError();
 42  
         }
 43  
 
 44  0
         super.defaultHandler(t);
 45  0
     }
 46  
 
 47  
     protected void logFatal(MuleMessage message, Throwable t)
 48  
     {
 49  0
         super.logFatal(message, t);
 50  
 
 51  0
         ServiceStatistics statistics = getServiceStatistics();
 52  0
         if (statistics != null)
 53  
         {
 54  0
             statistics.incFatalError();
 55  
         }
 56  0
     }
 57  
 
 58  
     protected void routeException(MuleMessage message, ImmutableEndpoint failedEndpoint, Throwable t)
 59  
     {
 60  0
         super.routeException(message, failedEndpoint, t);
 61  0
         List endpoints = getEndpoints(t);
 62  0
         if (CollectionUtils.isNotEmpty(endpoints) && getServiceStatistics() != null)
 63  
         {
 64  0
             ServiceStatistics statistics = getServiceStatistics();
 65  0
             for (int i = 0; i < endpoints.size(); i++)
 66  
             {
 67  0
                 statistics.getOutboundRouterStat().incrementRoutedMessage((ImmutableEndpoint) endpoints.get(i));
 68  
             }
 69  
         }
 70  0
     }
 71  
 
 72  
     protected ServiceStatistics getServiceStatistics()
 73  
     {
 74  0
         MuleEvent event = RequestContext.getEvent();
 75  0
         if (event == null)
 76  
         {
 77  
             // very bad should not happen
 78  0
             logger.fatal("The Default Service Exception Strategy has been invoked but there is no current event on the context");
 79  
             //logger.fatal("The error is: " + t.getMessage(), t);
 80  0
             return null;
 81  
         }
 82  0
         else if(event.getService()==null)
 83  
         {
 84  
             //this will ever happen, but JIC
 85  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");            
 86  0
             return null;
 87  
         }
 88  
         else
 89  
         {
 90  0
             return ((AbstractService)event.getService()).getStatistics();
 91  
         }
 92  
     }
 93  
 }