Author: davsclaus Date: Wed Apr 11 08:47:24 2012 New Revision: 1324642 URL: http://svn.apache.org/viewvc?rev=1324642&view=rev Log: CAMEL-5126: Improved error message if invalid configuration of throttler EIP. CAMEL-5163: Fixed issue if throttler/delayer expression evalution threw exception, then error handler does not react.
Added: camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/processor/ThrottlerInvalidConfiguredTest.java - copied unchanged from r1324638, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThrottlerInvalidConfiguredTest.java camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/processor/ThrottlerNullEvalTest.java - copied unchanged from r1324638, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThrottlerNullEvalTest.java Modified: camel/branches/camel-2.9.x/ (props changed) camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/model/ExpressionNode.java camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/model/ThrottleDefinition.java camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/processor/DelayProcessorSupport.java camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/processor/Throttler.java Propchange: camel/branches/camel-2.9.x/ ------------------------------------------------------------------------------ Merged /camel/trunk:r1324638 Propchange: camel/branches/camel-2.9.x/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/model/ExpressionNode.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/model/ExpressionNode.java?rev=1324642&r1=1324641&r2=1324642&view=diff ============================================================================== --- camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/model/ExpressionNode.java (original) +++ camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/model/ExpressionNode.java Wed Apr 11 08:47:24 2012 @@ -111,7 +111,7 @@ public class ExpressionNode extends Proc @Override protected void preCreateProcessor() { Expression exp = expression; - if (expression.getExpressionValue() != null) { + if (expression != null && expression.getExpressionValue() != null) { exp = expression.getExpressionValue(); } Modified: camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/model/ThrottleDefinition.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/model/ThrottleDefinition.java?rev=1324642&r1=1324641&r2=1324642&view=diff ============================================================================== --- camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/model/ThrottleDefinition.java (original) +++ camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/model/ThrottleDefinition.java Wed Apr 11 08:47:24 2012 @@ -87,7 +87,12 @@ public class ThrottleDefinition extends // should be default 1000 millis long period = getTimePeriodMillis() != null ? getTimePeriodMillis() : 1000L; + + // max requests per period is mandatory Expression maxRequestsExpression = createMaxRequestsPerPeriodExpression(routeContext); + if (maxRequestsExpression == null) { + throw new IllegalArgumentException("MaxRequestsPerPeriod expression must be provided on " + this); + } Throttler answer = new Throttler(childProcessor, maxRequestsExpression, period, scheduled); Modified: camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/processor/DelayProcessorSupport.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/processor/DelayProcessorSupport.java?rev=1324642&r1=1324641&r2=1324642&view=diff ============================================================================== --- camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/processor/DelayProcessorSupport.java (original) +++ camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/processor/DelayProcessorSupport.java Wed Apr 11 08:47:24 2012 @@ -90,11 +90,18 @@ public abstract class DelayProcessorSupp } // calculate delay and wait - long delay = calculateDelay(exchange); - if (delay <= 0) { - // no delay then continue routing - log.trace("No delay for exchangeId: {}", exchange.getExchangeId()); - return super.process(exchange, callback); + long delay; + try { + delay = calculateDelay(exchange); + if (delay <= 0) { + // no delay then continue routing + log.trace("No delay for exchangeId: {}", exchange.getExchangeId()); + return super.process(exchange, callback); + } + } catch (Throwable e) { + exchange.setException(e); + callback.done(true); + return true; } if (!isAsyncDelayed() || exchange.isTransacted()) { Modified: camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/processor/Throttler.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/processor/Throttler.java?rev=1324642&r1=1324641&r2=1324642&view=diff ============================================================================== --- camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/processor/Throttler.java (original) +++ camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/processor/Throttler.java Wed Apr 11 08:47:24 2012 @@ -21,6 +21,7 @@ import java.util.concurrent.ScheduledExe import org.apache.camel.Exchange; import org.apache.camel.Expression; import org.apache.camel.Processor; +import org.apache.camel.RuntimeExchangeException; import org.apache.camel.Traceable; import org.apache.camel.util.ObjectHelper; @@ -36,7 +37,7 @@ import org.apache.camel.util.ObjectHelpe * @version */ public class Throttler extends DelayProcessorSupport implements Traceable { - private long maximumRequestsPerPeriod; + private volatile long maximumRequestsPerPeriod; private Expression maxRequestsPerPeriodExpression; private long timePeriodMillis = 1000; private volatile TimeSlot slot; @@ -99,7 +100,14 @@ public class Throttler extends DelayProc // ----------------------------------------------------------------------- protected long calculateDelay(Exchange exchange) { - Long longValue = maxRequestsPerPeriodExpression.evaluate(exchange, Long.class); + // evaluate as Object first to see if we get any result at all + Object result = maxRequestsPerPeriodExpression.evaluate(exchange, Object.class); + if (result == null) { + throw new RuntimeExchangeException("The max requests per period expression was evaluated as null: " + maxRequestsPerPeriodExpression, exchange); + } + + // then must convert value to long + Long longValue = exchange.getContext().getTypeConverter().convertTo(Long.class, result); if (longValue != null) { // log if we changed max period after initial setting if (maximumRequestsPerPeriod > 0 && longValue.longValue() != maximumRequestsPerPeriod) {