Coverage Report - org.mule.exception.DefaultSystemExceptionStrategy
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultSystemExceptionStrategy
0%
0/30
0%
0/12
3.333
 
 1  
 /*
 2  
  * $Id: DefaultSystemExceptionStrategy.java 20358 2010-11-26 20:15:18Z 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.exception.SystemExceptionHandler;
 16  
 import org.mule.api.transport.Connectable;
 17  
 import org.mule.context.notification.ExceptionNotification;
 18  
 import org.mule.message.DefaultExceptionPayload;
 19  
 import org.mule.transport.ConnectException;
 20  
 
 21  
 import java.lang.reflect.InvocationTargetException;
 22  
 
 23  
 /**
 24  
  * Log exception, fire a notification, and clean up transaction if any.
 25  
  */
 26  
 public class DefaultSystemExceptionStrategy extends AbstractExceptionListener implements SystemExceptionHandler
 27  
 {
 28  
     /** 
 29  
      * For IoC only 
 30  
      * @deprecated Use DefaultSystemExceptionStrategy(MuleContext muleContext) instead 
 31  
      */
 32  
     public DefaultSystemExceptionStrategy()
 33  
     {
 34  0
         super();
 35  0
     }
 36  
     
 37  
     public DefaultSystemExceptionStrategy(MuleContext muleContext)
 38  
     {
 39  0
         super();
 40  0
         setMuleContext(muleContext);
 41  0
     }
 42  
 
 43  
     public void handleException(Exception e)
 44  
     {
 45  0
         Connectable connectable = null;
 46  
 
 47  
         // unwrap any exception caused by using reflection apis, but only the top layer
 48  0
         if (e instanceof InvocationTargetException)
 49  
         {
 50  0
             Throwable t = e.getCause();
 51  
             // just because API accepts Exception, not Throwable :\
 52  0
             e = t instanceof Exception ? (Exception) t : new Exception(t);
 53  
         }
 54  
 
 55  0
         if (enableNotifications)
 56  
         {
 57  0
             fireNotification(new ExceptionNotification(e));
 58  
         }
 59  
 
 60  0
         if (e instanceof ConnectException)
 61  
         {
 62  0
             logger.info("Exception caught is a ConnectException, attempting to reconnect...");
 63  0
             connectable = ((ConnectException) e).getFailed();
 64  
             try
 65  
             {
 66  0
                 logger.debug("Disconnecting " + connectable.getClass().getName());
 67  0
                 connectable.disconnect();
 68  
             }
 69  0
             catch (Exception e1)
 70  
             {
 71  0
                 logger.error(e1.getMessage());
 72  0
             }
 73  
         }
 74  
 
 75  0
         logException(e);
 76  
         
 77  0
         handleTransaction(e);
 78  
 
 79  0
         if (RequestContext.getEvent() != null)
 80  
         {
 81  0
             RequestContext.setExceptionPayload(new DefaultExceptionPayload(e));
 82  
         }
 83  
         
 84  0
         if (connectable != null)
 85  
         {
 86  
             // Reconnect (retry policy will go into effect here if configured)
 87  
             try
 88  
             {
 89  0
                 logger.debug("Reconnecting " + connectable.getClass().getName());
 90  0
                 connectable.connect();
 91  
             }
 92  0
             catch (Exception e2)
 93  
             {
 94  0
                 logger.error(e2.getMessage());
 95  0
             }
 96  
         }
 97  0
     }
 98  
 }