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 | 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 | |
|
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 | |
} |