You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Steven Durrenmath <st...@gmail.com> on 2021/01/06 10:46:06 UTC
[camel-support] Wrapped input stream not reset after extracting message body for logging
Hello,
Say I have a route with stream caching enabled and I send an exchange to an endpoint. Then I call:
MessageHelper.extractBodyForLogging(exchange.getMessage(), "", true, false);
The wrapped input stream is not reset and therefore not reusable. This is because body is of type CachedOutputStream$WrappedInputStream which does not override method markSupported.
https://github.com/apache/camel/blob/master/core/camel-support/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java#L168
Now checking the implementation of method extractBodyForLogging, in particular L348: https://github.com/apache/camel/blob/master/core/camel-support/src/main/java/org/apache/camel/support/MessageHelper.java#L348
else if (is != null && is.markSupported()) {
try {
is.reset();
} catch (IOException e) {
// ignore
}
}
Since the markSupported method of InputStream returns false, the stream is never reset.
There is another method that handles input streams that are wrapped in StreamCache: MessageHelper.extractBodyAsString. See https://github.com/apache/camel/blob/camel-3.6.0/core/camel-support/src/main/java/org/apache/camel/support/MessageHelper.java#L64
// we need to favor using stream cache so the body can be re-read later
StreamCache newBody = message.getBody(StreamCache.class);
if (newBody != null) {
message.setBody(newBody);
}
if (newBody != null) {
// Reset the InputStreamCache
newBody.reset();
}
But this method is not for logging purpose as it will not clip the message body.
Is there something I am missing?
Kind regards,
Steven Durrenmath