Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id CB6AE200C14 for ; Mon, 23 Jan 2017 08:07:26 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id C570D160B3E; Mon, 23 Jan 2017 07:07:26 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id E9CFA160B49 for ; Mon, 23 Jan 2017 08:07:25 +0100 (CET) Received: (qmail 77857 invoked by uid 500); 23 Jan 2017 07:07:25 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 77831 invoked by uid 99); 23 Jan 2017 07:07:25 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Jan 2017 07:07:25 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E274CDFD6D; Mon, 23 Jan 2017 07:07:24 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Mon, 23 Jan 2017 07:07:25 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/2] camel git commit: CAMEL-10738: Fix direct-vm broken due bad code in callback when done routing. archived-at: Mon, 23 Jan 2017 07:07:27 -0000 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/2a621603 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2a621603 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2a621603 Branch: refs/heads/camel-2.18.x Commit: 2a6216039f4bf8da39d728b9975b16e68f1e419b Parents: 85f4bd7 Author: Claus Ibsen Authored: Mon Jan 23 08:06:49 2017 +0100 Committer: Claus Ibsen Committed: Mon Jan 23 08:07:14 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/2a621603/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/2a621603/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/2a621603/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(); + } + +}