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 2010/03/22 12:22:47 UTC
svn commit: r926035 - in /camel/trunk/camel-core/src:
main/java/org/apache/camel/model/ProcessorDefinition.java
main/java/org/apache/camel/model/RecipientListDefinition.java
test/java/org/apache/camel/processor/CBRWithRecipientListTest.java
Author: davsclaus
Date: Mon Mar 22 11:22:47 2010
New Revision: 926035
URL: http://svn.apache.org/viewvc?rev=926035&view=rev
Log:
CAMEL-2567: recipientList now works inside a Content Based Router in Java DSL.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithRecipientListTest.java (with props)
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/RecipientListDefinition.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=926035&r1=926034&r2=926035&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 Mon Mar 22 11:22:47 2010
@@ -821,8 +821,7 @@ public abstract class ProcessorDefinitio
* destination gets a copy of the original message to avoid the processors
* interfering with each other.
*
- * @param aggregationStrategy the strategy used to aggregate responses for
- * every part
+ * @param aggregationStrategy the strategy used to aggregate responses for every part
* @return the builder
*/
public MulticastDefinition multicast(AggregationStrategy aggregationStrategy) {
@@ -1179,8 +1178,8 @@ public abstract class ProcessorDefinitio
* @return the builder
*/
@SuppressWarnings("unchecked")
- public RecipientListDefinition recipientList(Expression recipients) {
- RecipientListDefinition answer = new RecipientListDefinition(recipients);
+ public RecipientListDefinition<Type> recipientList(Expression recipients) {
+ RecipientListDefinition<Type> answer = new RecipientListDefinition<Type>(recipients);
addOutput(answer);
return answer;
}
@@ -1194,8 +1193,8 @@ public abstract class ProcessorDefinitio
* @return the builder
*/
@SuppressWarnings("unchecked")
- public RecipientListDefinition recipientList(Expression recipients, String delimiter) {
- RecipientListDefinition answer = new RecipientListDefinition(recipients);
+ public RecipientListDefinition<Type> recipientList(Expression recipients, String delimiter) {
+ RecipientListDefinition<Type> answer = new RecipientListDefinition<Type>(recipients);
answer.setDelimiter(delimiter);
addOutput(answer);
return answer;
@@ -1207,8 +1206,8 @@ public abstract class ProcessorDefinitio
*
* @return the expression clause to configure the expression to decide the destinations
*/
- public ExpressionClause<RecipientListDefinition> recipientList() {
- RecipientListDefinition answer = new RecipientListDefinition();
+ public ExpressionClause<RecipientListDefinition<Type>> recipientList() {
+ RecipientListDefinition<Type> answer = new RecipientListDefinition<Type>();
addOutput(answer);
return ExpressionClause.createAndSetExpression(answer);
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/RecipientListDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/RecipientListDefinition.java?rev=926035&r1=926034&r2=926035&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/RecipientListDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/RecipientListDefinition.java Mon Mar 22 11:22:47 2010
@@ -41,7 +41,7 @@ import org.apache.camel.util.concurrent.
*/
@XmlRootElement(name = "recipientList")
@XmlAccessorType(XmlAccessType.FIELD)
-public class RecipientListDefinition extends ExpressionNode implements ExecutorServiceAwareDefinition<RecipientListDefinition> {
+public class RecipientListDefinition<Type extends ProcessorDefinition> extends ExpressionNode implements ExecutorServiceAwareDefinition<RecipientListDefinition> {
@XmlTransient
private AggregationStrategy aggregationStrategy;
@@ -131,12 +131,20 @@ public class RecipientListDefinition ext
// Fluent API
// -------------------------------------------------------------------------
+ @Override
+ @SuppressWarnings("unchecked")
+ public Type end() {
+ // allow end() to return to previous type so you can continue in the DSL
+ return (Type) super.end();
+ }
+
/**
* Set the aggregationStrategy
*
+ * @param aggregationStrategy the strategy
* @return the builder
*/
- public RecipientListDefinition aggregationStrategy(AggregationStrategy aggregationStrategy) {
+ public RecipientListDefinition<Type> aggregationStrategy(AggregationStrategy aggregationStrategy) {
setAggregationStrategy(aggregationStrategy);
return this;
}
@@ -147,7 +155,7 @@ public class RecipientListDefinition ext
* @param aggregationStrategyRef a reference to a strategy to lookup
* @return the builder
*/
- public RecipientListDefinition aggregationStrategyRef(String aggregationStrategyRef) {
+ public RecipientListDefinition<Type> aggregationStrategyRef(String aggregationStrategyRef) {
setStrategyRef(aggregationStrategyRef);
return this;
}
@@ -157,7 +165,7 @@ public class RecipientListDefinition ext
*
* @return the builder
*/
- public RecipientListDefinition parallelProcessing() {
+ public RecipientListDefinition<Type> parallelProcessing() {
setParallelProcessing(true);
return this;
}
@@ -170,19 +178,19 @@ public class RecipientListDefinition ext
*
* @return the builder
*/
- public RecipientListDefinition stopOnException() {
+ public RecipientListDefinition<Type> stopOnException() {
setStopOnException(true);
return this;
}
@SuppressWarnings("unchecked")
- public RecipientListDefinition executorService(ExecutorService executorService) {
+ public RecipientListDefinition<Type> executorService(ExecutorService executorService) {
setExecutorService(executorService);
return this;
}
@SuppressWarnings("unchecked")
- public RecipientListDefinition executorServiceRef(String executorServiceRef) {
+ public RecipientListDefinition<Type> executorServiceRef(String executorServiceRef) {
setExecutorServiceRef(executorServiceRef);
return this;
}
Added: 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/CBRWithRecipientListTest.java?rev=926035&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithRecipientListTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithRecipientListTest.java Mon Mar 22 11:22:47 2010
@@ -0,0 +1,73 @@
+/**
+ * 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$
+ */
+public class CBRWithRecipientListTest extends ContextTestSupport {
+
+ public void testCBRWithRecipientListFoo() 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");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testCBRWithRecipientListBar() throws Exception {
+ getMockEndpoint("mock:result").expectedMessageCount(0);
+ getMockEndpoint("mock:foo").expectedMessageCount(0);
+ getMockEndpoint("mock:bar").expectedMessageCount(1);
+
+ template.sendBodyAndHeader("direct:start", "Donkey Kong", "bar", "mock:bar");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testCBRWithRecipientListResult() 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 {
+ from("direct:start")
+ .choice()
+ .when(body().contains("Camel"))
+ .recipientList(header("foo")).end()
+ .when(body().contains("Donkey"))
+ .recipientList(header("bar")).end()
+ .otherwise()
+ .to("mock:result");
+ }
+ };
+ }
+}
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithRecipientListTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWithRecipientListTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date