in core/camel-support/src/main/java/org/apache/camel/support/processor/DefaultExchangeFormatter.java [129:273]
public String format(Exchange exchange) {
Message in = exchange.getIn();
if (plain) {
return getBodyAsString(in);
}
StringBuilder sb = new StringBuilder(512);
if (showAll || showExchangeId) {
if (multiline) {
sb.append(SEPARATOR);
}
style(sb, "Id").append(exchange.getExchangeId());
}
if (showAll || showRouteGroup) {
if (multiline) {
sb.append(SEPARATOR);
}
Route route = ExchangeHelper.getRoute(exchange);
String group = "";
if (route != null) {
group = route.getGroup();
}
style(sb, "RouteGroup").append(group);
}
if (showAll || showRouteId) {
if (multiline) {
sb.append(SEPARATOR);
}
Route route = ExchangeHelper.getRoute(exchange);
String id = "";
if (route != null) {
id = route.getRouteId();
}
style(sb, "RouteId").append(id);
}
if (showAll || showExchangePattern) {
if (multiline) {
sb.append(SEPARATOR);
}
style(sb, "ExchangePattern").append(exchange.getPattern());
}
if (showAll || showAllProperties) {
if (multiline) {
sb.append(SEPARATOR);
}
style(sb, "Properties").append(sortMap(filterHeaderAndProperties(exchange.getAllProperties())));
} else if (showProperties) {
if (multiline) {
sb.append(SEPARATOR);
}
style(sb, "Properties").append(sortMap(filterHeaderAndProperties(exchange.getProperties())));
}
if (showAll || showVariables) {
if (multiline) {
sb.append(SEPARATOR);
}
if (exchange.hasVariables()) {
style(sb, "Variables").append(sortMap(filterHeaderAndProperties(exchange.getVariables())));
}
}
if (showAll || showHeaders) {
if (multiline) {
sb.append(SEPARATOR);
}
style(sb, "Headers").append(sortMap(filterHeaderAndProperties(in.getHeaders())));
}
if (showAll || showBodyType) {
if (multiline) {
sb.append(SEPARATOR);
}
style(sb, "BodyType").append(getBodyTypeAsString(in));
}
if (showAll || showBody) {
if (multiline) {
sb.append(SEPARATOR);
}
String body = getBodyAsString(in);
if (skipBodyLineSeparator && body != null) {
body = body.replace(LS, "");
}
style(sb, "Body").append(body);
}
if (showAll || showException || showCaughtException) {
// try exception on exchange first
Exception exception = exchange.getException();
boolean caught = false;
if ((showAll || showCaughtException) && exception == null) {
// fallback to caught exception
exception = exchange.getProperty(ExchangePropertyKey.EXCEPTION_CAUGHT, Exception.class);
caught = true;
}
if (exception != null) {
if (multiline) {
sb.append(SEPARATOR);
}
if (caught) {
style(sb, "CaughtExceptionType").append(exception.getClass().getCanonicalName());
style(sb, "CaughtExceptionMessage").append(exception.getMessage());
} else {
style(sb, "ExceptionType").append(exception.getClass().getCanonicalName());
style(sb, "ExceptionMessage").append(exception.getMessage());
}
if (showAll || showStackTrace) {
final String stackTrace = ExceptionHelper.stackTraceToString(exception);
style(sb, "StackTrace").append(stackTrace);
}
}
}
// only cut if we hit max-chars limit (or are using multiline
if (multiline || maxChars > 0 && sb.length() > maxChars) {
StringBuilder answer = new StringBuilder(sb.length());
for (String s : sb.toString().split(SEPARATOR)) {
if (s != null) {
if (s.length() > maxChars) {
s = s.substring(0, maxChars);
answer.append(s).append("...");
} else {
answer.append(s);
}
if (multiline) {
answer.append(LS);
}
}
}
// switch string buffer
sb = answer;
}
if (!multiline) {
// get rid of the leading comma space if needed
if (sb.length() > 1 && sb.charAt(0) == ',' && sb.charAt(1) == ' ') {
sb.replace(0, 2, "");
}
}
sb.insert(0, "Exchange[");
sb.append("]");
return sb.toString();
}