You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2007/11/14 13:14:36 UTC
svn commit: r594849 - in /activemq/camel/trunk/camel-core/src:
main/java/org/apache/camel/processor/DeadLetterChannel.java
main/java/org/apache/camel/util/ExchangeHelper.java
test/java/org/apache/camel/issues/ExceptionTest.java
Author: jstrachan
Date: Wed Nov 14 04:14:34 2007
New Revision: 594849
URL: http://svn.apache.org/viewvc?rev=594849&view=rev
Log:
applied patch from Roman with thanks for http://issues.apache.org/activemq/browse/CAMEL-210
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/ExceptionTest.java
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java?rev=594849&r1=594848&r2=594849&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java Wed Nov 14 04:14:34 2007
@@ -119,11 +119,16 @@
if (!data.currentRedeliveryPolicy.shouldRedeliver(data.redeliveryCounter)) {
setFailureHandled(exchange, true);
AsyncProcessor afp = AsyncProcessorTypeConverter.convert(data.failureProcessor);
- return afp.process(exchange, new AsyncCallback() {
+ boolean sync = afp.process(exchange, new AsyncCallback() {
public void done(boolean sync) {
+ restoreExceptionOnExchange(exchange);
callback.done(data.sync);
}
});
+
+ restoreExceptionOnExchange(exchange);
+
+ return sync;
}
if (data.redeliveryCounter > 0) {
@@ -162,14 +167,24 @@
}
public static boolean isFailureHandled(Exchange exchange) {
- Boolean rc = exchange.getProperty(FAILURE_HANDLED_PROPERTY, Boolean.class);
- return rc == null ? false : rc;
+ return exchange.getProperty(FAILURE_HANDLED_PROPERTY) != null;
}
- public static void setFailureHandled(Exchange exchange, boolean b) {
- exchange.setProperty(FAILURE_HANDLED_PROPERTY, b ? Boolean.TRUE : Boolean.FALSE );
+ public static void setFailureHandled(Exchange exchange, boolean isHandled) {
+ if (isHandled) {
+ exchange.setProperty(FAILURE_HANDLED_PROPERTY, exchange.getException());
+ exchange.setException(null);
+ } else {
+ exchange.setException(exchange.getProperty(FAILURE_HANDLED_PROPERTY, Throwable.class));
+ exchange.removeProperty(FAILURE_HANDLED_PROPERTY);
+ }
+
}
+ public static void restoreExceptionOnExchange(Exchange exchange) {
+ exchange.setException(exchange.getProperty(FAILURE_HANDLED_PROPERTY, Throwable.class));
+ }
+
public void process(Exchange exchange) throws Exception {
AsyncProcessorHelper.process(this, exchange);
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java?rev=594849&r1=594848&r2=594849&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java Wed Nov 14 04:14:34 2007
@@ -189,6 +189,9 @@
// so lets assume the last IN is the OUT
result.getOut(true).copyFrom(source.getIn());
}
+ Map<String, Object> propertiesToCopy = new HashMap<String, Object>(source.getProperties());
+ propertiesToCopy.entrySet().removeAll(result.getProperties().entrySet());
+ result.getProperties().putAll(propertiesToCopy);
}
}
Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/ExceptionTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/ExceptionTest.java?rev=594849&r1=594848&r2=594849&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/ExceptionTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/ExceptionTest.java Wed Nov 14 04:14:34 2007
@@ -50,6 +50,30 @@
assertMockEndpointsSatisifed();
}
+ public void testExceptionWithLongHandler() throws Exception {
+ MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
+ MockEndpoint exceptionEndpoint = getMockEndpoint("mock:exception");
+
+ exceptionEndpoint.expectedBodiesReceived("<handled/>");
+ resultEndpoint.expectedMessageCount(0);
+
+ template.sendBody("direct:start", "<body/>");
+
+ assertMockEndpointsSatisifed();
+ }
+
+ public void testLongRouteWithHandler() throws Exception {
+ MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
+ MockEndpoint exceptionEndpoint = getMockEndpoint("mock:exception");
+
+ exceptionEndpoint.expectedMessageCount(1);
+ resultEndpoint.expectedMessageCount(0);
+
+ template.sendBody("direct:start2", "<body/>");
+
+ assertMockEndpointsSatisifed();
+ }
+
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
final Processor exceptionThrower = new Processor() {
@@ -61,11 +85,17 @@
return new RouteBuilder() {
public void configure() {
- if (getName().endsWith("WithHandler")) {
+ if (getName().endsWith("WithLongHandler")) {
+ log.debug("Using long exception handler");
+ exception(IllegalArgumentException.class).setBody(constant("<handled/>")).
+ to("mock:exception");
+ } else if (getName().endsWith("WithHandler")) {
log.debug("Using exception handler");
exception(IllegalArgumentException.class).to("mock:exception");
}
from("direct:start").process(exceptionThrower).to("mock:result");
+ from("direct:start2").to("direct:intermediate").to("mock:result");
+ from("direct:intermediate").setBody(constant("<some-value/>")).process(exceptionThrower).to("mock:resuilt");
}
};
}