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 public class OutboundNotificationMessageProcessor implements MessageProcessor
26 {
27
28 private OutboundEndpoint endpoint;
29
30 public OutboundNotificationMessageProcessor(OutboundEndpoint endpoint)
31 {
32 this.endpoint = endpoint;
33 }
34
35 public MuleEvent process(MuleEvent event) throws MuleException
36 {
37 AbstractConnector connector = (AbstractConnector) endpoint.getConnector();
38 if (connector.isEnableMessageEvents())
39 {
40 int notificationAction;
41 if (endpoint.getExchangePattern().hasResponse())
42 {
43 notificationAction = EndpointMessageNotification.MESSAGE_SEND_END;
44 }
45 else
46 {
47 notificationAction = EndpointMessageNotification.MESSAGE_DISPATCH_END;
48 }
49 dispatchNotification(new EndpointMessageNotification(event.getMessage(), endpoint,
50 event.getFlowConstruct(), notificationAction));
51 }
52
53 return event;
54 }
55
56 public void dispatchNotification(EndpointMessageNotification notification)
57 {
58 AbstractConnector connector = (AbstractConnector) endpoint.getConnector();
59 if (notification != null && connector.isEnableMessageEvents())
60 {
61 connector.fireNotification(notification);
62 }
63 }
64
65 public EndpointMessageNotification createBeginNotification(MuleEvent event)
66 {
67 AbstractConnector connector = (AbstractConnector) endpoint.getConnector();
68 if (connector.isEnableMessageEvents())
69 {
70 int notificationAction;
71 if (endpoint.getExchangePattern().hasResponse())
72 {
73 notificationAction = EndpointMessageNotification.MESSAGE_SEND_BEGIN;
74 }
75 else
76 {
77 notificationAction = EndpointMessageNotification.MESSAGE_DISPATCH_BEGIN;
78 }
79 return new EndpointMessageNotification(event.getMessage(), endpoint, event.getFlowConstruct(), notificationAction);
80 }
81
82 return null;
83 }
84
85 @Override
86 public String toString()
87 {
88 return ObjectUtils.toString(this);
89 }
90 }