public static String extractBodyAsString(Message message) {
if (message == null) {
return null;
}
StreamCache newBody = null;
try {
newBody = message.getBody(StreamCache.class);
if (newBody != null) {
message.setBody(newBody);
}
} catch (NoTypeConversionAvailableException ex) {
// ignore, in not of StreamCache type
}
Object answer;
try {
answer = message.getBody(String.class);
} catch (NoTypeConversionAvailableException ex) {
answer = message.getBody();
}
if (newBody != null) {
// Reset the InputStreamCache
newBody.reset();
}
return answer != null ? answer.toString() : null;
}