Coverage Report - org.mule.endpoint.inbound.InboundExceptionDetailsMessageProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
InboundExceptionDetailsMessageProcessor
0%
0/18
0%
0/10
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.endpoint.inbound;
 8  
 
 9  
 import org.mule.api.MuleEvent;
 10  
 import org.mule.api.MuleException;
 11  
 import org.mule.api.MuleMessage;
 12  
 import org.mule.api.processor.MessageProcessor;
 13  
 import org.mule.api.transport.Connector;
 14  
 import org.mule.config.ExceptionHelper;
 15  
 import org.mule.util.ObjectUtils;
 16  
 
 17  
 import org.apache.commons.logging.Log;
 18  
 import org.apache.commons.logging.LogFactory;
 19  
 
 20  
 /**
 21  
  * Sets error message properties as specified by the transport based on the exception
 22  
  * type of the exception payload. This mechanism uses a transport properties file in
 23  
  * the META-INF/services/org/mule/config directory called
 24  
  * mule-exception-codes.properties. This property file maps the fully qualified class
 25  
  * names of exceptions to the value of the property that should be set. The name of
 26  
  * the property is defined by the error.code.property property in the same properties
 27  
  * file.
 28  
  */
 29  
 public class InboundExceptionDetailsMessageProcessor implements MessageProcessor
 30  
 {
 31  
 
 32  0
     private static final Log logger = LogFactory.getLog(InboundExceptionDetailsMessageProcessor.class);
 33  
 
 34  
     protected Connector connector;
 35  
 
 36  
     public InboundExceptionDetailsMessageProcessor(Connector connector)
 37  0
     {
 38  0
         this.connector = connector;
 39  0
     }
 40  
 
 41  
     public MuleEvent process(MuleEvent event) throws MuleException
 42  
     {
 43  0
         if (event != null)
 44  
         {
 45  0
             MuleMessage resultMessage = event.getMessage();
 46  0
             if (resultMessage != null)
 47  
             {
 48  0
                 if (resultMessage.getExceptionPayload() != null)
 49  
                 {
 50  0
                     setExceptionDetails(resultMessage, connector, resultMessage.getExceptionPayload()
 51  
                         .getException());
 52  
                 }
 53  
             }
 54  
         }
 55  0
         return event;
 56  
     }
 57  
 
 58  
     /**
 59  
      * This method is used to set any additional and possibly transport specific
 60  
      * information on the return message where it has an exception payload.
 61  
      * 
 62  
      * @param message
 63  
      * @param exception
 64  
      */
 65  
     protected void setExceptionDetails(MuleMessage message, Connector connector, Throwable exception)
 66  
     {
 67  0
         String propName = ExceptionHelper.getErrorCodePropertyName(connector.getProtocol());
 68  
         // If we dont find a error code property we can assume there are not
 69  
         // error code mappings for this connector
 70  0
         if (propName != null)
 71  
         {
 72  0
             String code = ExceptionHelper.getErrorMapping(connector.getProtocol(), exception.getClass());
 73  0
             if (logger.isDebugEnabled())
 74  
             {
 75  0
                 logger.debug("Setting error code for: " + connector.getProtocol() + ", " + propName + "="
 76  
                              + code);
 77  
             }
 78  0
             message.setOutboundProperty(propName, code);
 79  
         }
 80  0
     }
 81  
 
 82  
     @Override
 83  
     public String toString()
 84  
     {
 85  0
         return ObjectUtils.toString(this);
 86  
     }
 87  
 }