View Javadoc

1   /*
2    * $Id: OutboundNotificationMessageProcessor.java 20221 2010-11-17 17:49:45Z aperepel $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
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   * Publishes a {@link EndpointMessageNotification}'s when a message is sent or
23   * dispatched.
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  }