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 2009/02/22 15:28:13 UTC
svn commit: r746709 - in /camel/trunk:
camel-core/src/main/java/org/apache/camel/
camel-core/src/main/java/org/apache/camel/builder/
camel-core/src/main/java/org/apache/camel/impl/
camel-core/src/main/java/org/apache/camel/model/ camel-core/src/main/ja...
Author: davsclaus
Date: Sun Feb 22 14:28:12 2009
New Revision: 746709
URL: http://svn.apache.org/viewvc?rev=746709&view=rev
Log:
CAMEL-1368: onRedelivery now support per exception clause, instead of only global. Using CamelCase for some header keys.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelOnExceptionOnRedeliveryTest.java
- copied, changed from r746489, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelOnRedeliveryTest.java
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/SpringDeadLetterChannelOnExceptionOnRedeliveryTest.java
- copied, changed from r746448, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/RedeliveryPolicyReTest.java
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/DeadLetterChannelOnExceptionOnRedeliveryTest.xml
- copied, changed from r746448, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/RedeliveryPolicyRefTest.xml
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExceptionType.java
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Pipeline.java
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/BelasThreadErrorHandlerIssue794Test.java
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/ThreadErrorHandlerTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/model/GenerateXmFromCamelContextlTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelExceptionCausePropagatedTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelOnRedeliveryTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelRedeliveryDelayPatternTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelRedeliveryTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RedeliveryPolicyPerExceptionTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/InterceptAlterMessageBeforeRedeliveryTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionRetryUntilTest.java
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsRedeliveryWithInitialRedeliveryDelayTest.java
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionInterceptor.java
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/DeadLetterChannelRedeliveryConfigTest.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java?rev=746709&r1=746708&r2=746709&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java Sun Feb 22 14:28:12 2009
@@ -30,11 +30,22 @@
*/
public interface Exchange {
- String CHARSET_NAME = "org.apache.camel.Exchange.CharsetName";
+ String AGGREGATED_COUNT = "CamelAggregatedCount";
- String AGGREGATED_COUNT = "org.apache.camel.Exchange.AggregatedCount";
+ String CHARSET_NAME = "CamelCharsetName";
+
+ String EXCEPTION_CAUGHT = "CamelExceptionCaught";
+
+ String EXCEPTION_HANDLED = "CamelExceptionHandled";
+
+ String FAILURE_HANDLED = "CamelFailureHandled";
+
+ String REDELIVERED = "CamelRedelivered";
+
+ String REDELIVERY_COUNTER = "CamelRedeliveryCounter";
+
+ String TRANSACTED = "CamelTransacted";
- String EXCEPTION_HANDLED_PROPERTY = "CamelExceptionHandled";
/**
* Returns the {@link ExchangePattern} (MEP) of this exchange.
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java?rev=746709&r1=746708&r2=746709&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java Sun Feb 22 14:28:12 2009
@@ -152,7 +152,7 @@
public Object evaluate(Exchange exchange) {
Throwable exception = exchange.getException();
if (exception == null) {
- exception = exchange.getProperty(DeadLetterChannel.EXCEPTION_CAUSE_PROPERTY, Throwable.class);
+ exception = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
}
return exception;
}
@@ -175,7 +175,7 @@
public Object evaluate(Exchange exchange) {
Throwable exception = exchange.getException();
if (exception == null) {
- exception = exchange.getProperty(DeadLetterChannel.EXCEPTION_CAUSE_PROPERTY, Throwable.class);
+ exception = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
}
return exception != null ? exception.getMessage() : null;
}
@@ -451,6 +451,7 @@
/**
* Returns an expression which converts the given expression to the given type
*/
+ @SuppressWarnings("unchecked")
public static Expression convertToExpression(final Expression expression, final Class type) {
return new ExpressionAdapter() {
public Object evaluate(Exchange exchange) {
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java?rev=746709&r1=746708&r2=746709&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java Sun Feb 22 14:28:12 2009
@@ -313,8 +313,8 @@
}
public boolean isTransacted() {
- ExchangeProperty<?> property = ExchangeProperty.get("transacted");
- return property != null && property.get(this) == Boolean.TRUE;
+ Boolean transacted = getProperty(TRANSACTED, Boolean.class);
+ return transacted != null && transacted;
}
public UnitOfWork getUnitOfWork() {
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExceptionType.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExceptionType.java?rev=746709&r1=746708&r2=746709&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExceptionType.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExceptionType.java Sun Feb 22 14:28:12 2009
@@ -26,6 +26,7 @@
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
+import javax.xml.bind.annotation.XmlAttribute;
import org.apache.camel.CamelContext;
import org.apache.camel.Expression;
@@ -61,6 +62,8 @@
private RedeliveryPolicyType redeliveryPolicy;
@XmlElement(name = "handled", required = false)
private ExpressionSubElementType handled;
+ @XmlAttribute(name = "onRedeliveryRef", required = false)
+ private String onRedeliveryRef;
@XmlElementRef
private List<ProcessorType> outputs = new ArrayList<ProcessorType>();
@XmlTransient
@@ -71,6 +74,8 @@
private Predicate handledPolicy;
@XmlTransient
private Predicate retryUntilPolicy;
+ @XmlTransient
+ private Processor onRedelivery;
public ExceptionType() {
}
@@ -115,6 +120,11 @@
errorHandler = routeContext.createProcessor(this);
ErrorHandlerBuilder builder = routeContext.getRoute().getErrorHandlerBuilder();
builder.addErrorHandlers(this);
+
+ // lookup onRedelivery if ref is provided
+ if (ObjectHelper.isNotEmpty(onRedeliveryRef)) {
+ onRedelivery = routeContext.lookup(onRedeliveryRef, Processor.class);
+ }
}
@Override
@@ -331,6 +341,16 @@
return this;
}
+ /**
+ * Sets a processor that should be processed <b>before</b> a redelivey attempt.
+ * <p/>
+ * Can be used to change the {@link org.apache.camel.Exchange} <b>before</b> its being redelivered.
+ */
+ public ExceptionType onRedelivery(Processor processor) {
+ setOnRedelivery(processor);
+ return this;
+ }
+
// Properties
//-------------------------------------------------------------------------
public List<ProcessorType> getOutputs() {
@@ -412,6 +432,23 @@
this.retryUntilPolicy = retryUntilPolicy;
}
+ public Processor getOnRedelivery() {
+ return onRedelivery;
+ }
+
+ public void setOnRedelivery(Processor onRedelivery) {
+ this.onRedelivery = onRedelivery;
+ }
+
+ public String getOnRedeliveryRef() {
+ return onRedeliveryRef;
+ }
+
+ public void setOnRedeliveryRef(String onRedeliveryRef) {
+ this.onRedeliveryRef = onRedeliveryRef;
+ }
+
+
// Implementation methods
//-------------------------------------------------------------------------
protected RedeliveryPolicyType getOrCreateRedeliveryPolicy() {
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java?rev=746709&r1=746708&r2=746709&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java Sun Feb 22 14:28:12 2009
@@ -45,14 +45,8 @@
* @version $Revision$
*/
public class DeadLetterChannel extends ErrorHandlerSupport implements AsyncProcessor {
- public static final String REDELIVERY_COUNTER = "org.apache.camel.RedeliveryCounter";
- public static final String REDELIVERED = "org.apache.camel.Redelivered";
- public static final String EXCEPTION_CAUSE_PROPERTY = "CamelCauseException";
- public static final String CAUGHT_EXCEPTION_HEADER = "org.apache.camel.CamelCaughtException";
-
private static final transient Log LOG = LogFactory.getLog(DeadLetterChannel.class);
- private static final String FAILURE_HANDLED_PROPERTY = DeadLetterChannel.class.getName() + ".FAILURE_HANDLED";
-
+
private static Timer timer = new Timer();
private Processor output;
private Processor deadLetter;
@@ -71,6 +65,7 @@
// default behavior which can be overloaded on a per exception basis
RedeliveryPolicy currentRedeliveryPolicy = redeliveryPolicy;
Processor failureProcessor = deadLetter;
+ Processor onRedeliveryProcessor = redeliveryProcessor;
}
private class RedeliverTimerTask extends TimerTask {
@@ -267,8 +262,9 @@
private void handleException(Exchange exchange, RedeliveryData data) {
Throwable e = exchange.getException();
- // set the original caused exception
- exchange.setProperty(EXCEPTION_CAUSE_PROPERTY, e);
+
+ // store the original caused exception in a property, so we can restore it later
+ exchange.setProperty(Exchange.EXCEPTION_CAUGHT, e);
// find the error handler to use (if any)
ExceptionType exceptionPolicy = getExceptionPolicy(exchange, e);
@@ -276,10 +272,17 @@
data.currentRedeliveryPolicy = exceptionPolicy.createRedeliveryPolicy(exchange.getContext(), data.currentRedeliveryPolicy);
data.handledPredicate = exceptionPolicy.getHandledPolicy();
data.retryUntilPredicate = exceptionPolicy.getRetryUntilPolicy();
+
+ // route specific failure handler?
Processor processor = exceptionPolicy.getErrorHandler();
if (processor != null) {
data.failureProcessor = processor;
}
+ // route specific on redelivey?
+ processor = exceptionPolicy.getOnRedelivery();
+ if (processor != null) {
+ data.onRedeliveryProcessor = processor;
+ }
}
String msg = "Failed delivery for exchangeId: " + exchange.getExchangeId()
@@ -295,15 +298,15 @@
*/
private void deliverToRedeliveryProcessor(final Exchange exchange, final AsyncCallback callback,
final RedeliveryData data) {
- if (redeliveryProcessor == null) {
+ if (data.onRedeliveryProcessor == null) {
return;
}
if (LOG.isTraceEnabled()) {
- LOG.trace("RedeliveryProcessor " + redeliveryProcessor + " is processing Exchange: " + exchange + " before its redelivered");
+ LOG.trace("RedeliveryProcessor " + data.onRedeliveryProcessor + " is processing Exchange: " + exchange + " before its redelivered");
}
- AsyncProcessor afp = AsyncProcessorTypeConverter.convert(redeliveryProcessor);
+ AsyncProcessor afp = AsyncProcessorTypeConverter.convert(data.onRedeliveryProcessor);
afp.process(exchange, new AsyncCallback() {
public void done(boolean sync) {
LOG.trace("Redelivery processor done");
@@ -324,6 +327,7 @@
AsyncProcessor afp = AsyncProcessorTypeConverter.convert(data.failureProcessor);
boolean sync = afp.process(exchange, new AsyncCallback() {
public void done(boolean sync) {
+ LOG.trace("Fault processor done");
restoreExceptionOnExchange(exchange, data.handledPredicate);
callback.done(data.sync);
}
@@ -340,13 +344,13 @@
// -------------------------------------------------------------------------
public static boolean isFailureHandled(Exchange exchange) {
- return exchange.getProperty(FAILURE_HANDLED_PROPERTY) != null
- || exchange.getIn().getHeader(CAUGHT_EXCEPTION_HEADER) != null;
+ Boolean handled = exchange.getProperty(Exchange.FAILURE_HANDLED, Boolean.class);
+ return handled != null && handled;
}
public static void setFailureHandled(Exchange exchange) {
- exchange.setProperty(FAILURE_HANDLED_PROPERTY, exchange.getException());
- exchange.getIn().setHeader(CAUGHT_EXCEPTION_HEADER, exchange.getException());
+ exchange.setProperty(Exchange.FAILURE_HANDLED, Boolean.TRUE);
+ // clear exception since its failure handled
exchange.setException(null);
}
@@ -398,12 +402,12 @@
LOG.debug("This exchange is not handled so its marked as failed: " + exchange);
}
// exception not handled, put exception back in the exchange
- exchange.setException(exchange.getProperty(FAILURE_HANDLED_PROPERTY, Throwable.class));
+ exchange.setException(exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class));
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("This exchange is handled so its marked as not failed: " + exchange);
}
- exchange.setProperty(Exchange.EXCEPTION_HANDLED_PROPERTY, Boolean.TRUE);
+ exchange.setProperty(Exchange.EXCEPTION_HANDLED, Boolean.TRUE);
}
}
@@ -431,13 +435,13 @@
*/
protected int incrementRedeliveryCounter(Exchange exchange, Throwable e) {
Message in = exchange.getIn();
- Integer counter = in.getHeader(REDELIVERY_COUNTER, Integer.class);
+ Integer counter = in.getHeader(Exchange.REDELIVERY_COUNTER, Integer.class);
int next = 1;
if (counter != null) {
next = counter + 1;
}
- in.setHeader(REDELIVERY_COUNTER, next);
- in.setHeader(REDELIVERED, Boolean.TRUE);
+ in.setHeader(Exchange.REDELIVERY_COUNTER, next);
+ in.setHeader(Exchange.REDELIVERED, Boolean.TRUE);
return next;
}
@@ -446,16 +450,16 @@
*/
private void decrementRedeliveryCounter(Exchange exchange) {
Message in = exchange.getIn();
- Integer counter = in.getHeader(REDELIVERY_COUNTER, Integer.class);
+ Integer counter = in.getHeader(Exchange.REDELIVERY_COUNTER, Integer.class);
if (counter != null) {
int prev = counter - 1;
- in.setHeader(REDELIVERY_COUNTER, prev);
+ in.setHeader(Exchange.REDELIVERY_COUNTER, prev);
// set boolean flag according to counter
- in.setHeader(REDELIVERED, prev > 0 ? Boolean.TRUE : Boolean.FALSE);
+ in.setHeader(Exchange.REDELIVERED, prev > 0 ? Boolean.TRUE : Boolean.FALSE);
} else {
// not redelivered
- in.setHeader(REDELIVERY_COUNTER, 0);
- in.setHeader(REDELIVERED, Boolean.FALSE);
+ in.setHeader(Exchange.REDELIVERY_COUNTER, 0);
+ in.setHeader(Exchange.REDELIVERED, Boolean.FALSE);
}
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Pipeline.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Pipeline.java?rev=746709&r1=746708&r2=746709&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Pipeline.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Pipeline.java Sun Feb 22 14:28:12 2009
@@ -64,7 +64,7 @@
while (true) {
boolean exceptionHandled = hasExceptionBeenHandled(nextExchange);
if (nextExchange.isFailed() || exceptionHandled) {
- // The Exchange.EXCEPTION_HANDLED_PROPERTY property is only set if satisfactory handling was done
+ // The Exchange.EXCEPTION_HANDLED property is only set if satisfactory handling was done
// by the error handler. It's still an exception, the exchange still failed.
if (LOG.isDebugEnabled()) {
LOG.debug("Message exchange has failed so breaking out of pipeline: " + nextExchange
@@ -126,7 +126,7 @@
boolean exceptionHandled = hasExceptionBeenHandled(nextExchange);
if (nextExchange.isFailed() || exceptionHandled) {
- // The Exchange.EXCEPTION_HANDLED_PROPERTY property is only set if satisfactory handling was done
+ // The Exchange.EXCEPTION_HANDLED property is only set if satisfactory handling was done
// by the error handler. It's still an exception, the exchange still failed.
if (LOG.isDebugEnabled()) {
LOG.debug("Message exchange has failed so breaking out of pipeline: " + nextExchange
@@ -152,7 +152,7 @@
private static boolean hasExceptionBeenHandled(Exchange nextExchange) {
- return Boolean.TRUE.equals(nextExchange.getProperty(Exchange.EXCEPTION_HANDLED_PROPERTY));
+ return Boolean.TRUE.equals(nextExchange.getProperty(Exchange.EXCEPTION_HANDLED));
}
/**
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/issues/BelasThreadErrorHandlerIssue794Test.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/BelasThreadErrorHandlerIssue794Test.java?rev=746709&r1=746708&r2=746709&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/issues/BelasThreadErrorHandlerIssue794Test.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/issues/BelasThreadErrorHandlerIssue794Test.java Sun Feb 22 14:28:12 2009
@@ -35,8 +35,8 @@
// We expect the exchange here after 1 delivery and 2 re-deliveries
MockEndpoint mock = getMockEndpoint("mock:noThread");
mock.expectedMessageCount(1);
- mock.message(0).header("org.apache.camel.Redelivered").isEqualTo(Boolean.TRUE);
- mock.message(0).header("org.apache.camel.RedeliveryCounter").isEqualTo(2);
+ mock.message(0).header("CamelRedelivered").isEqualTo(Boolean.TRUE);
+ mock.message(0).header("CamelRedeliveryCounter").isEqualTo(2);
try {
template.sendBody("direct:inNoThread", "Hello World");
@@ -56,8 +56,8 @@
// We expect the exchange here after 1 delivery and 2 re-deliveries
MockEndpoint mock = getMockEndpoint("mock:beforeThread");
mock.expectedMessageCount(1);
- mock.message(0).header("org.apache.camel.Redelivered").isEqualTo(Boolean.TRUE);
- mock.message(0).header("org.apache.camel.RedeliveryCounter").isEqualTo(2);
+ mock.message(0).header("CamelRedelivered").isEqualTo(Boolean.TRUE);
+ mock.message(0).header("CamelRedeliveryCounter").isEqualTo(2);
try {
template.sendBody("direct:inBeforeThread", "Hello World");
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/issues/ThreadErrorHandlerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/ThreadErrorHandlerTest.java?rev=746709&r1=746708&r2=746709&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/issues/ThreadErrorHandlerTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/issues/ThreadErrorHandlerTest.java Sun Feb 22 14:28:12 2009
@@ -30,8 +30,8 @@
public void testThreadErrorHandler() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
- mock.message(0).header("org.apache.camel.Redelivered").isEqualTo(Boolean.TRUE);
- mock.message(0).header("org.apache.camel.RedeliveryCounter").isEqualTo(2);
+ mock.message(0).header("CamelRedelivered").isEqualTo(Boolean.TRUE);
+ mock.message(0).header("CamelRedeliveryCounter").isEqualTo(2);
try {
template.sendBody("direct:in", "Hello World");
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/model/GenerateXmFromCamelContextlTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/model/GenerateXmFromCamelContextlTest.java?rev=746709&r1=746708&r2=746709&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/model/GenerateXmFromCamelContextlTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/model/GenerateXmFromCamelContextlTest.java Sun Feb 22 14:28:12 2009
@@ -34,7 +34,7 @@
assertEquals("Size of list " + list, 1, list.size());
RouteType routeType = list.get(0);
- System.out.println("Found route: " + routeType);
+ log.info("Found route: " + routeType);
// now lets marshall it!
dump(routeType);
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelExceptionCausePropagatedTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelExceptionCausePropagatedTest.java?rev=746709&r1=746708&r2=746709&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelExceptionCausePropagatedTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelExceptionCausePropagatedTest.java Sun Feb 22 14:28:12 2009
@@ -17,6 +17,7 @@
package org.apache.camel.processor;
import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
import org.apache.camel.builder.ProcessorBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
@@ -31,7 +32,7 @@
MockEndpoint successEndpoint = getMockEndpoint("mock:success");
failedEndpoint.expectedBodiesReceived(body);
- failedEndpoint.message(0).header(DeadLetterChannel.CAUGHT_EXCEPTION_HEADER)
+ failedEndpoint.message(0).header(Exchange.EXCEPTION_CAUGHT)
.isEqualTo(RUNTIME_EXCEPTION);
failedEndpoint.expectedMessageCount(1);
Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelOnExceptionOnRedeliveryTest.java (from r746489, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelOnRedeliveryTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelOnExceptionOnRedeliveryTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelOnExceptionOnRedeliveryTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelOnRedeliveryTest.java&r1=746489&r2=746709&rev=746709&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelOnRedeliveryTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelOnExceptionOnRedeliveryTest.java Sun Feb 22 14:28:12 2009
@@ -16,6 +16,8 @@
*/
package org.apache.camel.processor;
+import java.io.IOException;
+
import org.apache.camel.ContextTestSupport;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
@@ -23,13 +25,14 @@
import org.apache.camel.component.mock.MockEndpoint;
/**
- * Unit test for testing possibility to modify exchange before redelivering
+ * Unit test for testing possibility to modify exchange before redelivering specific
+ * per on exception
*/
-public class DeadLetterChannelOnRedeliveryTest extends ContextTestSupport {
+public class DeadLetterChannelOnExceptionOnRedeliveryTest extends ContextTestSupport {
static int counter;
- public void testOnExceptionAlterMessageBeforeRedelivery() throws Exception {
+ public void testGlobalOnRedelivery() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World123");
@@ -38,12 +41,12 @@
assertMockEndpointsSatisfied();
}
- public void xxxtestOnExceptionAlterMessageWithHeadersBeforeRedelivery() throws Exception {
+ public void testRouteSpecificOnRedelivery() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
- mock.expectedBodiesReceived("Hello World123");
- mock.expectedHeaderReceived("foo", "123");
+ mock.expectedBodiesReceived("Hello World");
+ mock.message(0).header("Timeout").isEqualTo(5000);
- template.sendBodyAndHeader("direct:start", "Hello World", "foo", "123");
+ template.sendBody("direct:io", "Hello World");
assertMockEndpointsSatisfied();
}
@@ -60,6 +63,12 @@
@Override
public void configure() throws Exception {
// START SNIPPET: e1
+ // when we redeliver caused by an IOException we want to do some special
+ // code before the redeliver attempt
+ onException(IOException.class).onRedelivery(new MyIORedeliverPrcessor());
+ // END SNIPPET: e1
+
+ // START SNIPPET: e2
// we configure our Dead Letter Channel to invoke
// MyRedeliveryProcessor before a redelivery is
// attempted. This allows us to alter the message before
@@ -67,26 +76,20 @@
.onRedelivery(new MyRedeliverPrcessor())
// setting delay to zero is just to make unit teting faster
.delay(0L));
- // END SNIPPET: e1
+ // END SNIPPET: e2
- from("direct:start").process(new Processor() {
- public void process(Exchange exchange) throws Exception {
- // force some error so Camel will do redelivery
- if (++counter <= 3) {
- throw new IllegalArgumentException("Forced by unit test");
- }
- }
- }).to("mock:result");
+ from("direct:start").process(new ThrowExceptionProcessor()).to("mock:result");
+ from("direct:io").process(new ThrowIOExceptionProcessor()).to("mock:result");
}
};
}
- // START SNIPPET: e2
+ // START SNIPPET: e3
// This is our processor that is executed before every redelivery attempt
// here we can do what we want in the java code, such as altering the message
- public class MyRedeliverPrcessor implements Processor {
+ public static class MyRedeliverPrcessor implements Processor {
public void process(Exchange exchange) throws Exception {
// the message is being redelivered so we can alter it
@@ -94,12 +97,48 @@
// we just append the redelivery counter to the body
// you can of course do all kind of stuff instead
String body = exchange.getIn().getBody(String.class);
- int count = exchange.getIn().getHeader("org.apache.camel.RedeliveryCounter", Integer.class);
+ int count = exchange.getIn().getHeader("CamelRedeliveryCounter", Integer.class);
exchange.getIn().setBody(body + count);
}
}
- // END SNIPPET: e2
+ // END SNIPPET: e3
+
+ // START SNIPPET: e4
+ // This is our processor that is executed before IOException redeliver attempt
+ // here we can do what we want in the java code, such as altering the message
+
+ public static class MyIORedeliverPrcessor implements Processor {
+
+ public void process(Exchange exchange) throws Exception {
+ // just for show and tell, here we set a special header to instruct
+ // the receive a given timeout value
+ exchange.getIn().setHeader("Timeout", 5000);
+ }
+ }
+ // END SNIPPET: e4
+
+ public static class ThrowExceptionProcessor implements Processor {
+
+ public void process(Exchange exchange) throws Exception {
+ // force some error so Camel will do redelivery
+ if (++counter <= 3) {
+ throw new IllegalArgumentException("Forced by unit test");
+ }
+
+ }
+ }
+
+ public static class ThrowIOExceptionProcessor implements Processor {
+
+ public void process(Exchange exchange) throws Exception {
+ // force some error so Camel will do redelivery
+ if (++counter <= 3) {
+ throw new IOException("Cannot connect");
+ }
+
+ }
+ }
}
\ No newline at end of file
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelOnRedeliveryTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelOnRedeliveryTest.java?rev=746709&r1=746708&r2=746709&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelOnRedeliveryTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelOnRedeliveryTest.java Sun Feb 22 14:28:12 2009
@@ -94,7 +94,7 @@
// we just append the redelivery counter to the body
// you can of course do all kind of stuff instead
String body = exchange.getIn().getBody(String.class);
- int count = exchange.getIn().getHeader("org.apache.camel.RedeliveryCounter", Integer.class);
+ int count = exchange.getIn().getHeader("CamelRedeliveryCounter", Integer.class);
exchange.getIn().setBody(body + count);
}
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelRedeliveryDelayPatternTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelRedeliveryDelayPatternTest.java?rev=746709&r1=746708&r2=746709&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelRedeliveryDelayPatternTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelRedeliveryDelayPatternTest.java Sun Feb 22 14:28:12 2009
@@ -36,8 +36,8 @@
// We expect the exchange here after 1 delivery and 2 re-deliveries
MockEndpoint mock = getMockEndpoint("mock:error");
mock.expectedMessageCount(1);
- mock.message(0).header("org.apache.camel.Redelivered").isEqualTo(Boolean.TRUE);
- mock.message(0).header("org.apache.camel.RedeliveryCounter").isEqualTo(3);
+ mock.message(0).header("CamelRedelivered").isEqualTo(Boolean.TRUE);
+ mock.message(0).header("CamelRedeliveryCounter").isEqualTo(3);
long start = System.currentTimeMillis();
try {
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelRedeliveryTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelRedeliveryTest.java?rev=746709&r1=746708&r2=746709&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelRedeliveryTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelRedeliveryTest.java Sun Feb 22 14:28:12 2009
@@ -36,8 +36,8 @@
// We expect the exchange here after 1 delivery and 2 re-deliveries
MockEndpoint mock = getMockEndpoint("mock:error");
mock.expectedMessageCount(1);
- mock.message(0).header("org.apache.camel.Redelivered").isEqualTo(Boolean.TRUE);
- mock.message(0).header("org.apache.camel.RedeliveryCounter").isEqualTo(2);
+ mock.message(0).header("CamelRedelivered").isEqualTo(Boolean.TRUE);
+ mock.message(0).header("CamelRedeliveryCounter").isEqualTo(2);
try {
template.sendBody("direct:start", "Hello World");
@@ -56,8 +56,8 @@
// We expect the exchange here after 1 delivery
MockEndpoint mock = getMockEndpoint("mock:no");
mock.expectedMessageCount(1);
- mock.message(0).header("org.apache.camel.Redelivered").isEqualTo(Boolean.FALSE);
- mock.message(0).header("org.apache.camel.RedeliveryCounter").isEqualTo(0);
+ mock.message(0).header("CamelRedelivered").isEqualTo(Boolean.FALSE);
+ mock.message(0).header("CamelRedeliveryCounter").isEqualTo(0);
try {
template.sendBody("direct:no", "Hello World");
@@ -76,8 +76,8 @@
// We expect the exchange here after 1 delivery and 1 re delivery
MockEndpoint mock = getMockEndpoint("mock:one");
mock.expectedMessageCount(1);
- mock.message(0).header("org.apache.camel.Redelivered").isEqualTo(Boolean.TRUE);
- mock.message(0).header("org.apache.camel.RedeliveryCounter").isEqualTo(1);
+ mock.message(0).header("CamelRedelivered").isEqualTo(Boolean.TRUE);
+ mock.message(0).header("CamelRedeliveryCounter").isEqualTo(1);
try {
template.sendBody("direct:one", "Hello World");
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelTest.java?rev=746709&r1=746708&r2=746709&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelTest.java Sun Feb 22 14:28:12 2009
@@ -38,8 +38,8 @@
public void testFirstFewAttemptsFail() throws Exception {
successEndpoint.expectedBodiesReceived(body);
- successEndpoint.message(0).header(DeadLetterChannel.REDELIVERED).isEqualTo(true);
- successEndpoint.message(0).header(DeadLetterChannel.REDELIVERY_COUNTER).isEqualTo(1);
+ successEndpoint.message(0).header(Exchange.REDELIVERED).isEqualTo(true);
+ successEndpoint.message(0).header(Exchange.REDELIVERY_COUNTER).isEqualTo(1);
deadEndpoint.expectedMessageCount(0);
@@ -52,15 +52,15 @@
failUntilAttempt = 5;
deadEndpoint.expectedBodiesReceived(body);
- deadEndpoint.message(0).header(DeadLetterChannel.REDELIVERED).isEqualTo(true);
- deadEndpoint.message(0).header(DeadLetterChannel.REDELIVERY_COUNTER).isEqualTo(2);
+ deadEndpoint.message(0).header(Exchange.REDELIVERED).isEqualTo(true);
+ deadEndpoint.message(0).header(Exchange.REDELIVERY_COUNTER).isEqualTo(2);
successEndpoint.expectedMessageCount(0);
sendBody("direct:start", body);
assertMockEndpointsSatisfied();
- Throwable t = deadEndpoint.getExchanges().get(0).getProperty(DeadLetterChannel.EXCEPTION_CAUSE_PROPERTY, Throwable.class);
+ Throwable t = deadEndpoint.getExchanges().get(0).getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
assertNotNull("Should have been a cause property", t);
assertTrue(t instanceof RuntimeException);
assertEquals("Failed to process due to attempt: 3 being less than: 5", t.getMessage());
@@ -80,8 +80,7 @@
protected RouteBuilder createRouteBuilder() {
final Processor processor = new AsyncProcessor() {
public void process(Exchange exchange) {
- Integer counter = exchange.getIn().getHeader(DeadLetterChannel.REDELIVERY_COUNTER,
- Integer.class);
+ Integer counter = exchange.getIn().getHeader(Exchange.REDELIVERY_COUNTER, Integer.class);
int attempt = (counter == null) ? 1 : counter + 1;
if (attempt < failUntilAttempt) {
throw new RuntimeException("Failed to process due to attempt: " + attempt
@@ -90,8 +89,7 @@
}
// START SNIPPET: AsyncProcessor
public boolean process(Exchange exchange, AsyncCallback callback) {
- Integer counter = exchange.getIn().getHeader(DeadLetterChannel.REDELIVERY_COUNTER,
- Integer.class);
+ Integer counter = exchange.getIn().getHeader(Exchange.REDELIVERY_COUNTER, Integer.class);
int attempt = (counter == null) ? 1 : counter + 1;
if (attempt > 1) {
assertEquals("Now we should use TimerThread to call the process", Thread.currentThread().getName(), "Timer-0");
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RedeliveryPolicyPerExceptionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RedeliveryPolicyPerExceptionTest.java?rev=746709&r1=746708&r2=746709&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RedeliveryPolicyPerExceptionTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RedeliveryPolicyPerExceptionTest.java Sun Feb 22 14:28:12 2009
@@ -45,8 +45,8 @@
Message in = exchange.getIn();
log.info("Found message with headers: " + in.getHeaders());
- assertMessageHeader(in, DeadLetterChannel.REDELIVERY_COUNTER, 2);
- assertMessageHeader(in, DeadLetterChannel.REDELIVERED, true);
+ assertMessageHeader(in, Exchange.REDELIVERY_COUNTER, 2);
+ assertMessageHeader(in, Exchange.REDELIVERED, true);
}
public void testUsingCustomExceptionHandlerWithNoRedeliveries() throws Exception {
@@ -62,8 +62,8 @@
Message in = exchange.getIn();
log.info("Found message with headers: " + in.getHeaders());
- assertMessageHeader(in, DeadLetterChannel.REDELIVERY_COUNTER, 0);
- assertMessageHeader(in, DeadLetterChannel.REDELIVERED, false);
+ assertMessageHeader(in, Exchange.REDELIVERY_COUNTER, 0);
+ assertMessageHeader(in, Exchange.REDELIVERED, false);
}
@Override
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/InterceptAlterMessageBeforeRedeliveryTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/InterceptAlterMessageBeforeRedeliveryTest.java?rev=746709&r1=746708&r2=746709&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/InterceptAlterMessageBeforeRedeliveryTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/InterceptAlterMessageBeforeRedeliveryTest.java Sun Feb 22 14:28:12 2009
@@ -66,7 +66,7 @@
// START SNIPPET: e1
// we configure an interceptor that is triggered when the redelivery flag
// has been set TRUE on an exchange
- intercept().when(header("org.apache.camel.Redelivered").isEqualTo(Boolean.TRUE)).
+ intercept().when(header("CamelRedelivered").isEqualTo(Boolean.TRUE)).
process(new Processor() {
public void process(Exchange exchange) throws Exception {
// the message is being redelivered so we can alter it
@@ -74,7 +74,7 @@
// we just append the redelivery counter to the body
// you can of course do all kind of stuff instead
String body = exchange.getIn().getBody(String.class);
- int count = exchange.getIn().getHeader("org.apache.camel.RedeliveryCounter", Integer.class);
+ int count = exchange.getIn().getHeader("CamelRedeliveryCounter", Integer.class);
exchange.getIn().setBody(body + count);
}
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionRetryUntilTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionRetryUntilTest.java?rev=746709&r1=746708&r2=746709&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionRetryUntilTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionRetryUntilTest.java Sun Feb 22 14:28:12 2009
@@ -72,7 +72,7 @@
public class MyRetryBean {
// using bean binding we can bind the information from the exchange to the types we have in our method signature
- public boolean retryUntil(@Header(name = DeadLetterChannel.REDELIVERY_COUNTER) Integer counter, @Body String body, @ExchangeException Exception causedBy) {
+ public boolean retryUntil(@Header(name = Exchange.REDELIVERY_COUNTER) Integer counter, @Body String body, @ExchangeException Exception causedBy) {
// NOTE: counter is the redelivery attempt, will start from 1
invoked++;
Modified: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsRedeliveryWithInitialRedeliveryDelayTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsRedeliveryWithInitialRedeliveryDelayTest.java?rev=746709&r1=746708&r2=746709&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsRedeliveryWithInitialRedeliveryDelayTest.java (original)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsRedeliveryWithInitialRedeliveryDelayTest.java Sun Feb 22 14:28:12 2009
@@ -17,6 +17,7 @@
package org.apache.camel.component.jms.issues;
import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
import org.apache.camel.component.mock.MockEndpoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
@@ -36,8 +37,8 @@
MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);
dead.expectedBodiesReceived("Hello World");
- dead.message(0).header("org.apache.camel.Redelivered").isEqualTo(true);
- dead.message(0).header("org.apache.camel.RedeliveryCounter").isEqualTo(4);
+ dead.message(0).header(Exchange.REDELIVERED).isEqualTo(true);
+ dead.message(0).header(Exchange.REDELIVERY_COUNTER).isEqualTo(4);
result.expectedMessageCount(0);
context.createProducerTemplate().sendBody("activemq:in", "Hello World");
Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionInterceptor.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionInterceptor.java?rev=746709&r1=746708&r2=746709&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionInterceptor.java (original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionInterceptor.java Sun Feb 22 14:28:12 2009
@@ -17,7 +17,6 @@
package org.apache.camel.spring.spi;
import org.apache.camel.Exchange;
-import org.apache.camel.ExchangeProperty;
import org.apache.camel.Processor;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.processor.DelayPolicy;
@@ -41,8 +40,6 @@
* @version $Revision$
*/
public class TransactionInterceptor extends DelegateProcessor {
- public static final ExchangeProperty<Boolean> TRANSACTED =
- new ExchangeProperty<Boolean>("transacted", "org.apache.camel.transacted", Boolean.class);
private static final transient Log LOG = LogFactory.getLog(TransactionInterceptor.class);
private final TransactionTemplate transactionTemplate;
private RedeliveryPolicy redeliveryPolicy;
@@ -85,8 +82,7 @@
activeTx = status.isNewTransaction() && !status.isCompleted();
if (!activeTx) {
if (DefaultTransactionStatus.class.isAssignableFrom(status.getClass())) {
- DefaultTransactionStatus defStatus =
- DefaultTransactionStatus.class.cast(status);
+ DefaultTransactionStatus defStatus = DefaultTransactionStatus.class.cast(status);
activeTx = defStatus.hasTransaction() && !status.isCompleted();
}
}
@@ -98,7 +94,7 @@
// okay mark the exchange as transacted, then the DeadLetterChannel or others know
// its a transacted exchange
if (activeTx) {
- TRANSACTED.set(exchange, Boolean.TRUE);
+ exchange.setProperty(Exchange.TRANSACTED, Boolean.TRUE);
}
// process the exchange
Modified: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/DeadLetterChannelRedeliveryConfigTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/DeadLetterChannelRedeliveryConfigTest.java?rev=746709&r1=746708&r2=746709&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/DeadLetterChannelRedeliveryConfigTest.java (original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/DeadLetterChannelRedeliveryConfigTest.java Sun Feb 22 14:28:12 2009
@@ -17,6 +17,7 @@
package org.apache.camel.spring.config;
import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.springframework.beans.factory.annotation.Autowired;
@@ -40,8 +41,8 @@
MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);
dead.expectedBodiesReceived("Hello World");
- dead.message(0).header("org.apache.camel.Redelivered").isEqualTo(true);
- dead.message(0).header("org.apache.camel.RedeliveryCounter").isEqualTo(3);
+ dead.message(0).header(Exchange.REDELIVERED).isEqualTo(Boolean.TRUE);
+ dead.message(0).header(Exchange.REDELIVERY_COUNTER).isEqualTo(3);
result.expectedMessageCount(0);
try {
Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/SpringDeadLetterChannelOnExceptionOnRedeliveryTest.java (from r746448, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/RedeliveryPolicyReTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/SpringDeadLetterChannelOnExceptionOnRedeliveryTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/SpringDeadLetterChannelOnExceptionOnRedeliveryTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/RedeliveryPolicyReTest.java&r1=746448&r2=746709&rev=746709&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/RedeliveryPolicyReTest.java (original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/SpringDeadLetterChannelOnExceptionOnRedeliveryTest.java Sun Feb 22 14:28:12 2009
@@ -17,16 +17,16 @@
package org.apache.camel.spring.processor.onexception;
import org.apache.camel.CamelContext;
-
+import org.apache.camel.processor.DeadLetterChannelOnExceptionOnRedeliveryTest;
import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
/**
- * Unit test for onException with the spring DSL.
+ * Unit test for per on exception specificy on redelivery.
*/
-public class RedeliveryPolicyReTest extends DeadLetterChannelHandledExampleTest {
+public class SpringDeadLetterChannelOnExceptionOnRedeliveryTest extends DeadLetterChannelOnExceptionOnRedeliveryTest {
protected CamelContext createCamelContext() throws Exception {
return createSpringCamelContext(this,
- "/org/apache/camel/spring/processor/onexception/RedeliveryPolicyRefTest.xml");
+ "/org/apache/camel/spring/processor/onexception/DeadLetterChannelOnExceptionOnRedeliveryTest.xml");
}
}
\ No newline at end of file
Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/DeadLetterChannelOnExceptionOnRedeliveryTest.xml (from r746448, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/RedeliveryPolicyRefTest.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/DeadLetterChannelOnExceptionOnRedeliveryTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/DeadLetterChannelOnExceptionOnRedeliveryTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/RedeliveryPolicyRefTest.xml&r1=746448&r2=746709&rev=746709&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/RedeliveryPolicyRefTest.xml (original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/DeadLetterChannelOnExceptionOnRedeliveryTest.xml Sun Feb 22 14:28:12 2009
@@ -22,44 +22,49 @@
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">
- <!-- START SNIPPET: e1 -->
- <!-- here we define our redelivery policy using standard spring style -->
- <bean id="myRedeliveryPolicy" class="org.apache.camel.processor.RedeliveryPolicy">
- <property name="maximumRedeliveries" value="1" />
+ <bean id="deadLetterErrorHandler" class="org.apache.camel.builder.DeadLetterChannelBuilder">
+ <property name="defaultDeadLetterEndpointUri" value="mock:error"/>
+ <property name="onRedelivery" ref="myRedeliveryProcessor"/>
+ <property name="redeliveryPolicy" ref="redeliveryPolicy"/>
</bean>
+ <bean id="redeliveryPolicy" class="org.apache.camel.processor.RedeliveryPolicy">
+ <!-- go fast since its a unit test -->
+ <property name="delay" value="0"/>
+ </bean>
+
+
+ <bean id="myRedeliveryProcessor"
+ class="org.apache.camel.processor.DeadLetterChannelOnExceptionOnRedeliveryTest$MyRedeliverPrcessor"/>
+
+ <bean id="myIORedeliverProcessor"
+ class="org.apache.camel.processor.DeadLetterChannelOnExceptionOnRedeliveryTest$MyIORedeliverPrcessor"/>
+
+ <bean id="throwExceptionProcessor"
+ class="org.apache.camel.processor.DeadLetterChannelOnExceptionOnRedeliveryTest$ThrowExceptionProcessor"/>
+
+ <bean id="throwIOExceptionProcessor"
+ class="org.apache.camel.processor.DeadLetterChannelOnExceptionOnRedeliveryTest$ThrowIOExceptionProcessor"/>
- <!-- this is our POJO bean with our business logic defined as a plain spring bean -->
- <bean id="orderService" class="org.apache.camel.spring.processor.onexception.OrderService" />
<!-- this is the camel context where we define the routes -->
- <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <camelContext xmlns="http://camel.apache.org/schema/spring" errorHandlerRef="deadLetterErrorHandler">
- <onException>
- <!-- the exception is full qualified names as plain strings -->
- <!-- there can be more just add a 2nd, 3rd exception element (unbounded) -->
- <exception>org.apache.camel.spring.processor.onexception.OrderFailedException</exception>
- <exception>java.lang.IllegalArgumentException</exception>
- <!-- here we reference our redelivy policy -->
- <redeliveryPolicy ref="myRedeliveryPolicy" />
- <!-- mark this as handled -->
- <handled>
- <constant>true</constant>
- </handled>
- <!-- let our order service handle this exception, call the orderFailed method -->
- <bean ref="orderService" method="orderFailed" />
- <!-- and since this is a unit test we use mock for assertions -->
- <to uri="mock:error" />
- </onException>
-
- <route>
- <!-- the route -->
- <from uri="direct:start" />
- <!-- in the normal route then route to our order service and call handleOrder method -->
- <bean ref="orderService" method="handleOrder" />
- <!-- and since this is a unit test we use mock for assertions -->
- <to uri="mock:result" />
- </route>
+ <onException onRedeliveryRef="myIORedeliverProcessor">
+ <exception>java.io.IOException</exception>
+ </onException>
+
+ <route>
+ <from uri="direct:start"/>
+ <process ref="throwExceptionProcessor"/>
+ <to uri="mock:result"/>
+ </route>
+
+ <route>
+ <from uri="direct:io"/>
+ <process ref="throwIOExceptionProcessor"/>
+ <to uri="mock:result"/>
+ </route>
</camelContext>
<!-- END SNIPPET: e1 -->