CAMEL-6780: Binding component - Avoid duplicate prepare.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ce710545 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ce710545 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ce710545 Branch: refs/heads/camel-2.11.x Commit: ce710545affe8f49e2c8a39b7d157a801ce003b8 Parents: 4aed32f Author: Claus Ibsen <davscl...@apache.org> Authored: Tue Sep 24 11:41:23 2013 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Tue Sep 24 11:43:28 2013 +0200 ---------------------------------------------------------------------- .../component/binding/BindingEndpoint.java | 23 ++++---------------- .../org/apache/camel/processor/Pipeline.java | 10 +-------- .../apache/camel/processor/PipelineHelper.java | 20 +++++++++++++++++ 3 files changed, 25 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/ce710545/camel-core/src/main/java/org/apache/camel/component/binding/BindingEndpoint.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/component/binding/BindingEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/binding/BindingEndpoint.java index 1c44fb3..65707c1 100644 --- a/camel-core/src/main/java/org/apache/camel/component/binding/BindingEndpoint.java +++ b/camel-core/src/main/java/org/apache/camel/component/binding/BindingEndpoint.java @@ -24,9 +24,9 @@ import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.Producer; import org.apache.camel.impl.DefaultEndpoint; +import org.apache.camel.processor.PipelineHelper; import org.apache.camel.spi.Binding; import org.apache.camel.spi.HasBinding; -import org.apache.camel.util.ExchangeHelper; import org.apache.camel.util.ServiceHelper; /** @@ -73,25 +73,10 @@ public class BindingEndpoint extends DefaultEndpoint implements HasBinding { * Applies the {@link Binding} processor to the given exchange before passing it on to the delegateProcessor (either a producer or consumer) */ public void pipelineBindingProcessor(Processor bindingProcessor, Exchange exchange, Processor delegateProcessor) throws Exception { - // use same exchange - seems Pipeline does these days - Exchange bindingExchange = exchange; - bindingProcessor.process(bindingExchange); - Exchange delegateExchange = createNextExchange(bindingExchange); - ExchangeHelper.copyResults(bindingExchange, delegateExchange); - delegateProcessor.process(delegateExchange); - } - - // TODO this code was copied from Pipeline - should make it static and reuse the code? - protected Exchange createNextExchange(Exchange previousExchange) { - Exchange answer = previousExchange; + bindingProcessor.process(exchange); - // now lets set the input of the next exchange to the output of the - // previous message if it is not null - if (answer.hasOut()) { - answer.setIn(answer.getOut()); - answer.setOut(null); - } - return answer; + Exchange delegateExchange = PipelineHelper.createNextExchange(exchange); + delegateProcessor.process(delegateExchange); } @Override http://git-wip-us.apache.org/repos/asf/camel/blob/ce710545/camel-core/src/main/java/org/apache/camel/processor/Pipeline.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/processor/Pipeline.java b/camel-core/src/main/java/org/apache/camel/processor/Pipeline.java index 3ace4c5..28779d8 100644 --- a/camel-core/src/main/java/org/apache/camel/processor/Pipeline.java +++ b/camel-core/src/main/java/org/apache/camel/processor/Pipeline.java @@ -157,15 +157,7 @@ public class Pipeline extends MulticastProcessor implements AsyncProcessor, Trac * @return a new exchange */ protected Exchange createNextExchange(Exchange previousExchange) { - Exchange answer = previousExchange; - - // now lets set the input of the next exchange to the output of the - // previous message if it is not null - if (answer.hasOut()) { - answer.setIn(answer.getOut()); - answer.setOut(null); - } - return answer; + return PipelineHelper.createNextExchange(previousExchange); } protected boolean continueRouting(Iterator<Processor> it, Exchange exchange) { http://git-wip-us.apache.org/repos/asf/camel/blob/ce710545/camel-core/src/main/java/org/apache/camel/processor/PipelineHelper.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/processor/PipelineHelper.java b/camel-core/src/main/java/org/apache/camel/processor/PipelineHelper.java index 8c850a3..ebc5398 100644 --- a/camel-core/src/main/java/org/apache/camel/processor/PipelineHelper.java +++ b/camel-core/src/main/java/org/apache/camel/processor/PipelineHelper.java @@ -92,4 +92,24 @@ public final class PipelineHelper { return true; } + /** + * Strategy method to create the next exchange from the previous exchange. + * <p/> + * Remember to copy the original exchange id otherwise correlation of ids in the log is a problem + * + * @param previousExchange the previous exchange + * @return a new exchange + */ + public static Exchange createNextExchange(Exchange previousExchange) { + Exchange answer = previousExchange; + + // now lets set the input of the next exchange to the output of the + // previous message if it is not null + if (answer.hasOut()) { + answer.setIn(answer.getOut()); + answer.setOut(null); + } + return answer; + } + }