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.MuleMessage;
12  import org.mule.api.endpoint.InboundEndpoint;
13  import org.mule.api.processor.MessageProcessor;
14  import org.mule.util.ObjectUtils;
15  import org.mule.util.StringMessageUtils;
16  
17  import org.apache.commons.logging.Log;
18  import org.apache.commons.logging.LogFactory;
19  
20  public class InboundLoggingMessageProcessor implements MessageProcessor
21  {
22      protected final transient Log logger = LogFactory.getLog(getClass());
23      protected InboundEndpoint endpoint;
24  
25      public InboundLoggingMessageProcessor(InboundEndpoint endpoint)
26      {
27          this.endpoint = endpoint;
28      }
29  
30      public MuleEvent process(MuleEvent event) throws MuleException
31      {
32          MuleMessage message = event.getMessage();
33          if (logger.isDebugEnabled())
34          {
35              logger.debug("Message Received on: " + endpoint.getEndpointURI());
36          }
37          if (logger.isTraceEnabled())
38          {
39              try
40              {
41                  logger.trace("Message Payload: \n"
42                               + StringMessageUtils.truncate(StringMessageUtils.toString(message.getPayload()),
43                                   200, false));
44                  logger.trace("Message detail: \n" + StringMessageUtils.headersToString(message));
45              }
46              catch (Exception e)
47              {
48                  // ignore
49              }
50          }
51  
52          return event;
53      }
54  
55      @Override
56      public String toString()
57      {
58          return ObjectUtils.toString(this);
59      }
60  }