View Javadoc

1   /*
2    * $Id: EndpointMessageNotificationTestListener.java 22391 2011-07-12 12:00:48Z dirk.olmes $
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.transport.sftp.notification;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.api.context.notification.EndpointMessageNotificationListener;
15  import org.mule.api.context.notification.ServerNotification;
16  import org.mule.context.notification.EndpointMessageNotification;
17  
18  import java.util.Date;
19  
20  import org.slf4j.Logger;
21  import org.slf4j.LoggerFactory;
22  
23  public class EndpointMessageNotificationTestListener implements EndpointMessageNotificationListener
24  {
25      private final Logger logger = LoggerFactory.getLogger(getClass());
26  
27      @Override
28      public void onNotification(ServerNotification notification)
29      {
30  
31          EndpointMessageNotification endpointNotification;
32          if (notification instanceof EndpointMessageNotification)
33          {
34              endpointNotification = (EndpointMessageNotification) notification;
35          }
36          else
37          {
38              logger.debug(
39                  "*** EndpointMessageNotificationTestListener RECEIVED UNKNOWN NOTIFICATION OF TYPE {}",
40                  notification.getClass().getName());
41              return;
42          }
43  
44          MuleMessage message = endpointNotification.getSource();
45          String msgType = message.getPayload().getClass().getName();
46          String correlationId = (String) message.getProperty("MULE_CORRELATION_ID", "?");
47          // String endpointUri =
48          // endpointNotification.getEndpoint().getEndpointURI().toString();
49          String endpointName = endpointNotification.getEndpoint();
50          String action = notification.getActionName();
51          String resourceId = notification.getResourceIdentifier();
52          String timestamp = new Date(notification.getTimestamp()).toString();
53  
54          if (logger.isDebugEnabled())
55          {
56              logger.debug("OnNotification: " + notification.EVENT_NAME + "\nTimestamp=" + timestamp
57                           + "\nMsgType=" + msgType + "\nAction=" + action + "\nResourceId=" + resourceId
58                           + "\nEndpointName=" + endpointName +
59                           // "\nEndpointUri=" + endpointUri +
60                           "\nCorrelationId=" + correlationId + "");
61          }
62      }
63  }