camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/3] camel git commit: CAMEL-10406: vm endpoint should prepare exchange with the CamelContext from the consumer and not from cached endpoint which can be different. Thanks to Xavier Fournet for the unit test.
Date Sat, 29 Oct 2016 19:55:16 GMT
CAMEL-10406: vm endpoint should prepare exchange with the CamelContext from the consumer and
not from cached endpoint which can be different. Thanks to Xavier Fournet for the unit test.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/df5e6a67
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/df5e6a67
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/df5e6a67

Branch: refs/heads/camel-2.18.x
Commit: df5e6a675eb02abb8b6c71673dd5541b013cbdd2
Parents: 7ae4a18
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Oct 29 21:54:15 2016 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Oct 29 21:54:42 2016 +0200

----------------------------------------------------------------------
 .../apache/camel/component/vm/VmConsumer.java   | 33 +++++++++++-
 .../vm/VmShouldUseConsumerContext.java          | 54 ++++++++++++++++++++
 2 files changed, 86 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/df5e6a67/camel-core/src/main/java/org/apache/camel/component/vm/VmConsumer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/vm/VmConsumer.java b/camel-core/src/main/java/org/apache/camel/component/vm/VmConsumer.java
index a110ba4..ef4666c 100644
--- a/camel-core/src/main/java/org/apache/camel/component/vm/VmConsumer.java
+++ b/camel-core/src/main/java/org/apache/camel/component/vm/VmConsumer.java
@@ -16,12 +16,43 @@
  */
 package org.apache.camel.component.vm;
 
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.component.seda.SedaConsumer;
+import org.apache.camel.util.ExchangeHelper;
 
-public class VmConsumer extends SedaConsumer {
+public class VmConsumer extends SedaConsumer implements CamelContextAware {
+
+    private CamelContext camelContext;
 
     public VmConsumer(VmEndpoint endpoint, Processor processor) {
         super(endpoint, processor);
     }
+
+    @Override
+    public CamelContext getCamelContext() {
+        return camelContext;
+    }
+
+    @Override
+    public void setCamelContext(CamelContext camelContext) {
+        this.camelContext = camelContext;
+    }
+
+    /**
+     * Strategy to prepare exchange for being processed by this consumer
+     *
+     * @param exchange the exchange
+     * @return the exchange to process by this consumer.
+     */
+    protected Exchange prepareExchange(Exchange exchange) {
+        // send a new copied exchange with the camel context from this consumer
+        Exchange newExchange = ExchangeHelper.copyExchangeAndSetCamelContext(exchange, getCamelContext());
+        // set the from endpoint
+        newExchange.setFromEndpoint(getEndpoint());
+        return newExchange;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/df5e6a67/camel-core/src/test/java/org/apache/camel/component/vm/VmShouldUseConsumerContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/vm/VmShouldUseConsumerContext.java
b/camel-core/src/test/java/org/apache/camel/component/vm/VmShouldUseConsumerContext.java
new file mode 100644
index 0000000..2babebe
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/vm/VmShouldUseConsumerContext.java
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.vm;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class VmShouldUseConsumerContext extends AbstractVmTestSupport {
+
+    public void testConsumerContext() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+
+        String out = template2.requestBody("direct:start", "Hello World", String.class);
+        assertEquals("Hello World", out);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // using "toD" instead of "to" make use of the exchange context to resolve
the direct endpoint at route execution.
+                // if the exchange context is not the excepted one, the toD will fail
+                from("vm:test").toD("direct:process");
+                from("direct:process").to("mock:result");
+            }
+        };
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilderForSecondContext() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").to("vm:test");
+            }
+        };
+    }
+}
\ No newline at end of file


Mime
View raw message