01: /*
02: * $Id: LogComponent.java 10529 2008-01-25 05:58:36Z dfeist $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
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: private static Log logger = LogFactory.getLog(LogComponent.class);
27:
28: public Object onCall(MuleEventContext context) throws Exception {
29: String contents = context.getMessageAsString();
30: String msg = "Message received in service: "
31: + context.getService().getName();
32: msg = StringMessageUtils.getBoilerPlate(msg + ". Content is: '"
33: + StringMessageUtils.truncate(contents, 100, true)
34: + "'");
35: log(msg);
36: return null;
37: }
38:
39: public void log(String message) {
40: logger.info(message);
41: }
42: }
|