View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.endpoint.inbound;
8   
9   import org.mule.api.MuleEvent;
10  import org.mule.api.MuleException;
11  import org.mule.api.endpoint.InboundEndpoint;
12  import org.mule.api.processor.MessageProcessor;
13  import org.mule.context.notification.EndpointMessageNotification;
14  import org.mule.transport.AbstractConnector;
15  import org.mule.util.ObjectUtils;
16  
17  /**
18   * Publishes a {@link EndpointMessageNotification}'s when a message is received.
19   */
20  public class InboundNotificationMessageProcessor implements MessageProcessor
21  {
22      protected InboundEndpoint endpoint;
23  
24      public InboundNotificationMessageProcessor(InboundEndpoint endpoint)
25      {
26          this.endpoint = endpoint;
27      }
28  
29      public MuleEvent process(MuleEvent event) throws MuleException
30      {
31          AbstractConnector connector = (AbstractConnector) endpoint.getConnector();
32          if (connector.isEnableMessageEvents())
33          {
34              connector.fireNotification(new EndpointMessageNotification(event.getMessage(), endpoint,
35                  event.getFlowConstruct().getName(), EndpointMessageNotification.MESSAGE_RECEIVED));
36          }
37  
38          return event;
39      }
40  
41      @Override
42      public String toString()
43      {
44          return ObjectUtils.toString(this);
45      }
46  }