1
2
3
4
5
6
7
8
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
24
25
26 public class ExceptionMessage extends BaseMessageDTO
27 {
28
29
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 super(message);
44 this.exception = exception;
45 timeStamp = new Date();
46 this.componentName = componentName;
47 this.endpointUri = endpointUri.toString();
48
49 MuleEventContext ctx = RequestContext.getEventContext();
50 if (ctx != null)
51 {
52 MuleMessage msg = ctx.getMessage();
53 for (Iterator iterator = msg.getPropertyNames().iterator(); iterator.hasNext();)
54 {
55 String propertyKey = (String) iterator.next();
56 setProperty(propertyKey, msg.getProperty(propertyKey));
57 }
58 }
59 }
60
61
62
63
64 public ExceptionMessage(Object message,
65 Throwable exception,
66 String componentName,
67 EndpointURI endpointUri)
68 {
69 super(getAsSerializable(message));
70 this.exception = exception;
71 timeStamp = new Date();
72 this.componentName = componentName;
73 this.endpointUri = endpointUri.toString();
74
75 MuleEventContext ctx = RequestContext.getEventContext();
76 if (ctx != null)
77 {
78 MuleMessage msg = ctx.getMessage();
79 for (Iterator iterator = msg.getPropertyNames().iterator(); iterator.hasNext();)
80 {
81 String propertyKey = (String) iterator.next();
82 setProperty(propertyKey, msg.getProperty(propertyKey));
83 }
84 }
85 }
86
87 protected static Serializable getAsSerializable(Object message)
88 {
89 if (message instanceof Serializable)
90 {
91 return (Serializable) message;
92 }
93 else
94 {
95 return message.toString();
96 }
97 }
98
99 public String getComponentName()
100 {
101 return componentName;
102 }
103
104 public String getEndpoint()
105 {
106 return endpointUri;
107 }
108
109 public Date getTimeStamp()
110 {
111 return timeStamp;
112 }
113
114 public Throwable getException()
115 {
116 return exception;
117 }
118
119 public String toString()
120 {
121 return "ExceptionMessage{" + "payload=" + getPayload() + ", context=" + properties + "exception=" + exception
122 + ", componentName='" + componentName + "'" + ", endpointUri=" + endpointUri + ", timeStamp="
123 + timeStamp + "}";
124 }
125 }