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 2014/09/01 11:18:20 UTC
[3/3] git commit: CAMEL-7581: Added aggregateOnException option to
enrich/pollEnrich so end users can handle exception in their aggregte method.
CAMEL-7581: Added aggregateOnException option to enrich/pollEnrich so end users can handle exception in their aggregte method.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4ffc5e25
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4ffc5e25
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4ffc5e25
Branch: refs/heads/master
Commit: 4ffc5e258c0d0e3ebba2bfe08c0c48416e4099a0
Parents: 5ad6cb8
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Sep 1 11:18:06 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Sep 1 11:18:06 2014 +0200
----------------------------------------------------------------------
.../EnricherAggregateOnExceptionTest.java | 25 ++++++-----
.../scala/org/apache/camel/scala/dsl/DSL.scala | 3 ++
.../camel/scala/dsl/SAbstractDefinition.scala | 3 ++
.../camel/scala/dsl/builder/RouteBuilder.scala | 3 ++
.../dsl/SEnricherAggregateOnExceptionTest.scala | 41 +++++++++++++++++
.../SpringEnricherAggregateOnExceptionTest.java | 30 +++++++++++++
.../SpringEnricherAggregateOnExceptionTest.xml | 47 ++++++++++++++++++++
7 files changed, 141 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/4ffc5e25/camel-core/src/test/java/org/apache/camel/processor/enricher/EnricherAggregateOnExceptionTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/enricher/EnricherAggregateOnExceptionTest.java b/camel-core/src/test/java/org/apache/camel/processor/enricher/EnricherAggregateOnExceptionTest.java
index 4353a66..844b598 100644
--- a/camel-core/src/test/java/org/apache/camel/processor/enricher/EnricherAggregateOnExceptionTest.java
+++ b/camel-core/src/test/java/org/apache/camel/processor/enricher/EnricherAggregateOnExceptionTest.java
@@ -85,21 +85,24 @@ public class EnricherAggregateOnExceptionTest extends ContextTestSupport {
.to("mock:result");
from("direct:foo")
- .process(new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- String body = exchange.getIn().getBody(String.class);
- if (body.startsWith("Kaboom")) {
- throw new IllegalArgumentException("I cannot do this");
- }
- exchange.getIn().setBody("Hello " + body);
- }
- });
+ .process(new MyProcessor());
}
};
}
- private class MyAggregationStrategy implements AggregationStrategy {
+ public static class MyProcessor implements Processor {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ String body = exchange.getIn().getBody(String.class);
+ if (body.startsWith("Kaboom")) {
+ throw new IllegalArgumentException("I cannot do this");
+ }
+ exchange.getIn().setBody("Hello " + body);
+ }
+ }
+
+ public static class MyAggregationStrategy implements AggregationStrategy {
@Override
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
http://git-wip-us.apache.org/repos/asf/camel/blob/4ffc5e25/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
----------------------------------------------------------------------
diff --git a/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala b/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
index a94416c..9900246 100644
--- a/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
+++ b/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
@@ -43,6 +43,7 @@ trait DSL {
def dynamicRouter(expression: Exchange => Any) : DSL
def enrich(uri:String, strategy: AggregationStrategy) : DSL
+ def enrich(uri:String, strategy: AggregationStrategy, aggregateOnException: Boolean) : DSL
def filter(predicate: Exchange => Any) : SFilterDefinition
@@ -71,6 +72,7 @@ trait DSL {
def pipeline : SPipelineDefinition
def policy(policy: Policy) : DSL
def pollEnrich(uri: String, strategy: AggregationStrategy = null, timeout: Long = 0) : DSL
+ def pollEnrich(uri: String, strategy: AggregationStrategy, timeout: Long, aggregateOnException: Boolean) : DSL
def process(function: Exchange => Unit) : DSL
def process(processor: Processor) : DSL
@@ -85,6 +87,7 @@ trait DSL {
def setBody(expression: Exchange => Any) : DSL
def setFaultBody(expression: Exchange => Any) : DSL
def setHeader(header: String, expression: Exchange => Any) : DSL
+ def setExchangePattern(mep: ExchangePattern) : DSL
def setProperty(header: String, expression: Exchange => Any) : DSL
def sort[T](expression: Exchange => Any, comparator: Comparator[T] = null) : DSL
def split(expression: Exchange => Any) : SSplitDefinition
http://git-wip-us.apache.org/repos/asf/camel/blob/4ffc5e25/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractDefinition.scala
----------------------------------------------------------------------
diff --git a/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractDefinition.scala b/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractDefinition.scala
index 16005c5..275b6d0 100644
--- a/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractDefinition.scala
+++ b/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractDefinition.scala
@@ -71,6 +71,7 @@ abstract class SAbstractDefinition[P <: ProcessorDefinition[_]] extends DSL with
def dynamicRouter(expression: Exchange => Any) = wrap(target.dynamicRouter(expression))
def enrich(uri: String, strategy: AggregationStrategy) = wrap(target.enrich(uri, strategy))
+ def enrich(uri: String, strategy: AggregationStrategy, aggregateOnException: Boolean) = wrap(target.enrich(uri, strategy, aggregateOnException))
def filter(predicate: Exchange => Any) = SFilterDefinition(target.filter(predicateBuilder(predicate)))
@@ -110,6 +111,8 @@ abstract class SAbstractDefinition[P <: ProcessorDefinition[_]] extends DSL with
def policy(policy: Policy) = wrap(target.policy(policy))
def pollEnrich(uri: String, strategy: AggregationStrategy = null, timeout: Long = -1) =
wrap(target.pollEnrich(uri, timeout, strategy))
+ def pollEnrich(uri: String, strategy: AggregationStrategy, timeout: Long, aggregateOnException: Boolean) =
+ wrap(target.pollEnrich(uri, timeout, strategy, aggregateOnException))
def process(function: Exchange => Unit) = wrap(target.process(new ScalaProcessor(function)))
def process(processor: Processor) = wrap(target.process(processor))
http://git-wip-us.apache.org/repos/asf/camel/blob/4ffc5e25/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
----------------------------------------------------------------------
diff --git a/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala b/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
index dead968..5d68b63 100644
--- a/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
+++ b/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
@@ -110,6 +110,7 @@ class RouteBuilder extends Preamble with DSL with RoutesBuilder with Languages w
def dynamicRouter(expression: Exchange => Any) = stack.top.dynamicRouter(expression)
def enrich(uri: String, strategy: AggregationStrategy) = stack.top.enrich(uri, strategy)
+ def enrich(uri: String, strategy: AggregationStrategy, aggregateOnException: Boolean) = stack.top.enrich(uri, strategy, aggregateOnException)
def errorHandler(error: ErrorHandlerBuilder) { builder.setErrorHandlerBuilder(error) }
def deadLetterChannel(uri: String) = {
val dlc = new DeadLetterChannelBuilder
@@ -163,6 +164,7 @@ class RouteBuilder extends Preamble with DSL with RoutesBuilder with Languages w
def pipeline = stack.top.pipeline
def pollEnrich(uri: String, strategy: AggregationStrategy = null, timeout: Long = 0) = stack.top.pollEnrich(uri, strategy, timeout)
+ def pollEnrich(uri: String, strategy: AggregationStrategy, timeout: Long, aggregateOnException: Boolean) = stack.top.pollEnrich(uri, strategy, timeout, aggregateOnException)
def policy(policy: Policy) = stack.top.policy(policy)
def process(function: Exchange => Unit) = stack.top.process(function)
def process(processor: Processor) = stack.top.process(processor)
@@ -178,6 +180,7 @@ class RouteBuilder extends Preamble with DSL with RoutesBuilder with Languages w
def setBody(expression : Exchange => Any) = stack.top.setBody(expression)
def setFaultBody(expression: Exchange => Any) = stack.top.setFaultBody(expression)
def setHeader(name: String, expression: Exchange => Any) = stack.top.setHeader(name, expression)
+ def setExchangePattern(mep: ExchangePattern) = stack.top.setExchangePattern(mep)
def setProperty(name: String, expression: Exchange => Any) = stack.top.setProperty(name, expression)
def sort[T](expression: (Exchange) => Any, comparator: Comparator[T] = null) = stack.top.sort(expression, comparator)
def split(expression: Exchange => Any) = stack.top.split(expression)
http://git-wip-us.apache.org/repos/asf/camel/blob/4ffc5e25/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SEnricherAggregateOnExceptionTest.scala
----------------------------------------------------------------------
diff --git a/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SEnricherAggregateOnExceptionTest.scala b/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SEnricherAggregateOnExceptionTest.scala
new file mode 100644
index 0000000..e8d4a8b
--- /dev/null
+++ b/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SEnricherAggregateOnExceptionTest.scala
@@ -0,0 +1,41 @@
+/**
+ * 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.scala.dsl
+
+import org.apache.camel.scala.dsl.builder.{RouteBuilderSupport, RouteBuilder}
+import org.apache.camel.processor.enricher.EnricherAggregateOnExceptionTest
+
+class SEnricherAggregateOnExceptionTest extends EnricherAggregateOnExceptionTest with RouteBuilderSupport {
+
+ override def createRouteBuilder = new RouteBuilder {
+ "direct:start" ==> {
+ enrich("direct:foo", new EnricherAggregateOnExceptionTest.MyAggregationStrategy(), aggregateOnException = true)
+ to("mock:result")
+ }
+
+ "direct:start2" ==> {
+ enrich("direct:foo", new EnricherAggregateOnExceptionTest.MyAggregationStrategy(), aggregateOnException = false)
+ to("mock:result")
+ }
+
+ "direct:foo" ==> {
+ process(new EnricherAggregateOnExceptionTest.MyProcessor())
+ }
+
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/4ffc5e25/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringEnricherAggregateOnExceptionTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringEnricherAggregateOnExceptionTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringEnricherAggregateOnExceptionTest.java
new file mode 100644
index 0000000..d585d31
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringEnricherAggregateOnExceptionTest.java
@@ -0,0 +1,30 @@
+/**
+ * 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.spring.processor;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.processor.enricher.EnricherAggregateOnExceptionTest;
+
+import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+public class SpringEnricherAggregateOnExceptionTest extends EnricherAggregateOnExceptionTest {
+
+ protected CamelContext createCamelContext() throws Exception {
+ return createSpringCamelContext(this, "org/apache/camel/spring/processor/SpringEnricherAggregateOnExceptionTest.xml");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/4ffc5e25/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringEnricherAggregateOnExceptionTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringEnricherAggregateOnExceptionTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringEnricherAggregateOnExceptionTest.xml
new file mode 100644
index 0000000..8084d3a
--- /dev/null
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringEnricherAggregateOnExceptionTest.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <enrich uri="direct:foo" strategyRef="myAggregator" aggregateOnException="true"/>
+ <to uri="mock:result"/>
+ </route>
+ <route>
+ <from uri="direct:start2"/>
+ <enrich uri="direct:foo" strategyRef="myAggregator" aggregateOnException="false"/>
+ <to uri="mock:result"/>
+ </route>
+ <route>
+ <from uri="direct:foo"/>
+ <process ref="myProcessor"/>
+ </route>
+ </camelContext>
+
+ <bean id="myProcessor" class="org.apache.camel.processor.enricher.EnricherAggregateOnExceptionTest.MyProcessor"/>
+
+ <bean id="myAggregator"
+ class="org.apache.camel.processor.enricher.EnricherAggregateOnExceptionTest.MyAggregationStrategy"/>
+
+</beans>