View Javadoc

1   /*
2    * $Id: LogComponent.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.component.simple;
12  
13  import org.mule.api.MuleEventContext;
14  import org.mule.api.component.simple.LogService;
15  import org.mule.api.lifecycle.Callable;
16  import org.mule.util.StringMessageUtils;
17  
18  import org.apache.commons.logging.Log;
19  import org.apache.commons.logging.LogFactory;
20  
21  /**
22   * <code>LogComponent</code> simply logs the content (or content length if it is a
23   * large message)
24   */
25  public class LogComponent implements Callable, LogService
26  {
27      private static Log logger = LogFactory.getLog(LogComponent.class);
28  
29      public Object onCall(MuleEventContext context) throws Exception
30      {
31          String contents = context.getMessageAsString();
32          String msg = "Message received in service: " + context.getFlowConstruct().getName();
33          msg = StringMessageUtils.getBoilerPlate(msg + ". Content is: '"
34                          + StringMessageUtils.truncate(contents, 100, true) + "'");
35          log(msg);
36          return context.getMessage();
37      }
38  
39      public void log(String message)
40      {
41          logger.info(message);
42      }
43  }