You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2011/02/17 14:53:19 UTC
svn commit: r1071613 - in /camel/trunk/camel-core/src:
main/java/org/apache/camel/model/ test/java/org/apache/camel/processor/
Author: davsclaus
Date: Thu Feb 17 13:53:19 2011
New Revision: 1071613
URL: http://svn.apache.org/viewvc?rev=1071613&view=rev
Log:
CAMEL-3678: Added endChoice in the DSL so you can use any EIPs inside the Content Based Router and continue routing with when/otherwise.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithLoadBalancerTest.java
- copied, changed from r1071517, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithRecipientListTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithMulticastTest.java
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/ToDefinition.java
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=1071613&r1=1071612&r2=1071613&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 Thu Feb 17 13:53:19 2011
@@ -1054,6 +1054,15 @@ public abstract class ProcessorDefinitio
}
/**
+ * Ends the current block and returns back to the {@link ChoiceDefinition choice()} DSL.
+ *
+ * @return the builder
+ */
+ public ChoiceDefinition endChoice() {
+ return (ChoiceDefinition) end();
+ }
+
+ /**
* <a href="http://camel.apache.org/idempotent-consumer.html">Idempotent consumer EIP:</a>
* Creates an {@link org.apache.camel.processor.idempotent.IdempotentConsumer IdempotentConsumer}
* to avoid duplicate messages
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ToDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ToDefinition.java?rev=1071613&r1=1071612&r2=1071613&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ToDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/ToDefinition.java Thu Feb 17 13:53:19 2011
@@ -90,7 +90,10 @@ public class ToDefinition extends SendDe
/**
* Sets the optional {@link ExchangePattern} used to invoke this endpoint
+ *
+ * @deprecated
*/
+ @Deprecated
public ToDefinition pattern(ExchangePattern pattern) {
setPattern(pattern);
return this;
Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithLoadBalancerTest.java (from r1071517, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithRecipientListTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithLoadBalancerTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithLoadBalancerTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithRecipientListTest.java&r1=1071517&r2=1071613&rev=1071613&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithRecipientListTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithLoadBalancerTest.java Thu Feb 17 13:53:19 2011
@@ -22,29 +22,30 @@ import org.apache.camel.builder.RouteBui
/**
* @version $Revision$
*/
-public class CBRWithRecipientListTest extends ContextTestSupport {
+public class CBRWithLoadBalancerTest extends ContextTestSupport {
- public void testCBRWithRecipientListFoo() throws Exception {
+ public void testFoo() throws Exception {
getMockEndpoint("mock:result").expectedMessageCount(0);
getMockEndpoint("mock:foo").expectedMessageCount(1);
getMockEndpoint("mock:bar").expectedMessageCount(0);
- template.sendBodyAndHeader("direct:start", "Camel rules", "foo", "mock:foo");
+ template.sendBody("direct:start", "Camel rules");
assertMockEndpointsSatisfied();
}
- public void testCBRWithRecipientListBar() throws Exception {
+ public void testFooBar() throws Exception {
getMockEndpoint("mock:result").expectedMessageCount(0);
- getMockEndpoint("mock:foo").expectedMessageCount(0);
+ getMockEndpoint("mock:foo").expectedMessageCount(1);
getMockEndpoint("mock:bar").expectedMessageCount(1);
- template.sendBodyAndHeader("direct:start", "Donkey Kong", "bar", "mock:bar");
+ template.sendBody("direct:start", "Camel rules");
+ template.sendBody("direct:start", "Camel rocks");
assertMockEndpointsSatisfied();
}
- public void testCBRWithRecipientListResult() throws Exception {
+ public void testResult() throws Exception {
getMockEndpoint("mock:result").expectedMessageCount(1);
getMockEndpoint("mock:foo").expectedMessageCount(0);
getMockEndpoint("mock:bar").expectedMessageCount(0);
@@ -59,14 +60,15 @@ public class CBRWithRecipientListTest ex
return new RouteBuilder() {
@Override
public void configure() throws Exception {
+ // START SNIPPET: e1
from("direct:start")
.choice()
.when(body().contains("Camel"))
- .recipientList(header("foo")).end()
- .when(body().contains("Donkey"))
- .recipientList(header("bar")).end()
+ // we need to use endChoice to tell Java DSL to return scope back to the choice DSL
+ .loadBalance().roundRobin().to("mock:foo").to("mock:bar").endChoice()
.otherwise()
.to("mock:result");
+ // END SNIPPET: e1
}
};
}
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithMulticastTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithMulticastTest.java?rev=1071613&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithMulticastTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithMulticastTest.java Thu Feb 17 13:53:19 2011
@@ -0,0 +1,75 @@
+/**
+ * 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.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision: 926035 $
+ */
+public class CBRWithMulticastTest extends ContextTestSupport {
+
+ public void testOneMessage() throws Exception {
+ getMockEndpoint("mock:result").expectedMessageCount(0);
+ getMockEndpoint("mock:foo").expectedMessageCount(1);
+ getMockEndpoint("mock:bar").expectedMessageCount(1);
+
+ template.sendBody("direct:start", "Camel rules");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testTwoMesssages() throws Exception {
+ getMockEndpoint("mock:result").expectedMessageCount(0);
+ getMockEndpoint("mock:foo").expectedMessageCount(2);
+ getMockEndpoint("mock:bar").expectedMessageCount(2);
+
+ template.sendBody("direct:start", "Camel rules");
+ template.sendBody("direct:start", "Camel rocks");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testResult() throws Exception {
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+ getMockEndpoint("mock:foo").expectedMessageCount(0);
+ getMockEndpoint("mock:bar").expectedMessageCount(0);
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // START SNIPPET: e1
+ from("direct:start")
+ .choice()
+ .when(body().contains("Camel"))
+ // we need to use endChoice to tell Java DSL to return scope back to the choice DSL
+ .multicast().to("mock:foo").to("mock:bar").endChoice()
+ .otherwise()
+ .to("mock:result");
+ // END SNIPPET: e1
+ }
+ };
+ }
+}