View Javadoc

1   /*
2    * $Id: InboundLoggingMessageProcessor.java 19191 2010-08-25 21:05:23Z tcarlson $
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.inbound;
12  
13  import org.mule.api.MuleEvent;
14  import org.mule.api.MuleMessage;
15  import org.mule.api.endpoint.InboundEndpoint;
16  import org.mule.processor.AbstractMessageObserver;
17  import org.mule.util.StringMessageUtils;
18  
19  public class InboundLoggingMessageProcessor extends AbstractMessageObserver
20  {
21  
22      protected InboundEndpoint endpoint;
23  
24      public InboundLoggingMessageProcessor(InboundEndpoint endpoint)
25      {
26          this.endpoint = endpoint;
27      }
28  
29      @Override
30      public void observe(MuleEvent event)
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  }