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/05/21 07:57:40 UTC
svn commit: r946886 - in /camel/trunk/camel-core/src:
main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java
test/java/org/apache/camel/processor/aggregator/AggregateRepositoryReturnNullTest.java
Author: davsclaus
Date: Fri May 21 05:57:40 2010
New Revision: 946886
URL: http://svn.apache.org/viewvc?rev=946886&view=rev
Log:
CAMEL-2744: Added better exception if AggregationStrategy returned null
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateRepositoryReturnNullTest.java (with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java?rev=946886&r1=946885&r2=946886&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java Fri May 21 05:57:40 2010
@@ -195,7 +195,7 @@ public class AggregateProcessor extends
* @param exchange the exchange
* @return the aggregated exchange
*/
- private Exchange doAggregation(String key, Exchange exchange) {
+ private Exchange doAggregation(String key, Exchange exchange) throws CamelExchangeException {
if (LOG.isTraceEnabled()) {
LOG.trace("onAggregation +++ start +++ with correlation key: " + key);
}
@@ -223,6 +223,10 @@ public class AggregateProcessor extends
// prepare the exchanges for aggregation and aggregate it
ExchangeHelper.prepareAggregation(oldExchange, newExchange);
answer = onAggregation(oldExchange, exchange);
+ if (answer == null) {
+ throw new CamelExchangeException("AggregationStrategy " + aggregationStrategy + " returned null which is not allowed", exchange);
+ }
+
// update the aggregated size
answer.setProperty(Exchange.AGGREGATED_SIZE, size);
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateRepositoryReturnNullTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateRepositoryReturnNullTest.java?rev=946886&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateRepositoryReturnNullTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateRepositoryReturnNullTest.java Fri May 21 05:57:40 2010
@@ -0,0 +1,61 @@
+/**
+ * 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.aggregator;
+
+import org.apache.camel.CamelExchangeException;
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.processor.aggregate.AggregationStrategy;
+
+/**
+ * @version $Revision$
+ */
+public class AggregateRepositoryReturnNullTest extends ContextTestSupport {
+
+ public void testAggregateRepositoryReturnNull() throws Exception {
+ try {
+ template.sendBodyAndHeader("direct:start", "Hello World", "id", 123);
+ fail("Should throw exception");
+ } catch (CamelExecutionException e) {
+ assertIsInstanceOf(CamelExchangeException.class, e.getCause());
+ assertTrue(e.getCause().getMessage().startsWith("AggregationStrategy"));
+ assertTrue(e.getCause().getMessage().contains("returned null which is not allowed"));
+ }
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .aggregate(header("id"), new MyNullAggregationStrategy()).completionSize(3)
+ .to("mock:result");
+ }
+ };
+ }
+
+ private class MyNullAggregationStrategy implements AggregationStrategy {
+ public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+ // on purpose
+ return null;
+ }
+ }
+
+}
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateRepositoryReturnNullTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateRepositoryReturnNullTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date