View Javadoc

1   /*
2    * $Id: ExceptionMessage.java 7976 2007-08-21 14:26:13Z dirk.olmes $
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.impl.message;
12  
13  import org.mule.impl.RequestContext;
14  import org.mule.umo.UMOEventContext;
15  import org.mule.umo.UMOMessage;
16  import org.mule.umo.endpoint.UMOEndpointURI;
17  
18  import java.util.Date;
19  import java.util.Iterator;
20  
21  /**
22   * <code>ExceptionMessage</code> is used by the DefaultComponentExceptionStrategy
23   * for wrapping an exception with a message to send via an endpointUri.
24   */
25  public class ExceptionMessage extends BaseMessage
26  {
27      /**
28       * Serial version
29       */
30      private static final long serialVersionUID = -538516243574950621L;
31  
32      private Throwable exception;
33      private String componentName;
34      private UMOEndpointURI endpointUri;
35      private Date timeStamp;
36  
37      public ExceptionMessage(Object message,
38                              Throwable exception,
39                              String componentName,
40                              UMOEndpointURI endpointUri)
41      {
42          super(message);
43          this.exception = exception;
44          timeStamp = new Date();
45          this.componentName = componentName;
46          this.endpointUri = endpointUri;
47  
48          UMOEventContext ctx = RequestContext.getEventContext();
49          if (ctx != null)
50          {
51              UMOMessage msg = ctx.getMessage();
52              for (Iterator iterator = msg.getPropertyNames().iterator(); iterator.hasNext();)
53              {
54                  String propertyKey = (String) iterator.next();
55                  setProperty(propertyKey, msg.getProperty(propertyKey));
56              }
57          }
58      }
59  
60      public String getComponentName()
61      {
62          return componentName;
63      }
64  
65      public UMOEndpointURI getEndpoint()
66      {
67          return endpointUri;
68      }
69  
70      public Date getTimeStamp()
71      {
72          return timeStamp;
73      }
74  
75      public Throwable getException()
76      {
77          return exception;
78      }
79  
80      public String toString()
81      {
82          return "ExceptionMessage{" + "message=" + message + ", context=" + context + "exception=" + exception
83                 + ", componentName='" + componentName + "'" + ", endpointUri=" + endpointUri + ", timeStamp="
84                 + timeStamp + "}";
85      }
86  }