1
2
3
4
5
6
7
8
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
23
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 }