CAMEL-6604: Fixed recipient list EIP to work with stream caching properly. Conflicts: camel-core/src/main/java/org/apache/camel/processor/RecipientListProcessor.java
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/94440979 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/94440979 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/94440979 Branch: refs/heads/camel-2.10.x Commit: 9444097971a7cc1fbd620dc7d06b9f881d3246be Parents: 10b3108 Author: Claus Ibsen <davscl...@apache.org> Authored: Mon Aug 5 11:57:06 2013 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Mon Aug 5 12:02:53 2013 +0200 ---------------------------------------------------------------------- .../camel/processor/RecipientListProcessor.java | 3 ++ .../StreamCachingRecipientListTest.java | 49 ++++++++++++++++++++ 2 files changed, 52 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/94440979/camel-core/src/main/java/org/apache/camel/processor/RecipientListProcessor.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/processor/RecipientListProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/RecipientListProcessor.java index 636a88a..d936b43 100644 --- a/camel-core/src/main/java/org/apache/camel/processor/RecipientListProcessor.java +++ b/camel-core/src/main/java/org/apache/camel/processor/RecipientListProcessor.java @@ -30,6 +30,7 @@ import org.apache.camel.impl.ProducerCache; import org.apache.camel.processor.aggregate.AggregationStrategy; import org.apache.camel.spi.RouteContext; import org.apache.camel.util.ExchangeHelper; +import org.apache.camel.util.MessageHelper; import org.apache.camel.util.ServiceHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -99,6 +100,8 @@ public class RecipientListProcessor extends MulticastProcessor { public void begin() { // we have already acquired and prepare the producer so we LOG.trace("RecipientProcessorExchangePair #{} begin: {}", index, exchange); + // ensure stream caching is reset + MessageHelper.resetStreamCache(exchange.getIn()); } public void done() { http://git-wip-us.apache.org/repos/asf/camel/blob/94440979/camel-core/src/test/java/org/apache/camel/processor/StreamCachingRecipientListTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/processor/StreamCachingRecipientListTest.java b/camel-core/src/test/java/org/apache/camel/processor/StreamCachingRecipientListTest.java new file mode 100644 index 0000000..373e3e4 --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/processor/StreamCachingRecipientListTest.java @@ -0,0 +1,49 @@ +/** + * 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.processor; + +import java.io.ByteArrayInputStream; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.builder.RouteBuilder; + +public class StreamCachingRecipientListTest extends ContextTestSupport { + + public void testByteArrayInputStream() throws Exception { + getMockEndpoint("mock:foo").expectedBodiesReceived("<hello/>"); + getMockEndpoint("mock:bar").expectedBodiesReceived("<hello/>"); + getMockEndpoint("mock:baz").expectedBodiesReceived("<hello/>"); + + template.sendBodyAndHeader("direct:a", new ByteArrayInputStream("<hello/>".getBytes()), "mySlip", "mock:foo,mock:bar,mock:baz"); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + context.setStreamCaching(true); + + from("direct:a") + .recipientList(header("mySlip")); + } + }; + } +} +