camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] camel git commit: CAMEL-10738: Fix direct-vm broken due bad code in callback when done routing.
Date Mon, 23 Jan 2017 07:07:24 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.18.x 85f4bd7ba -> 2a6216039
  refs/heads/master 9856285d1 -> 7a0d94c95


CAMEL-10738: Fix direct-vm broken due bad code in callback when done routing.


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

Branch: refs/heads/master
Commit: 7a0d94c95b9d3e4284eddb746e7b373ba8901548
Parents: 9856285
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Mon Jan 23 08:06:49 2017 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon Jan 23 08:06:49 2017 +0100

----------------------------------------------------------------------
 .../component/directvm/DirectVmProducer.java    | 15 +++-
 .../directvm/AbstractDirectVmTestSupport.java   |  6 ++
 .../DirectVmTwoCamelContextAdviceWithTest.java  | 83 ++++++++++++++++++++
 3 files changed, 100 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7a0d94c9/camel-core/src/main/java/org/apache/camel/component/directvm/DirectVmProducer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/directvm/DirectVmProducer.java
b/camel-core/src/main/java/org/apache/camel/component/directvm/DirectVmProducer.java
index 60d6f59..6ec6c9f 100644
--- a/camel-core/src/main/java/org/apache/camel/component/directvm/DirectVmProducer.java
+++ b/camel-core/src/main/java/org/apache/camel/component/directvm/DirectVmProducer.java
@@ -18,8 +18,10 @@ package org.apache.camel.component.directvm;
 
 import org.apache.camel.AsyncCallback;
 import org.apache.camel.Exchange;
+import org.apache.camel.Message;
 import org.apache.camel.impl.DefaultAsyncProducer;
 import org.apache.camel.spi.HeaderFilterStrategy;
+import org.apache.camel.util.ExchangeHelper;
 
 /**
  * The Direct-VM producer.
@@ -52,7 +54,7 @@ public class DirectVmProducer extends DefaultAsyncProducer {
 
         // Only clone the Exchange if we actually need to filter out properties or headers.
         final Exchange submitted = (!endpoint.isPropagateProperties() || headerFilterStrategy
!= null) ? exchange.copy(true) : exchange;
-        
+
         // Clear properties in the copy if we are not propagating them.
         if (!endpoint.isPropagateProperties()) {
             submitted.getProperties().clear();
@@ -64,11 +66,16 @@ public class DirectVmProducer extends DefaultAsyncProducer {
         }
         
         return consumer.getAsyncProcessor().process(submitted, done -> {
-            exchange.setException(submitted.getException());
-            exchange.getOut().copyFrom(submitted.hasOut() ? submitted.getOut() : submitted.getIn());
+            Message msg = submitted.hasOut() ? submitted.getOut() : submitted.getIn();
 
             if (headerFilterStrategy != null) {
-                exchange.getOut().getHeaders().entrySet().removeIf(e -> headerFilterStrategy.applyFilterToExternalHeaders(e.getKey(),
e.getValue(), submitted));
+                msg.getHeaders().entrySet().removeIf(e -> headerFilterStrategy.applyFilterToExternalHeaders(e.getKey(),
e.getValue(), submitted));
+            }
+
+            if (exchange != submitted) {
+                // only need to copy back if they are different
+                exchange.setException(submitted.getException());
+                exchange.getOut().copyFrom(msg);
             }
 
             if (endpoint.isPropagateProperties()) {

http://git-wip-us.apache.org/repos/asf/camel/blob/7a0d94c9/camel-core/src/test/java/org/apache/camel/component/directvm/AbstractDirectVmTestSupport.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/directvm/AbstractDirectVmTestSupport.java
b/camel-core/src/test/java/org/apache/camel/component/directvm/AbstractDirectVmTestSupport.java
index f093a18..9e18dd9 100644
--- a/camel-core/src/test/java/org/apache/camel/component/directvm/AbstractDirectVmTestSupport.java
+++ b/camel-core/src/test/java/org/apache/camel/component/directvm/AbstractDirectVmTestSupport.java
@@ -37,6 +37,8 @@ public abstract class AbstractDirectVmTestSupport extends ContextTestSupport
{
     protected void setUp() throws Exception {
         super.setUp();
 
+        doPostSetup();
+
         context2 = new DefaultCamelContext();
         template2 = context2.createProducerTemplate();
 
@@ -49,6 +51,10 @@ public abstract class AbstractDirectVmTestSupport extends ContextTestSupport
{
         }
     }
 
+    protected void doPostSetup() throws Exception {
+        // noop
+    }
+
     @Override
     @After
     protected void tearDown() throws Exception {

http://git-wip-us.apache.org/repos/asf/camel/blob/7a0d94c9/camel-core/src/test/java/org/apache/camel/component/directvm/DirectVmTwoCamelContextAdviceWithTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/directvm/DirectVmTwoCamelContextAdviceWithTest.java
b/camel-core/src/test/java/org/apache/camel/component/directvm/DirectVmTwoCamelContextAdviceWithTest.java
new file mode 100644
index 0000000..40fc7d6
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/directvm/DirectVmTwoCamelContextAdviceWithTest.java
@@ -0,0 +1,83 @@
+/**
+ * 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.directvm;
+
+import org.apache.camel.builder.AdviceWithRouteBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ *
+ */
+public class DirectVmTwoCamelContextAdviceWithTest extends AbstractDirectVmTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:step-1a").routeId("step-1a")
+                    .log("Before Step-1a ${body}")
+                    .to("direct-vm:step-2a")
+                    .log("After Step-1a ${body}");
+            }
+        };
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilderForSecondContext() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct-vm:step-2a").routeId("step-2a")
+                    .log("Before Step-2a ${body}")
+                    .setBody(constant("Bye"))
+                    .log("After Step-2a ${body}");
+            }
+        };
+    }
+
+    public void testTwoCamelContext() throws Exception {
+        // add route
+        context.addRoutes(createRouteBuilder());
+
+        // advice
+        context.getRouteDefinition("step-1a").adviceWith(context, new AdviceWithRouteBuilder()
{
+            @Override
+            public void configure() throws Exception {
+                weaveAddLast().to("mock:results");
+            }
+        });
+
+        // start camel
+        context.start();
+        context2.start();
+
+        MockEndpoint endpoint = getMockEndpoint("mock:results");
+        endpoint.expectedBodiesReceived("Bye");
+
+        template.sendBody("direct:step-1a", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+}


Mime
View raw message