Author: davsclaus Date: Sun Apr 10 10:30:55 2011 New Revision: 1090762 URL: http://svn.apache.org/viewvc?rev=1090762&view=rev Log: CAMEL-3556: Added onPrepare to WireTap. Added fluent builders to wireTap Java DSL.
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapCustomPool2Test.java - copied, changed from r1090751, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapCustomPoolTest.java camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapOnPrepareRefTest.java camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapOnPrepareTest.java - copied, changed from r1090751, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MulticastOnPrepareTest.java camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringWireTapOnPrepareTest.java - copied, changed from r1090751, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringMulticastOnPrepareTest.java camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/WireTapOnPrepareTest.xml - copied, changed from r1090751, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/MulticastOnPrepareTest.xml Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java camel/trunk/camel-core/src/main/java/org/apache/camel/model/WireTapDefinition.java camel/trunk/camel-core/src/main/java/org/apache/camel/processor/WireTapProcessor.java camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapUsingFireAndForgetCopyAsDefaultTest.java camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapUsingFireAndForgetCopyTest.java camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/MulticastOnPrepareTest.xml Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java?rev=1090762&r1=1090761&r2=1090762&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java Sun Apr 10 10:30:55 2011 @@ -1928,12 +1928,11 @@ public abstract class ProcessorDefinitio * @param uri the destination * @return the builder */ - @SuppressWarnings("unchecked") - public Type wireTap(String uri) { + public WireTapDefinition wireTap(String uri) { WireTapDefinition answer = new WireTapDefinition(); answer.setUri(uri); addOutput(answer); - return (Type) this; + return answer; } /** @@ -1946,14 +1945,15 @@ public abstract class ProcessorDefinitio * @param executorService a custom {@link ExecutorService} to use as thread pool * for sending tapped exchanges * @return the builder + * @deprecated use the fluent builder from {@link WireTapDefinition} */ - @SuppressWarnings("unchecked") - public Type wireTap(String uri, ExecutorService executorService) { + @Deprecated + public WireTapDefinition wireTap(String uri, ExecutorService executorService) { WireTapDefinition answer = new WireTapDefinition(); answer.setUri(uri); answer.setExecutorService(executorService); addOutput(answer); - return (Type) this; + return answer; } /** @@ -1966,14 +1966,15 @@ public abstract class ProcessorDefinitio * @param executorServiceRef reference to lookup a custom {@link ExecutorService} * to use as thread pool for sending tapped exchanges * @return the builder + * @deprecated use the fluent builder from {@link WireTapDefinition} */ - @SuppressWarnings("unchecked") - public Type wireTap(String uri, String executorServiceRef) { + @Deprecated + public WireTapDefinition wireTap(String uri, String executorServiceRef) { WireTapDefinition answer = new WireTapDefinition(); answer.setUri(uri); answer.setExecutorServiceRef(executorServiceRef); addOutput(answer); - return (Type) this; + return answer; } /** @@ -1987,8 +1988,10 @@ public abstract class ProcessorDefinitio * @param uri the destination * @param body expression that creates the body to send * @return the builder + * @deprecated use the fluent builder from {@link WireTapDefinition} */ - public Type wireTap(String uri, Expression body) { + @Deprecated + public WireTapDefinition wireTap(String uri, Expression body) { return wireTap(uri, true, body); } @@ -2001,15 +2004,16 @@ public abstract class ProcessorDefinitio * @param copy whether or not use a copy of the original exchange or a new empty exchange * @param body expression that creates the body to send * @return the builder + * @deprecated use the fluent builder from {@link WireTapDefinition} */ - @SuppressWarnings("unchecked") - public Type wireTap(String uri, boolean copy, Expression body) { + @Deprecated + public WireTapDefinition wireTap(String uri, boolean copy, Expression body) { WireTapDefinition answer = new WireTapDefinition(); answer.setUri(uri); answer.setCopy(copy); answer.setNewExchangeExpression(body); addOutput(answer); - return (Type) this; + return answer; } /** @@ -2023,8 +2027,10 @@ public abstract class ProcessorDefinitio * @param uri the destination * @param processor processor preparing the new exchange to send * @return the builder + * @deprecated use the fluent builder from {@link WireTapDefinition} */ - public Type wireTap(String uri, Processor processor) { + @Deprecated + public WireTapDefinition wireTap(String uri, Processor processor) { return wireTap(uri, true, processor); } @@ -2037,15 +2043,16 @@ public abstract class ProcessorDefinitio * @param copy whether or not use a copy of the original exchange or a new empty exchange * @param processor processor preparing the new exchange to send * @return the builder + * @deprecated use the fluent builder from {@link WireTapDefinition} */ - @SuppressWarnings("unchecked") - public Type wireTap(String uri, boolean copy, Processor processor) { + @Deprecated + public WireTapDefinition wireTap(String uri, boolean copy, Processor processor) { WireTapDefinition answer = new WireTapDefinition(); answer.setUri(uri); answer.setCopy(copy); answer.setNewExchangeProcessor(processor); addOutput(answer); - return (Type) this; + return answer; } /** Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/WireTapDefinition.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/WireTapDefinition.java?rev=1090762&r1=1090761&r2=1090762&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/model/WireTapDefinition.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/WireTapDefinition.java Sun Apr 10 10:30:55 2011 @@ -30,12 +30,11 @@ import org.apache.camel.Expression; import org.apache.camel.Processor; import org.apache.camel.processor.WireTapProcessor; import org.apache.camel.spi.RouteContext; +import org.apache.camel.util.CamelContextHelper; import org.apache.camel.util.concurrent.ExecutorServiceHelper; /** * Represents an XML <wireTap/> element - * - * @version */ @XmlRootElement(name = "wireTap") @XmlAccessorType(XmlAccessType.FIELD) @@ -52,6 +51,10 @@ public class WireTapDefinition extends S private String executorServiceRef; @XmlAttribute private Boolean copy; + @XmlAttribute + private String onPrepareRef; + @XmlTransient + private Processor onPrepare; public WireTapDefinition() { } @@ -82,6 +85,12 @@ public class WireTapDefinition extends S if (newExchangeExpression != null) { answer.setNewExchangeExpression(newExchangeExpression.createExpression(routeContext)); } + if (onPrepareRef != null) { + onPrepare = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), onPrepareRef, Processor.class); + } + if (onPrepare != null) { + answer.setOnPrepare(onPrepare); + } return answer; } @@ -99,17 +108,108 @@ public class WireTapDefinition extends S public String getShortName() { return "wireTap"; } - - public ProcessorDefinition executorService(ExecutorService executorService) { - // wiretap has no outputs and therefore we cannot use custom wiretap builder methods in Java DSL - // as the Java DSL is stretched so far we can using regular Java - throw new UnsupportedOperationException("wireTap does not support these builder methods"); - } - - public ProcessorDefinition executorServiceRef(String executorServiceRef) { - // wiretap has no outputs and therefore we cannot use custom wiretap builder methods in Java DSL - // as the Java DSL is stretched so far we can using regular Java - throw new UnsupportedOperationException("wireTap does not support these builder methods"); + + @Override + public void addOutput(ProcessorDefinition output) { + // add outputs on parent as this wiretap does not support outputs + getParent().addOutput(output); + } + + // Fluent API + // ------------------------------------------------------------------------- + + /** + * Uses a custom thread pool + * + * @param executorService a custom {@link ExecutorService} to use as thread pool + * for sending tapped exchanges + * @return the builder + */ + public WireTapDefinition executorService(ExecutorService executorService) { + setExecutorService(executorService); + return this; + } + + /** + * Uses a custom thread pool + * + * @param executorServiceRef reference to lookup a custom {@link ExecutorService} + * to use as thread pool for sending tapped exchanges + * @return the builder + */ + public WireTapDefinition executorServiceRef(String executorServiceRef) { + setExecutorServiceRef(executorServiceRef); + return this; + } + + /** + * Uses a copy of the original exchange + * + * @return the builder + */ + public WireTapDefinition copy() { + setCopy(true); + return this; + } + + /** + * Sends a <i>new</i> Exchange, instead of tapping an existing, using {@link ExchangePattern#InOnly} + * + * @param expression expression that creates the new body to send + * @return the builder + */ + public WireTapDefinition newExchange(Expression expression) { + setNewExchangeExpression(expression); + return this; + } + + /** + * Sends a <i>new</i> Exchange, instead of tapping an existing, using {@link ExchangePattern#InOnly} + * + * @param processor processor preparing the new exchange to send + * @return the builder + */ + public WireTapDefinition newExchange(Processor processor) { + setNewExchangeProcessor(processor); + return this; + } + + /** + * Sends a <i>new</i> Exchange, instead of tapping an existing, using {@link ExchangePattern#InOnly} + * + * @param ref reference to the processor to lookup in the {@link org.apache.camel.spi.Registry} to + * be used for preparing the new exchange to send + * @return the builder + */ + public WireTapDefinition newExchangeRef(String ref) { + setNewExchangeProcessorRef(ref); + return this; + } + + /** + * Uses the {@link Processor} when preparing the {@link org.apache.camel.Exchange} to be send. + * This can be used to deep-clone messages that should be send, or any custom logic needed before + * the exchange is send. + * + * @param onPrepare the processor + * @return the builder + */ + public WireTapDefinition onPrepare(Processor onPrepare) { + setOnPrepare(onPrepare); + return this; + } + + /** + * Uses the {@link Processor} when preparing the {@link org.apache.camel.Exchange} to be send. + * This can be used to deep-clone messages that should be send, or any custom logic needed before + * the exchange is send. + * + * @param onPrepareRef reference to the processor to lookup in the {@link org.apache.camel.spi.Registry} + * @return the builder + */ + public WireTapDefinition onPrepareRef(String onPrepareRef) { + setOnPrepareRef(onPrepareRef); + return this; } public Processor getNewExchangeProcessor() { @@ -168,4 +268,20 @@ public class WireTapDefinition extends S // should default to true if not configured return copy != null ? copy : true; } + + public String getOnPrepareRef() { + return onPrepareRef; + } + + public void setOnPrepareRef(String onPrepareRef) { + this.onPrepareRef = onPrepareRef; + } + + public Processor getOnPrepare() { + return onPrepare; + } + + public void setOnPrepare(Processor onPrepare) { + this.onPrepare = onPrepare; + } } Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/WireTapProcessor.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/WireTapProcessor.java?rev=1090762&r1=1090761&r2=1090762&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/WireTapProcessor.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/WireTapProcessor.java Sun Apr 10 10:30:55 2011 @@ -44,6 +44,7 @@ public class WireTapProcessor extends Se private Expression newExchangeExpression; private Processor newExchangeProcessor; private boolean copy; + private Processor onPrepare; public WireTapProcessor(Endpoint destination, ExecutorService executorService) { super(destination); @@ -144,6 +145,15 @@ public class WireTapProcessor extends Se } } + // invoke on prepare on the exchange if specified + if (onPrepare != null) { + try { + onPrepare.process(exchange); + } catch (Exception e) { + exchange.setException(e); + } + } + return answer; } @@ -182,4 +192,12 @@ public class WireTapProcessor extends Se public void setCopy(boolean copy) { this.copy = copy; } + + public Processor getOnPrepare() { + return onPrepare; + } + + public void setOnPrepare(Processor onPrepare) { + this.onPrepare = onPrepare; + } } Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapCustomPool2Test.java (from r1090751, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapCustomPoolTest.java) URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapCustomPool2Test.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapCustomPool2Test.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapCustomPoolTest.java&r1=1090751&r2=1090762&rev=1090762&view=diff ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapCustomPoolTest.java (original) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapCustomPool2Test.java Sun Apr 10 10:30:55 2011 @@ -28,7 +28,7 @@ import org.apache.camel.component.mock.M * * @version */ -public class WireTapCustomPoolTest extends ContextTestSupport { +public class WireTapCustomPool2Test extends ContextTestSupport { protected MockEndpoint tap; protected MockEndpoint result; @@ -59,7 +59,7 @@ public class WireTapCustomPoolTest exten from("direct:start") .to("log:foo") // pass in the custom pool to the wireTap DSL - .wireTap("direct:tap", pool) + .wireTap("direct:tap").executorService(pool) .to("mock:result"); // END SNIPPET: e1 Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapOnPrepareRefTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapOnPrepareRefTest.java?rev=1090762&view=auto ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapOnPrepareRefTest.java (added) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapOnPrepareRefTest.java Sun Apr 10 10:30:55 2011 @@ -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 org.apache.camel.builder.RouteBuilder; +import org.apache.camel.impl.JndiRegistry; + +/** + * + */ +public class WireTapOnPrepareRefTest extends WireTapOnPrepareTest { + + @Override + protected JndiRegistry createRegistry() throws Exception { + JndiRegistry jndi = super.createRegistry(); + jndi.bind("deepClone", new AnimalDeepClonePrepare()); + return jndi; + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .wireTap("direct:a").onPrepareRef("deepClone") + .to("direct:b"); + + from("direct:a").process(new ProcessorA()).to("mock:a"); + from("direct:b").delay(1000).process(new ProcessorB()).to("mock:b"); + } + }; + } + +} Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapOnPrepareTest.java (from r1090751, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MulticastOnPrepareTest.java) URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapOnPrepareTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapOnPrepareTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MulticastOnPrepareTest.java&r1=1090751&r2=1090762&rev=1090762&view=diff ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MulticastOnPrepareTest.java (original) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapOnPrepareTest.java Sun Apr 10 10:30:55 2011 @@ -24,9 +24,9 @@ import org.apache.camel.builder.RouteBui /** * */ -public class MulticastOnPrepareTest extends ContextTestSupport { +public class WireTapOnPrepareTest extends ContextTestSupport { - public void testMulticastOnPrepare() throws Exception { + public void testWireTapOnPrepare() throws Exception { getMockEndpoint("mock:a").expectedMessageCount(1); getMockEndpoint("mock:a").message(0).body(String.class).isEqualTo("1 Tony the Tiger"); getMockEndpoint("mock:b").expectedMessageCount(1); @@ -44,11 +44,12 @@ public class MulticastOnPrepareTest exte public void configure() throws Exception { // START SNIPPET: e1 from("direct:start") - .multicast().onPrepare(new AnimalDeepClonePrepare()).to("direct:a").to("direct:b"); + .wireTap("direct:a").onPrepare(new AnimalDeepClonePrepare()) + .to("direct:b"); // END SNIPPET: e1 from("direct:a").process(new ProcessorA()).to("mock:a"); - from("direct:b").process(new ProcessorB()).to("mock:b"); + from("direct:b").delay(1000).process(new ProcessorB()).to("mock:b"); } }; } Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapUsingFireAndForgetCopyAsDefaultTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapUsingFireAndForgetCopyAsDefaultTest.java?rev=1090762&r1=1090761&r2=1090762&view=diff ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapUsingFireAndForgetCopyAsDefaultTest.java (original) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapUsingFireAndForgetCopyAsDefaultTest.java Sun Apr 10 10:30:55 2011 @@ -76,6 +76,46 @@ public class WireTapUsingFireAndForgetCo assertEquals("direct://start", e2.getFromEndpoint().getEndpointUri()); } + public void testFireAndForgetUsingProcessor2() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .wireTap("direct:foo").newExchange(new Processor() { + public void process(Exchange exchange) throws Exception { + String body = exchange.getIn().getBody(String.class); + exchange.getIn().setBody("Bye " + body); + exchange.getIn().setHeader("foo", "bar"); + } + }).to("mock:result"); + + + from("direct:foo").to("mock:foo"); + } + }); + context.start(); + + MockEndpoint result = getMockEndpoint("mock:result"); + result.expectedBodiesReceived("World"); + + MockEndpoint foo = getMockEndpoint("mock:foo"); + foo.expectedBodiesReceived("Bye World"); + foo.expectedHeaderReceived("foo", "bar"); + + template.sendBody("direct:start", "World"); + + assertMockEndpointsSatisfied(); + + // should be different exchange instances + Exchange e1 = result.getReceivedExchanges().get(0); + Exchange e2 = foo.getReceivedExchanges().get(0); + assertNotSame("Should not be same Exchange", e1, e2); + + // should have same from endpoint + assertEquals("direct://start", e1.getFromEndpoint().getEndpointUri()); + assertEquals("direct://start", e2.getFromEndpoint().getEndpointUri()); + } + public void testFireAndForgetUsingExpression() throws Exception { context.addRoutes(new RouteBuilder() { @Override @@ -111,4 +151,37 @@ public class WireTapUsingFireAndForgetCo assertEquals("direct://start", e2.getFromEndpoint().getEndpointUri()); } + public void testFireAndForgetUsingExpression2() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .wireTap("direct:foo").newExchange(simple("Bye ${body}")) + .to("mock:result"); + + from("direct:foo").to("mock:foo"); + } + }); + context.start(); + + MockEndpoint result = getMockEndpoint("mock:result"); + result.expectedBodiesReceived("World"); + + MockEndpoint foo = getMockEndpoint("mock:foo"); + foo.expectedBodiesReceived("Bye World"); + + template.sendBody("direct:start", "World"); + + assertMockEndpointsSatisfied(); + + // should be different exchange instances + Exchange e1 = result.getReceivedExchanges().get(0); + Exchange e2 = foo.getReceivedExchanges().get(0); + assertNotSame("Should not be same Exchange", e1, e2); + + // should have same from endpoint + assertEquals("direct://start", e1.getFromEndpoint().getEndpointUri()); + assertEquals("direct://start", e2.getFromEndpoint().getEndpointUri()); + } + } \ No newline at end of file Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapUsingFireAndForgetCopyTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapUsingFireAndForgetCopyTest.java?rev=1090762&r1=1090761&r2=1090762&view=diff ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapUsingFireAndForgetCopyTest.java (original) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/WireTapUsingFireAndForgetCopyTest.java Sun Apr 10 10:30:55 2011 @@ -76,6 +76,46 @@ public class WireTapUsingFireAndForgetCo assertEquals("direct://start", e2.getFromEndpoint().getEndpointUri()); } + public void testFireAndForgetUsingProcessor2() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .wireTap("direct:foo").copy().newExchange(new Processor() { + public void process(Exchange exchange) throws Exception { + String body = exchange.getIn().getBody(String.class); + exchange.getIn().setBody("Bye " + body); + exchange.getIn().setHeader("foo", "bar"); + } + }).to("mock:result"); + + + from("direct:foo").to("mock:foo"); + } + }); + context.start(); + + MockEndpoint result = getMockEndpoint("mock:result"); + result.expectedBodiesReceived("World"); + + MockEndpoint foo = getMockEndpoint("mock:foo"); + foo.expectedBodiesReceived("Bye World"); + foo.expectedHeaderReceived("foo", "bar"); + + template.sendBody("direct:start", "World"); + + assertMockEndpointsSatisfied(); + + // should be different exchange instances + Exchange e1 = result.getReceivedExchanges().get(0); + Exchange e2 = foo.getReceivedExchanges().get(0); + assertNotSame("Should not be same Exchange", e1, e2); + + // should have same from endpoint + assertEquals("direct://start", e1.getFromEndpoint().getEndpointUri()); + assertEquals("direct://start", e2.getFromEndpoint().getEndpointUri()); + } + public void testFireAndForgetUsingExpression() throws Exception { context.addRoutes(new RouteBuilder() { @Override @@ -111,4 +151,37 @@ public class WireTapUsingFireAndForgetCo assertEquals("direct://start", e2.getFromEndpoint().getEndpointUri()); } + public void testFireAndForgetUsingExpression2() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .wireTap("direct:foo").copy().newExchange(simple("Bye ${body}")) + .to("mock:result"); + + from("direct:foo").to("mock:foo"); + } + }); + context.start(); + + MockEndpoint result = getMockEndpoint("mock:result"); + result.expectedBodiesReceived("World"); + + MockEndpoint foo = getMockEndpoint("mock:foo"); + foo.expectedBodiesReceived("Bye World"); + + template.sendBody("direct:start", "World"); + + assertMockEndpointsSatisfied(); + + // should be different exchange instances + Exchange e1 = result.getReceivedExchanges().get(0); + Exchange e2 = foo.getReceivedExchanges().get(0); + assertNotSame("Should not be same Exchange", e1, e2); + + // should have same from endpoint + assertEquals("direct://start", e1.getFromEndpoint().getEndpointUri()); + assertEquals("direct://start", e2.getFromEndpoint().getEndpointUri()); + } + } \ No newline at end of file Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringWireTapOnPrepareTest.java (from r1090751, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringMulticastOnPrepareTest.java) URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringWireTapOnPrepareTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringWireTapOnPrepareTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringMulticastOnPrepareTest.java&r1=1090751&r2=1090762&rev=1090762&view=diff ============================================================================== --- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringMulticastOnPrepareTest.java (original) +++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringWireTapOnPrepareTest.java Sun Apr 10 10:30:55 2011 @@ -17,16 +17,16 @@ package org.apache.camel.spring.processor; import org.apache.camel.CamelContext; -import org.apache.camel.processor.MulticastOnPrepareTest; +import org.apache.camel.processor.WireTapOnPrepareTest; import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext; /** * @version */ -public class SpringMulticastOnPrepareTest extends MulticastOnPrepareTest { +public class SpringWireTapOnPrepareTest extends WireTapOnPrepareTest { protected CamelContext createCamelContext() throws Exception { - return createSpringCamelContext(this, "org/apache/camel/spring/processor/MulticastOnPrepareTest.xml"); + return createSpringCamelContext(this, "org/apache/camel/spring/processor/WireTapOnPrepareTest.xml"); } } \ No newline at end of file Modified: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/MulticastOnPrepareTest.xml URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/MulticastOnPrepareTest.xml?rev=1090762&r1=1090761&r2=1090762&view=diff ============================================================================== --- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/MulticastOnPrepareTest.xml (original) +++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/MulticastOnPrepareTest.xml Sun Apr 10 10:30:55 2011 @@ -22,9 +22,11 @@ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd "> + <!-- START SNIPPET: e1 --> <camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="direct:start"/> + <!-- use on prepare with multicast --> <multicast onPrepareRef="animalDeepClonePrepare"> <to uri="direct:a"/> <to uri="direct:b"/> @@ -43,8 +45,12 @@ </route> </camelContext> + <!-- the on prepare Processor which performs the deep cloning --> <bean id="animalDeepClonePrepare" class="org.apache.camel.processor.AnimalDeepClonePrepare"/> + + <!-- processors used for the last two routes, as part of unit test --> <bean id="processorA" class="org.apache.camel.processor.MulticastOnPrepareTest$ProcessorA"/> <bean id="processorB" class="org.apache.camel.processor.MulticastOnPrepareTest$ProcessorB"/> + <!-- END SNIPPET: e1 --> </beans> Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/WireTapOnPrepareTest.xml (from r1090751, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/MulticastOnPrepareTest.xml) URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/WireTapOnPrepareTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/WireTapOnPrepareTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/MulticastOnPrepareTest.xml&r1=1090751&r2=1090762&rev=1090762&view=diff ============================================================================== --- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/MulticastOnPrepareTest.xml (original) +++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/WireTapOnPrepareTest.xml Sun Apr 10 10:30:55 2011 @@ -22,13 +22,13 @@ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd "> + <!-- START SNIPPET: e1 --> <camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="direct:start"/> - <multicast onPrepareRef="animalDeepClonePrepare"> - <to uri="direct:a"/> - <to uri="direct:b"/> - </multicast> + <!-- use on prepare with wiretap --> + <wireTap uri="direct:a" onPrepareRef="animalDeepClonePrepare"/> + <to uri="direct:b"/> </route> <route> @@ -43,8 +43,12 @@ </route> </camelContext> + <!-- the on prepare Processor which performs the deep cloning --> <bean id="animalDeepClonePrepare" class="org.apache.camel.processor.AnimalDeepClonePrepare"/> + + <!-- processors used for the last two routes, as part of unit test --> <bean id="processorA" class="org.apache.camel.processor.MulticastOnPrepareTest$ProcessorA"/> <bean id="processorB" class="org.apache.camel.processor.MulticastOnPrepareTest$ProcessorB"/> + <!-- END SNIPPET: e1 --> </beans>