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