1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.context.notification; |
8 | |
|
9 | |
import org.mule.api.MuleMessage; |
10 | |
import org.mule.api.context.notification.ServerNotification; |
11 | |
import org.mule.api.endpoint.ImmutableEndpoint; |
12 | |
|
13 | |
import org.apache.commons.logging.Log; |
14 | |
import org.apache.commons.logging.LogFactory; |
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | 0 | public class EndpointMessageNotification extends ServerNotification |
21 | |
{ |
22 | |
|
23 | |
|
24 | |
|
25 | |
private static final long serialVersionUID = -5118299601117624094L; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | 0 | protected static final Log logger = LogFactory.getLog(EndpointMessageNotification.class); |
31 | |
|
32 | |
public static final int MESSAGE_RECEIVED = MESSAGE_EVENT_ACTION_START_RANGE + 1; |
33 | |
public static final int MESSAGE_DISPATCHED = MESSAGE_EVENT_ACTION_START_RANGE + 2; |
34 | |
public static final int MESSAGE_SENT = MESSAGE_EVENT_ACTION_START_RANGE + 3; |
35 | |
public static final int MESSAGE_REQUESTED = MESSAGE_EVENT_ACTION_START_RANGE + 4; |
36 | |
public static final int MESSAGE_RESPONSE = MESSAGE_EVENT_ACTION_START_RANGE + 5; |
37 | |
|
38 | |
static |
39 | |
{ |
40 | 0 | registerAction("received", MESSAGE_RECEIVED); |
41 | 0 | registerAction("dispatched", MESSAGE_DISPATCHED); |
42 | 0 | registerAction("sent", MESSAGE_SENT); |
43 | 0 | registerAction("requested", MESSAGE_REQUESTED); |
44 | 0 | registerAction("response", MESSAGE_RESPONSE); |
45 | 0 | } |
46 | |
|
47 | |
private String endpoint; |
48 | |
|
49 | |
public EndpointMessageNotification(MuleMessage resource, |
50 | |
ImmutableEndpoint endpoint, |
51 | |
String identifier, |
52 | |
int action) |
53 | |
{ |
54 | 0 | super(cloneMessage(resource), action); |
55 | 0 | resourceIdentifier = identifier; |
56 | 0 | this.endpoint = endpoint.getEndpointURI().toString(); |
57 | 0 | } |
58 | |
|
59 | |
|
60 | |
@Override |
61 | |
protected String getPayloadToString() |
62 | |
{ |
63 | |
try |
64 | |
{ |
65 | 0 | return ((MuleMessage)source).getPayloadAsString(); |
66 | |
} |
67 | 0 | catch (Exception e) |
68 | |
{ |
69 | 0 | return source.toString(); |
70 | |
} |
71 | |
} |
72 | |
|
73 | |
@Override |
74 | |
public String toString() |
75 | |
{ |
76 | 0 | return EVENT_NAME + "{action=" + getActionName(action) + ", endpoint: " + endpoint |
77 | |
+ ", resourceId=" + resourceIdentifier + ", timestamp=" + timestamp + ", serverId=" |
78 | |
+ serverId + ", message: " + source + "}"; |
79 | |
} |
80 | |
|
81 | |
public String getEndpoint() |
82 | |
{ |
83 | 0 | return endpoint; |
84 | |
} |
85 | |
|
86 | |
@Override |
87 | |
public String getType() |
88 | |
{ |
89 | 0 | return TYPE_TRACE; |
90 | |
} |
91 | |
|
92 | |
@Override |
93 | |
public MuleMessage getSource() |
94 | |
{ |
95 | 0 | return (MuleMessage) super.getSource(); |
96 | |
} |
97 | |
} |