Coverage Report - org.mule.message.ExceptionMessage
 
Classes in this File Line Coverage Branch Coverage Complexity
ExceptionMessage
0%
0/34
0%
0/10
1.75
 
 1  
 /*
 2  
  * $Id: ExceptionMessage.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.message;
 12  
 
 13  
 import org.mule.RequestContext;
 14  
 import org.mule.api.MuleEventContext;
 15  
 import org.mule.api.MuleMessage;
 16  
 import org.mule.api.endpoint.EndpointURI;
 17  
 
 18  
 import java.io.Serializable;
 19  
 import java.util.Date;
 20  
 import java.util.Iterator;
 21  
 
 22  
 /**
 23  
  * <code>ExceptionMessage</code> is used by the DefaultServiceExceptionStrategy
 24  
  * for wrapping an exception with a message to send via an endpointUri.
 25  
  */
 26  
 public class ExceptionMessage extends BaseMessageDTO
 27  
 {
 28  
     /**
 29  
      * Serial version
 30  
      */
 31  
     private static final long serialVersionUID = -538516243574950621L;
 32  
 
 33  
     private Throwable exception;
 34  
     private String componentName;
 35  
     private String endpointUri;
 36  
     private Date timeStamp;
 37  
 
 38  
     public ExceptionMessage(Serializable message,
 39  
                             Throwable exception,
 40  
                             String componentName,
 41  
                             EndpointURI endpointUri)
 42  
     {
 43  0
         super(message);
 44  0
         this.exception = exception;
 45  0
         timeStamp = new Date();
 46  0
         this.componentName = componentName;
 47  0
         this.endpointUri = endpointUri.toString();
 48  
 
 49  0
         MuleEventContext ctx = RequestContext.getEventContext();
 50  0
         if (ctx != null)
 51  
         {
 52  0
             MuleMessage msg = ctx.getMessage();
 53  0
             for (Iterator iterator = msg.getPropertyNames().iterator(); iterator.hasNext();)
 54  
             {
 55  0
                 String propertyKey = (String) iterator.next();
 56  0
                 setProperty(propertyKey, msg.getProperty(propertyKey));
 57  0
             }
 58  
         }
 59  0
     }
 60  
 
 61  
     /**
 62  
      * @deprecated Use ExceptionMessage(Serializable message...) instead
 63  
      */
 64  
     public ExceptionMessage(Object message,
 65  
                             Throwable exception,
 66  
                             String componentName,
 67  
                             EndpointURI endpointUri)
 68  
     {
 69  0
         super(getAsSerializable(message));
 70  0
         this.exception = exception;
 71  0
         timeStamp = new Date();
 72  0
         this.componentName = componentName;
 73  0
         this.endpointUri = endpointUri.toString();
 74  
 
 75  0
         MuleEventContext ctx = RequestContext.getEventContext();
 76  0
         if (ctx != null)
 77  
         {
 78  0
             MuleMessage msg = ctx.getMessage();
 79  0
             for (Iterator iterator = msg.getPropertyNames().iterator(); iterator.hasNext();)
 80  
             {
 81  0
                 String propertyKey = (String) iterator.next();
 82  0
                 setProperty(propertyKey, msg.getProperty(propertyKey));
 83  0
             }
 84  
         }
 85  0
     }
 86  
 
 87  
     protected static Serializable getAsSerializable(Object message)
 88  
     {
 89  0
         if (message instanceof Serializable)
 90  
         {
 91  0
             return (Serializable) message;
 92  
         }
 93  
         else
 94  
         {
 95  0
             return message.toString();
 96  
         }
 97  
     }
 98  
 
 99  
     public String getComponentName()
 100  
     {
 101  0
         return componentName;
 102  
     }
 103  
 
 104  
     public String getEndpoint()
 105  
     {
 106  0
         return endpointUri;
 107  
     }
 108  
 
 109  
     public Date getTimeStamp()
 110  
     {
 111  0
         return timeStamp;
 112  
     }
 113  
 
 114  
     public Throwable getException()
 115  
     {
 116  0
         return exception;
 117  
     }
 118  
 
 119  
     public String toString()
 120  
     {
 121  0
         return "ExceptionMessage{" + "payload=" + getPayload() + ", context=" + properties + "exception=" + exception
 122  
                 + ", componentName='" + componentName + "'" + ", endpointUri=" + endpointUri + ", timeStamp="
 123  
                 + timeStamp + "}";
 124  
     }
 125  
 }