This is an automated email from the ASF dual-hosted git repository. orpiske pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new ce27767a62c (chores): break the before method on the StreamCachingAdvice ce27767a62c is described below commit ce27767a62c52c317d5b8c37459f81644bf3648e Author: Otavio Rodolfo Piske <angusyo...@gmail.com> AuthorDate: Fri May 5 18:00:34 2023 +0200 (chores): break the before method on the StreamCachingAdvice This should help the profiler to provide more useful information --- .../apache/camel/impl/engine/CamelInternalProcessor.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/CamelInternalProcessor.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/CamelInternalProcessor.java index 476bbf9838e..b6622a4368b 100644 --- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/CamelInternalProcessor.java +++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/CamelInternalProcessor.java @@ -26,6 +26,7 @@ import org.apache.camel.AsyncCallback; import org.apache.camel.CamelContext; import org.apache.camel.Exchange; import org.apache.camel.ExchangePropertyKey; +import org.apache.camel.Message; import org.apache.camel.MessageHistory; import org.apache.camel.NamedNode; import org.apache.camel.NamedRoute; @@ -933,9 +934,11 @@ public class CamelInternalProcessor extends DelegateAsyncProcessor implements In @Override public StreamCache before(Exchange exchange) throws Exception { + final Message inMessage = exchange.getIn(); + // check if body is already cached try { - Object body = exchange.getIn().getBody(); + Object body = inMessage.getBody(); if (body == null) { return null; } else if (body instanceof StreamCache) { @@ -957,7 +960,11 @@ public class CamelInternalProcessor extends DelegateAsyncProcessor implements In if (cause == null) { cause = exchange.getProperty(ExchangePropertyKey.EXCEPTION_CAUGHT, Throwable.class); } - boolean failed = cause != null && ObjectHelper.getException(StreamCacheException.class, cause) != null; + return tryStreamCache(exchange, inMessage, cause); + } + + private StreamCache tryStreamCache(Exchange exchange, Message inMessage, Throwable cause) { + final boolean failed = cause != null && ObjectHelper.getException(StreamCacheException.class, cause) != null; if (!failed) { boolean disabled = exchange.getExchangeExtension().isStreamCacheDisabled(); if (disabled) { @@ -967,7 +974,7 @@ public class CamelInternalProcessor extends DelegateAsyncProcessor implements In // cache the body and if we could do that replace it as the new body StreamCache sc = strategy.cache(exchange); if (sc != null) { - exchange.getIn().setBody(sc); + inMessage.setBody(sc); } return sc; } catch (Exception e) {