View Javadoc

1   /*
2    * $Id: LogComponent.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.components.simple;
12  
13  import org.mule.umo.UMOEventContext;
14  import org.mule.umo.lifecycle.Callable;
15  import org.mule.util.StringMessageUtils;
16  
17  import org.apache.commons.logging.Log;
18  import org.apache.commons.logging.LogFactory;
19  
20  /**
21   * <code>LogComponent</code> simply logs the content (or content length if it is a
22   * large message)
23   */
24  public class LogComponent implements Callable, LogService
25  {
26      private static Log logger = LogFactory.getLog(LogComponent.class);
27  
28      public Object onCall(UMOEventContext context) throws Exception
29      {
30          String contents = context.getMessageAsString();
31          String msg = "Message received in component: " + context.getComponentDescriptor().getName();
32          msg = StringMessageUtils.getBoilerPlate(msg + ". Content is: '"
33                          + StringMessageUtils.truncate(contents, 100, true) + "'");
34          log(msg);
35          return null;
36      }
37  
38      public void log(String message)
39      {
40          logger.info(message);
41      }
42  }