1 17 package org.apache.servicemix.components.util; 18 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 import org.apache.servicemix.MessageExchangeListener; 22 import org.apache.servicemix.jbi.jaxp.SourceTransformer; 23 24 import javax.jbi.messaging.MessageExchange; 25 import javax.jbi.messaging.MessagingException; 26 import javax.jbi.messaging.NormalizedMessage; 27 import javax.xml.transform.TransformerException ; 28 29 35 public class TraceComponent extends ComponentSupport implements MessageExchangeListener { 36 37 private Log log = LogFactory.getLog(TraceComponent.class); 38 39 private SourceTransformer sourceTransformer = new SourceTransformer(); 40 41 public Log getLog() { 42 return log; 43 } 44 45 public void setLog(Log log) { 46 this.log = log; 47 } 48 49 public SourceTransformer getSourceTransformer() { 50 return sourceTransformer; 51 } 52 53 public void setSourceTransformer(SourceTransformer sourceTransformer) { 54 this.sourceTransformer = sourceTransformer; 55 } 56 57 public void onMessageExchange(MessageExchange exchange) throws MessagingException { 58 NormalizedMessage message = exchange.getMessage("in"); 60 if (message == null) { 61 log.warn("Received null message from exchange: " + exchange); 62 } 63 else { 64 log.info("Exchange: " + exchange + " received IN message: " + message); 65 try { 66 log.info("Body is: " + sourceTransformer.toString(message.getContent())); 67 } 68 catch (TransformerException e) { 69 log.error("Failed to turn message body into text: " + e, e); 70 } 71 } 72 done(exchange); 73 } 74 } 75 | Popular Tags |