You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ha...@apache.org on 2008/03/26 21:46:27 UTC
svn commit: r641566 - in /activemq/camel/trunk/camel-core/src:
main/java/org/apache/camel/processor/TryProcessor.java
test/java/org/apache/camel/builder/BuilderWithScopesTest.java
Author: hadrian
Date: Wed Mar 26 13:46:26 2008
New Revision: 641566
URL: http://svn.apache.org/viewvc?rev=641566&view=rev
Log:
CAMEL-399. Fixed tests.
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/BuilderWithScopesTest.java
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java?rev=641566&r1=641565&r2=641566&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java Wed Mar 26 13:46:26 2008
@@ -62,40 +62,27 @@
if (e != null && DeadLetterChannel.isFailureHandled(exchange)) {
e = null;
}
- } catch (Exception ex) {
+ } catch (Throwable ex) {
e = ex;
exchange.setException(e);
}
- if (e != null) {
- try {
+ Exception unexpected = null;
+ try {
+ if (e != null) {
+ LOG.info("Caught exception while processing exchange.", e);
handleException(exchange, e);
- } catch (Exception ex) {
- throw ex;
- } catch (Throwable ex) {
- throw new RuntimeCamelException(ex);
- } finally {
- processFinally(exchange);
}
- } else {
processFinally(exchange);
+ } catch (Exception ex) {
+ unexpected = ex;
+ } catch (Throwable ex) {
+ unexpected = new RuntimeCamelException(ex);
}
- }
-
- private void processFinally(Exchange exchange) {
- if (finallyProcessor != null) {
- Throwable lastException = exchange.getException();
- exchange.setException(null);
- try {
- finallyProcessor.process(exchange);
- if (exchange.getException() == null) {
- exchange.setException(lastException);
- }
- } catch (Exception e2) {
- LOG.warn("Caught exception in finally block while handling other exception: " + e2, e2);
- exchange.setException(e2);
- }
+ if (unexpected != null) {
+ LOG.warn("Caught exception inside catch clause.", unexpected);
+ throw unexpected;
}
}
@@ -115,20 +102,26 @@
localExchange.getIn().setHeader("caught.exception", e);
// give the rest of the pipeline another chance
localExchange.setException(null);
- try {
- catchClause.process(localExchange);
- ExchangeHelper.copyResults(exchange, localExchange);
- } catch (Exception e1) {
- LOG.warn("Caught exception inside catch clause: " + e1, e1);
- exchange.setException(e1);
- }
+
+ // do not catch any exception here, let it propagate up
+ catchClause.process(localExchange);
+ localExchange.getIn().removeHeader("caught.exception");
+ ExchangeHelper.copyResults(exchange, localExchange);
return;
}
}
+ }
- // unhandled exception
- if (finallyProcessor == null) {
- throw e;
+ protected void processFinally(Exchange exchange) throws Throwable {
+ if (finallyProcessor != null) {
+ Throwable lastException = exchange.getException();
+ exchange.setException(null);
+
+ // do not catch any exception here, let it propagate up
+ finallyProcessor.process(exchange);
+ if (exchange.getException() == null) {
+ exchange.setException(lastException);
+ }
}
}
}
Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/BuilderWithScopesTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/BuilderWithScopesTest.java?rev=641566&r1=641565&r2=641566&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/BuilderWithScopesTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/BuilderWithScopesTest.java Wed Mar 26 13:46:26 2008
@@ -291,6 +291,7 @@
protected RouteBuilder createTryCatchFinallyNoEnd() {
return new RouteBuilder() {
public void configure() {
+ errorHandler(deadLetterChannel().maximumRedeliveries(2));
from("direct:a").tryBlock().process(validator).process(toProcessor)
.handle(ValidationException.class).process(orderProcessor).finallyBlock()
.process(orderProcessor2).process(orderProcessor3); // continuation of the finallyBlock clause
@@ -323,6 +324,10 @@
expected.add("VALIDATE");
expected.add("INVOKED2");
expected.add("INVOKED3");
+ // exchange should be processed twice for an uncaught exception and maximumRedeliveries(2)
+ expected.add("VALIDATE");
+ expected.add("INVOKED2");
+ expected.add("INVOKED3");
runTest(createTryCatchFinallyNoEnd(), expected);
}
@@ -330,6 +335,7 @@
protected RouteBuilder createTryCatchFinallyEnd() {
return new RouteBuilder() {
public void configure() {
+ errorHandler(deadLetterChannel().maximumRedeliveries(2));
from("direct:a").tryBlock().process(validator).process(toProcessor)
.handle(ValidationException.class).process(orderProcessor).finallyBlock()
.process(orderProcessor2).end().process(orderProcessor3);
@@ -361,8 +367,11 @@
ArrayList<String> expected = new ArrayList<String>();
expected.add("VALIDATE");
expected.add("INVOKED2");
- expected.add("INVOKED3");
-
+ // exchange should be processed twice for an uncaught exception and maximumRedeliveries(2)
+ expected.add("VALIDATE");
+ expected.add("INVOKED2");
+ // orderProcessor3 will not be invoked past end() with an uncaught exception
+
runTest(createTryCatchFinallyEnd(), expected);
}
}