1
2
3
4
5
6
7
8
9
10
11 package org.mule.endpoint.outbound;
12
13 import org.mule.api.MuleEvent;
14 import org.mule.api.MuleException;
15 import org.mule.api.endpoint.OutboundEndpoint;
16 import org.mule.api.processor.MessageProcessor;
17 import org.mule.context.notification.EndpointMessageNotification;
18 import org.mule.transport.AbstractConnector;
19 import org.mule.util.ObjectUtils;
20
21
22
23
24
25
26 public class OutboundNotificationMessageProcessor implements MessageProcessor
27 {
28
29 private OutboundEndpoint endpoint;
30
31 public OutboundNotificationMessageProcessor(OutboundEndpoint endpoint)
32 {
33 this.endpoint = endpoint;
34 }
35
36 public MuleEvent process(MuleEvent event) throws MuleException
37 {
38 AbstractConnector connector = (AbstractConnector) endpoint.getConnector();
39 if (connector.isEnableMessageEvents())
40 {
41 String component = null;
42 if (event.getFlowConstruct() != null)
43 {
44 component = event.getFlowConstruct().getName();
45 }
46
47 int notificationAction;
48 if (event.getEndpoint().getExchangePattern().hasResponse())
49 {
50 notificationAction = EndpointMessageNotification.MESSAGE_SENT;
51 }
52 else
53 {
54 notificationAction = EndpointMessageNotification.MESSAGE_DISPATCHED;
55 }
56 connector.fireNotification(new EndpointMessageNotification(event.getMessage(),
57 event.getEndpoint(), component, notificationAction));
58 }
59
60 return event;
61 }
62
63 @Override
64 public String toString()
65 {
66 return ObjectUtils.toString(this);
67 }
68 }