Updated Branches: refs/heads/camel-2.11.x 4aed32f69 -> ce710545a refs/heads/camel-2.12.x 0018d8992 -> 936a589a6 refs/heads/master 1ce21f422 -> 1e5feb83f
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/62994fd8 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/62994fd8 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/62994fd8 Branch: refs/heads/master Commit: 62994fd811c0b95b7594f832787b8e537b169c25 Parents: 1ce21f4 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:41:23 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/62994fd8/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/62994fd8/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 99ab66e..9c14476 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 @@ -158,15 +158,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/62994fd8/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; + } + }