if (camel == null) {
System.err.println("CamelContext " + context + " not found.");
return null;
}
BacklogTracer backlogTracer = BacklogTracer.getBacklogTracer(camel);
if (backlogTracer == null) {
backlogTracer = (BacklogTracer) camel.getDefaultBacklogTracer();
}
if (format == null || "text".equals(format)) {
JAXBContext context = JAXBContext.newInstance(MessageDump.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
SimpleDateFormat sdf = new SimpleDateFormat(BacklogTracerEventMessage.TIMESTAMP_FORMAT);
List<BacklogTracerEventMessage> events;
if (pattern != null) {
events = backlogTracer.dumpTracedMessages(pattern);
} else {
events = backlogTracer.dumpAllTracedMessages();
}
for (BacklogTracerEventMessage event : events) {
MessageDump msg = (MessageDump) unmarshaller.unmarshal(new StringReader(event.getMessageAsXml()));
String breadcrumb = getBreadcrumbId(msg.getHeaders());
System.out.println("#" + event.getUid() + "\tTimestamp:\t" + sdf.format(event.getTimestamp()));
if (breadcrumb != null) {
System.out.println("Breadcrumb: " + breadcrumb);
}
System.out.println("ExchangeId: " + event.getExchangeId());
if (event.getToNode() != null) {
System.out.println("Route: " + event.getRouteId() + "\t--> " + event.getToNode());
} else {
System.out.println("Route: " + event.getRouteId());
}
String body = msg.getBody().getValue();
if (bodySize != null && bodySize > 0) {
if (body.length() > bodySize) {
body = body.substring(0, bodySize);
}
}
System.out.println(body);
System.out.println("");
}
} else if ("xml".equals(format)) {
if (pattern != null) {
System.out.println("BacklogTracer messages:\n" + backlogTracer.dumpTracedMessages(pattern));
} else {
System.out.println("BacklogTracer messages:\n" + backlogTracer.dumpAllTracedMessagesAsXml());
}
return null;
}
return null;