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 2019/07/26 12:36:02 UTC
[camel] 02/04: CAMEL-13175: Added useOriginalBody as alternative to
useOriginalMessage and correct docs.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 1e9b9dc228cfcaf60b5026eb1d87f05688954512
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Jul 26 13:18:43 2019 +0200
CAMEL-13175: Added useOriginalBody as alternative to useOriginalMessage and correct docs.
---
.../blueprint/CamelErrorHandlerFactoryBean.java | 5 ++
.../transaction/JtaTransactionErrorHandler.java | 1 +
.../camel/spring/ErrorHandlerDefinition.java | 61 +++++++++++++++++++---
.../handler/ErrorHandlerDefinitionParser.java | 5 ++
.../camel/spring/spi/TransactionErrorHandler.java | 2 +-
.../processor/errorhandler/DeadLetterChannel.java | 7 +--
.../errorhandler/DefaultErrorHandler.java | 2 +-
.../processor/errorhandler/ExceptionPolicy.java | 10 +++-
.../errorhandler/RedeliveryErrorHandler.java | 26 ++++++---
.../camel/builder/DeadLetterChannelBuilder.java | 2 +-
.../camel/builder/DefaultErrorHandlerBuilder.java | 52 +++++++++++++++++-
.../camel/builder/ErrorHandlerBuilderSupport.java | 6 ++-
.../apache/camel/model/OnExceptionDefinition.java | 59 ++++++++++++++++++++-
.../errorhandler/DeadLetterChannelReifier.java | 2 +-
.../reifier/errorhandler/ErrorHandlerReifier.java | 3 +-
...BodyAndEnrichedHeadersUseOriginalBodyTest.java} | 7 +--
.../management/mbean/ManagedErrorHandlerMBean.java | 3 ++
.../management/mbean/ManagedErrorHandler.java | 9 ++++
18 files changed, 232 insertions(+), 30 deletions(-)
diff --git a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelErrorHandlerFactoryBean.java b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelErrorHandlerFactoryBean.java
index 38199df..6db7ce5 100644
--- a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelErrorHandlerFactoryBean.java
+++ b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelErrorHandlerFactoryBean.java
@@ -47,6 +47,8 @@ public class CamelErrorHandlerFactoryBean extends AbstractCamelFactoryBean<Error
@XmlAttribute
private Boolean useOriginalMessage;
@XmlAttribute
+ private Boolean useOriginalBody;
+ @XmlAttribute
private String onRedeliveryRef;
@XmlAttribute
private String onPrepareFailureRef;
@@ -77,6 +79,9 @@ public class CamelErrorHandlerFactoryBean extends AbstractCamelFactoryBean<Error
if (useOriginalMessage != null) {
handler.setUseOriginalMessage(useOriginalMessage);
}
+ if (useOriginalBody != null) {
+ handler.setUseOriginalBody(useOriginalBody);
+ }
if (redeliveryPolicy != null) {
handler.setRedeliveryPolicy(ErrorHandlerReifier.createRedeliveryPolicy(redeliveryPolicy, getCamelContext(), null));
}
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/transaction/JtaTransactionErrorHandler.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/transaction/JtaTransactionErrorHandler.java
index 4169c21..5d8652d 100644
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/transaction/JtaTransactionErrorHandler.java
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/transaction/JtaTransactionErrorHandler.java
@@ -55,6 +55,7 @@ public class JtaTransactionErrorHandler extends RedeliveryErrorHandler {
null,
false,
false,
+ false,
retryWhile,
executorService,
null,
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/ErrorHandlerDefinition.java b/components/camel-spring/src/main/java/org/apache/camel/spring/ErrorHandlerDefinition.java
index d74ed72..b8bc7f7 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/ErrorHandlerDefinition.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/ErrorHandlerDefinition.java
@@ -49,6 +49,8 @@ public class ErrorHandlerDefinition extends IdentifiedType {
@XmlAttribute
private Boolean useOriginalMessage;
@XmlAttribute
+ private Boolean useOriginalBody;
+ @XmlAttribute
private String transactionTemplateRef;
@XmlAttribute
private String transactionManagerRef;
@@ -148,22 +150,69 @@ public class ErrorHandlerDefinition extends IdentifiedType {
}
/**
- * Will use the original input message when an {@link org.apache.camel.Exchange} is moved to the dead letter queue.
+ * Will use the original input {@link org.apache.camel.Message} (original body and headers) when an {@link org.apache.camel.Exchange}
+ * is moved to the dead letter queue.
* <p/>
- * <b>Notice:</b> this only applies when all redeliveries attempt have failed and the {@link org.apache.camel.Exchange} is doomed for failure.
+ * <b>Notice:</b> this only applies when all redeliveries attempt have failed and the {@link org.apache.camel.Exchange}
+ * is doomed for failure.
* <br/>
- * Instead of using the current inprogress {@link org.apache.camel.Exchange} IN body we use the original IN body instead. This allows
- * you to store the original input in the dead letter queue instead of the inprogress snapshot of the IN body.
+ * Instead of using the current inprogress {@link org.apache.camel.Exchange} IN message we use the original
+ * IN message instead. This allows you to store the original input in the dead letter queue instead of the inprogress
+ * snapshot of the IN message.
* For instance if you route transform the IN body during routing and then failed. With the original exchange
- * store in the dead letter queue it might be easier to manually re submit the {@link org.apache.camel.Exchange} again as the IN body
- * is the same as when Camel received it. So you should be able to send the {@link org.apache.camel.Exchange} to the same input.
+ * store in the dead letter queue it might be easier to manually re submit the {@link org.apache.camel.Exchange}
+ * again as the IN message is the same as when Camel received it.
+ * So you should be able to send the {@link org.apache.camel.Exchange} to the same input.
+ * <p/>
+ * The difference between useOriginalMessage and useOriginalBody is that the former includes both the original
+ * body and headers, where as the latter only includes the original body. You can use the latter to enrich
+ * the message with custom headers and include the original message body. The former wont let you do this, as its
+ * using the original message body and headers as they are.
+ * <p/>
+ * You cannot enable both useOriginalMessage and useOriginalBody.
* <p/>
* By default this feature is off.
+ *
+ * @see #setUseOriginalBody(Boolean)
*/
public void setUseOriginalMessage(Boolean useOriginalMessage) {
this.useOriginalMessage = useOriginalMessage;
}
+ public Boolean getUseOriginalBody() {
+ return useOriginalBody;
+ }
+
+ /**
+ * Will use the original input {@link org.apache.camel.Message} body (original body only) when an {@link org.apache.camel.Exchange}
+ * is moved to the dead letter queue.
+ * <p/>
+ * <b>Notice:</b> this only applies when all redeliveries attempt have failed and the {@link org.apache.camel.Exchange}
+ * is doomed for failure.
+ * <br/>
+ * Instead of using the current inprogress {@link org.apache.camel.Exchange} IN message we use the original
+ * IN message instead. This allows you to store the original input in the dead letter queue instead of the inprogress
+ * snapshot of the IN message.
+ * For instance if you route transform the IN body during routing and then failed. With the original exchange
+ * store in the dead letter queue it might be easier to manually re submit the {@link org.apache.camel.Exchange}
+ * again as the IN message is the same as when Camel received it.
+ * So you should be able to send the {@link org.apache.camel.Exchange} to the same input.
+ * <p/>
+ * The difference between useOriginalMessage and useOriginalBody is that the former includes both the original
+ * body and headers, where as the latter only includes the original body. You can use the latter to enrich
+ * the message with custom headers and include the original message body. The former wont let you do this, as its
+ * using the original message body and headers as they are.
+ * <p/>
+ * You cannot enable both useOriginalMessage and useOriginalBody.
+ * <p/>
+ * By default this feature is off.
+ *
+ * @see #setUseOriginalMessage(Boolean)
+ */
+ public void setUseOriginalBody(Boolean useOriginalBody) {
+ this.useOriginalBody = useOriginalBody;
+ }
+
public String getTransactionTemplateRef() {
return transactionTemplateRef;
}
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.java b/components/camel-spring/src/main/java/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.java
index 8ae4a0e..ee3a18f 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/handler/ErrorHandlerDefinitionParser.java
@@ -145,6 +145,11 @@ public class ErrorHandlerDefinitionParser extends BeanDefinitionParser {
throw new IllegalArgumentException("Attribute useOriginalMessage is not supported by error handler type: "
+ type.name() + ", in error handler with id: " + id);
}
+ String useOriginalBody = element.getAttribute("useOriginalBody");
+ if (ObjectHelper.isNotEmpty(useOriginalBody) && type.equals(ErrorHandlerType.NoErrorHandler)) {
+ throw new IllegalArgumentException("Attribute useOriginalBody is not supported by error handler type: "
+ + type.name() + ", in error handler with id: " + id);
+ }
String onRedeliveryRef = element.getAttribute("onRedeliveryRef");
if (ObjectHelper.isNotEmpty(onRedeliveryRef) && type.equals(ErrorHandlerType.NoErrorHandler)) {
throw new IllegalArgumentException("Attribute onRedeliveryRef is not supported by error handler type: "
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java b/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java
index 102d8eb..ff92ca6 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java
@@ -67,7 +67,7 @@ public class TransactionErrorHandler extends RedeliveryErrorHandler {
TransactionTemplate transactionTemplate, Predicate retryWhile, ScheduledExecutorService executorService,
LoggingLevel rollbackLoggingLevel, Processor onExceptionOccurredProcessor) {
- super(camelContext, output, logger, redeliveryProcessor, redeliveryPolicy, null, null, false, false, retryWhile,
+ super(camelContext, output, logger, redeliveryProcessor, redeliveryPolicy, null, null, false, false, false, retryWhile,
executorService, null, onExceptionOccurredProcessor);
setExceptionPolicy(exceptionPolicyStrategy);
this.transactionTemplate = transactionTemplate;
diff --git a/core/camel-base/src/main/java/org/apache/camel/processor/errorhandler/DeadLetterChannel.java b/core/camel-base/src/main/java/org/apache/camel/processor/errorhandler/DeadLetterChannel.java
index d7b9f00..ba12cb4 100644
--- a/core/camel-base/src/main/java/org/apache/camel/processor/errorhandler/DeadLetterChannel.java
+++ b/core/camel-base/src/main/java/org/apache/camel/processor/errorhandler/DeadLetterChannel.java
@@ -43,7 +43,8 @@ public class DeadLetterChannel extends RedeliveryErrorHandler {
* @param deadLetter the failure processor to send failed exchanges to
* @param deadLetterUri an optional uri for logging purpose
* @param deadLetterHandleException whether dead letter channel should handle (and ignore) exceptions which may be thrown during sending the message to the dead letter endpoint
- * @param useOriginalBodyPolicy should the original IN body be moved to the dead letter queue or the current exchange IN body?
+ * @param useOriginalMessagePolicy should the original IN message be moved to the dead letter queue or the current exchange IN message?
+ * @param useOriginalBodyPolicy should the original IN message body be moved to the dead letter queue or the current exchange IN message body?
* @param retryWhile retry while
* @param executorService the {@link java.util.concurrent.ScheduledExecutorService} to be used for redelivery thread pool. Can be <tt>null</tt>.
* @param onPrepareProcessor a custom {@link org.apache.camel.Processor} to prepare the {@link org.apache.camel.Exchange} before
@@ -52,10 +53,10 @@ public class DeadLetterChannel extends RedeliveryErrorHandler {
*/
public DeadLetterChannel(CamelContext camelContext, Processor output, CamelLogger logger, Processor redeliveryProcessor, RedeliveryPolicy redeliveryPolicy,
ExceptionPolicyStrategy exceptionPolicyStrategy, Processor deadLetter, String deadLetterUri, boolean deadLetterHandleException,
- boolean useOriginalBodyPolicy, Predicate retryWhile, ScheduledExecutorService executorService, Processor onPrepareProcessor, Processor onExceptionOccurredProcessor) {
+ boolean useOriginalMessagePolicy, boolean useOriginalBodyPolicy, Predicate retryWhile, ScheduledExecutorService executorService, Processor onPrepareProcessor, Processor onExceptionOccurredProcessor) {
super(camelContext, output, logger, redeliveryProcessor, redeliveryPolicy, deadLetter, deadLetterUri, deadLetterHandleException,
- useOriginalBodyPolicy, retryWhile, executorService, onPrepareProcessor, onExceptionOccurredProcessor);
+ useOriginalMessagePolicy, useOriginalBodyPolicy, retryWhile, executorService, onPrepareProcessor, onExceptionOccurredProcessor);
setExceptionPolicy(exceptionPolicyStrategy);
}
diff --git a/core/camel-base/src/main/java/org/apache/camel/processor/errorhandler/DefaultErrorHandler.java b/core/camel-base/src/main/java/org/apache/camel/processor/errorhandler/DefaultErrorHandler.java
index d7b3f51..d6df5e2 100644
--- a/core/camel-base/src/main/java/org/apache/camel/processor/errorhandler/DefaultErrorHandler.java
+++ b/core/camel-base/src/main/java/org/apache/camel/processor/errorhandler/DefaultErrorHandler.java
@@ -47,7 +47,7 @@ public class DefaultErrorHandler extends RedeliveryErrorHandler {
RedeliveryPolicy redeliveryPolicy, ExceptionPolicyStrategy exceptionPolicyStrategy, Predicate retryWhile,
ScheduledExecutorService executorService, Processor onPrepareProcessor, Processor onExceptionOccurredProcessor) {
- super(camelContext, output, logger, redeliveryProcessor, redeliveryPolicy, null, null, true, false, retryWhile, executorService, onPrepareProcessor, onExceptionOccurredProcessor);
+ super(camelContext, output, logger, redeliveryProcessor, redeliveryPolicy, null, null, true, false, false, retryWhile, executorService, onPrepareProcessor, onExceptionOccurredProcessor);
setExceptionPolicy(exceptionPolicyStrategy);
}
diff --git a/core/camel-base/src/main/java/org/apache/camel/processor/errorhandler/ExceptionPolicy.java b/core/camel-base/src/main/java/org/apache/camel/processor/errorhandler/ExceptionPolicy.java
index 84766cc..6a8d4de 100644
--- a/core/camel-base/src/main/java/org/apache/camel/processor/errorhandler/ExceptionPolicy.java
+++ b/core/camel-base/src/main/java/org/apache/camel/processor/errorhandler/ExceptionPolicy.java
@@ -32,6 +32,7 @@ public class ExceptionPolicy {
private String id;
private String routeId;
private boolean useOriginalInMessage;
+ private boolean useOriginalInBody;
private boolean hasOutputs;
private Predicate handledPolicy;
@@ -43,13 +44,14 @@ public class ExceptionPolicy {
private Map<RedeliveryOption, String> redeliveryPolicy;
private List<String> exceptions;
- public ExceptionPolicy(String id, String routeId, boolean useOriginalInMessage,
+ public ExceptionPolicy(String id, String routeId, boolean useOriginalInMessage, boolean useOriginalInBody,
boolean hasOutputs, Predicate handledPolicy, Predicate continuedPolicy,
Predicate retryWhilePolicy, Processor onRedelivery, Processor onExceptionOccurred,
String redeliveryPolicyRef, Map<RedeliveryOption, String> redeliveryPolicy, List<String> exceptions) {
this.id = id;
this.routeId = routeId;
this.useOriginalInMessage = useOriginalInMessage;
+ this.useOriginalInBody = useOriginalInBody;
this.hasOutputs = hasOutputs;
this.handledPolicy = handledPolicy;
this.continuedPolicy = continuedPolicy;
@@ -69,10 +71,14 @@ public class ExceptionPolicy {
return routeId;
}
- public boolean getUseOriginalInMessage() {
+ public boolean isUseOriginalInMessage() {
return useOriginalInMessage;
}
+ public boolean isUseOriginalInBody() {
+ return useOriginalInBody;
+ }
+
public List<String> getExceptions() {
return exceptions;
}
diff --git a/core/camel-base/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java b/core/camel-base/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java
index 2628c67..ec43a0a 100644
--- a/core/camel-base/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java
+++ b/core/camel-base/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java
@@ -77,6 +77,7 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport impleme
protected final Predicate retryWhilePolicy;
protected final CamelLogger logger;
protected final boolean useOriginalMessagePolicy;
+ protected final boolean useOriginalBodyPolicy;
protected boolean redeliveryEnabled;
protected volatile boolean preparingShutdown;
protected final ExchangeFormatter exchangeFormatter;
@@ -86,7 +87,7 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport impleme
public RedeliveryErrorHandler(CamelContext camelContext, Processor output, CamelLogger logger,
Processor redeliveryProcessor, RedeliveryPolicy redeliveryPolicy, Processor deadLetter,
- String deadLetterUri, boolean deadLetterHandleNewException, boolean useOriginalMessagePolicy,
+ String deadLetterUri, boolean deadLetterHandleNewException, boolean useOriginalMessagePolicy, boolean useOriginalBodyPolicy,
Predicate retryWhile, ScheduledExecutorService executorService, Processor onPrepareProcessor, Processor onExceptionProcessor) {
ObjectHelper.notNull(camelContext, "CamelContext", this);
@@ -103,6 +104,7 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport impleme
this.deadLetterUri = deadLetterUri;
this.deadLetterHandleNewException = deadLetterHandleNewException;
this.useOriginalMessagePolicy = useOriginalMessagePolicy;
+ this.useOriginalBodyPolicy = useOriginalBodyPolicy;
this.retryWhilePolicy = retryWhile;
this.executorService = executorService;
this.onPrepareProcessor = onPrepareProcessor;
@@ -315,6 +317,10 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport impleme
return useOriginalMessagePolicy;
}
+ public boolean isUseOriginalBodyPolicy() {
+ return useOriginalBodyPolicy;
+ }
+
public boolean isDeadLetterHandleNewException() {
return deadLetterHandleNewException;
}
@@ -353,6 +359,7 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport impleme
Predicate handledPredicate;
Predicate continuedPredicate;
boolean useOriginalInMessage;
+ boolean useOriginalInBody;
public RedeliveryState(Exchange exchange, AsyncCallback callback) {
// init with values from the error handler
@@ -360,6 +367,7 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport impleme
this.currentRedeliveryPolicy = redeliveryPolicy;
this.handledPredicate = getDefaultHandledPredicate();
this.useOriginalInMessage = useOriginalMessagePolicy;
+ this.useOriginalInBody = useOriginalBodyPolicy;
this.onRedeliveryProcessor = redeliveryProcessor;
this.onExceptionProcessor = RedeliveryErrorHandler.this.onExceptionProcessor;
@@ -667,7 +675,8 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport impleme
handledPredicate = exceptionPolicy.getHandledPolicy();
continuedPredicate = exceptionPolicy.getContinuedPolicy();
retryWhilePredicate = exceptionPolicy.getRetryWhilePolicy();
- useOriginalInMessage = exceptionPolicy.getUseOriginalInMessage();
+ useOriginalInMessage = exceptionPolicy.isUseOriginalInMessage();
+ useOriginalInBody = exceptionPolicy.isUseOriginalInBody();
// route specific failure handler?
Processor processor = null;
@@ -794,11 +803,16 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport impleme
if (allowFailureProcessor && processor != null) {
- // prepare original IN body if it should be moved instead of current body
- if (useOriginalInMessage) {
- log.trace("Using the original IN message instead of current");
+ // prepare original IN message/body if it should be moved instead of current message/body
+ if (useOriginalInMessage || useOriginalInBody) {
Message original = ExchangeHelper.getOriginalInMessage(exchange);
- exchange.setIn(original);
+ if (useOriginalInMessage) {
+ log.trace("Using the original IN message instead of current");
+ exchange.setIn(original);
+ } else {
+ log.trace("Using the original IN message body instead of current");
+ exchange.getIn().setBody(original.getBody());
+ }
if (exchange.hasOut()) {
log.trace("Removing the out message to avoid some uncertain behavior");
exchange.setOut(null);
diff --git a/core/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java b/core/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java
index a9907e7..3ce8c95 100644
--- a/core/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java
+++ b/core/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java
@@ -55,7 +55,7 @@ public class DeadLetterChannelBuilder extends DefaultErrorHandlerBuilder {
DeadLetterChannel answer = new DeadLetterChannel(routeContext.getCamelContext(), processor, getLogger(), getOnRedelivery(),
getRedeliveryPolicy(), getExceptionPolicyStrategy(), getFailureProcessor(), getDeadLetterUri(), isDeadLetterHandleNewException(),
- isUseOriginalMessage(), getRetryWhilePolicy(routeContext.getCamelContext()), getExecutorService(routeContext.getCamelContext()),
+ isUseOriginalMessage(), isUseOriginalBody(), getRetryWhilePolicy(routeContext.getCamelContext()), getExecutorService(routeContext.getCamelContext()),
getOnPrepareFailure(), getOnExceptionOccurred());
// configure error handler before we can use it
configure(routeContext, answer);
diff --git a/core/camel-core/src/main/java/org/apache/camel/builder/DefaultErrorHandlerBuilder.java b/core/camel-core/src/main/java/org/apache/camel/builder/DefaultErrorHandlerBuilder.java
index 768f63c..3e03652 100644
--- a/core/camel-core/src/main/java/org/apache/camel/builder/DefaultErrorHandlerBuilder.java
+++ b/core/camel-core/src/main/java/org/apache/camel/builder/DefaultErrorHandlerBuilder.java
@@ -49,6 +49,7 @@ public class DefaultErrorHandlerBuilder extends ErrorHandlerBuilderSupport {
protected String deadLetterUri;
protected boolean deadLetterHandleNewException = true;
protected boolean useOriginalMessage;
+ protected boolean useOriginalBody;
protected boolean asyncDelayedRedelivery;
protected String executorServiceRef;
protected ScheduledExecutorService executorService;
@@ -113,6 +114,7 @@ public class DefaultErrorHandlerBuilder extends ErrorHandlerBuilderSupport {
}
other.setDeadLetterHandleNewException(deadLetterHandleNewException);
other.setUseOriginalMessage(useOriginalMessage);
+ other.setUseOriginalBody(useOriginalBody);
other.setAsyncDelayedRedelivery(asyncDelayedRedelivery);
other.setExecutorServiceRef(executorServiceRef);
}
@@ -338,7 +340,7 @@ public class DefaultErrorHandlerBuilder extends ErrorHandlerBuilderSupport {
}
/**
- * Will use the original input {@link org.apache.camel.Message} when an {@link org.apache.camel.Exchange}
+ * Will use the original input {@link org.apache.camel.Message} (original body and headers) when an {@link org.apache.camel.Exchange}
* is moved to the dead letter queue.
* <p/>
* <b>Notice:</b> this only applies when all redeliveries attempt have failed and the {@link org.apache.camel.Exchange}
@@ -352,9 +354,17 @@ public class DefaultErrorHandlerBuilder extends ErrorHandlerBuilderSupport {
* again as the IN message is the same as when Camel received it.
* So you should be able to send the {@link org.apache.camel.Exchange} to the same input.
* <p/>
+ * The difference between useOriginalMessage and useOriginalBody is that the former includes both the original
+ * body and headers, where as the latter only includes the original body. You can use the latter to enrich
+ * the message with custom headers and include the original message body. The former wont let you do this, as its
+ * using the original message body and headers as they are.
+ * <p/>
+ * You cannot enable both useOriginalMessage and useOriginalBody.
+ * <p/>
* By default this feature is off.
*
* @return the builder
+ * @see #useOriginalBody()
*/
public DefaultErrorHandlerBuilder useOriginalMessage() {
setUseOriginalMessage(true);
@@ -362,6 +372,38 @@ public class DefaultErrorHandlerBuilder extends ErrorHandlerBuilderSupport {
}
/**
+ * Will use the original input {@link org.apache.camel.Message} body (original body only) when an {@link org.apache.camel.Exchange}
+ * is moved to the dead letter queue.
+ * <p/>
+ * <b>Notice:</b> this only applies when all redeliveries attempt have failed and the {@link org.apache.camel.Exchange}
+ * is doomed for failure.
+ * <br/>
+ * Instead of using the current inprogress {@link org.apache.camel.Exchange} IN message we use the original
+ * IN message instead. This allows you to store the original input in the dead letter queue instead of the inprogress
+ * snapshot of the IN message.
+ * For instance if you route transform the IN body during routing and then failed. With the original exchange
+ * store in the dead letter queue it might be easier to manually re submit the {@link org.apache.camel.Exchange}
+ * again as the IN message is the same as when Camel received it.
+ * So you should be able to send the {@link org.apache.camel.Exchange} to the same input.
+ * <p/>
+ * The difference between useOriginalMessage and useOriginalBody is that the former includes both the original
+ * body and headers, where as the latter only includes the original body. You can use the latter to enrich
+ * the message with custom headers and include the original message body. The former wont let you do this, as its
+ * using the original message body and headers as they are.
+ * <p/>
+ * You cannot enable both useOriginalMessage and useOriginalBody.
+ * <p/>
+ * By default this feature is off.
+ *
+ * @return the builder
+ * @see #useOriginalMessage()
+ */
+ public DefaultErrorHandlerBuilder useOriginalBody() {
+ setUseOriginalBody(true);
+ return this;
+ }
+
+ /**
* Whether the dead letter channel should handle (and ignore) any new exception that may been thrown during sending the
* message to the dead letter endpoint.
* <p/>
@@ -513,6 +555,14 @@ public class DefaultErrorHandlerBuilder extends ErrorHandlerBuilderSupport {
this.useOriginalMessage = useOriginalMessage;
}
+ public boolean isUseOriginalBody() {
+ return useOriginalBody;
+ }
+
+ public void setUseOriginalBody(boolean useOriginalBody) {
+ this.useOriginalBody = useOriginalBody;
+ }
+
public boolean isAsyncDelayedRedelivery() {
return asyncDelayedRedelivery;
}
diff --git a/core/camel-core/src/main/java/org/apache/camel/builder/ErrorHandlerBuilderSupport.java b/core/camel-core/src/main/java/org/apache/camel/builder/ErrorHandlerBuilderSupport.java
index 81e86e7..2d7090c 100644
--- a/core/camel-core/src/main/java/org/apache/camel/builder/ErrorHandlerBuilderSupport.java
+++ b/core/camel-core/src/main/java/org/apache/camel/builder/ErrorHandlerBuilderSupport.java
@@ -64,8 +64,12 @@ public abstract class ErrorHandlerBuilderSupport implements ErrorHandlerBuilder
}
}
if (handler instanceof RedeliveryErrorHandler) {
- boolean original = ((RedeliveryErrorHandler) handler).isUseOriginalMessagePolicy();
+ RedeliveryErrorHandler reh = (RedeliveryErrorHandler) handler;
+ boolean original = reh.isUseOriginalMessagePolicy() || reh.isUseOriginalBodyPolicy();;
if (original) {
+ if (reh.isUseOriginalMessagePolicy() && reh.isUseOriginalBodyPolicy()) {
+ throw new IllegalArgumentException("Cannot set both useOriginalMessage and useOriginalBody on the error handler");
+ }
// ensure allow original is turned on
routeContext.setAllowUseOriginalMessage(true);
}
diff --git a/core/camel-core/src/main/java/org/apache/camel/model/OnExceptionDefinition.java b/core/camel-core/src/main/java/org/apache/camel/model/OnExceptionDefinition.java
index b887b44..b392ece 100644
--- a/core/camel-core/src/main/java/org/apache/camel/model/OnExceptionDefinition.java
+++ b/core/camel-core/src/main/java/org/apache/camel/model/OnExceptionDefinition.java
@@ -66,6 +66,8 @@ public class OnExceptionDefinition extends ProcessorDefinition<OnExceptionDefini
private String onExceptionOccurredRef;
@XmlAttribute(name = "useOriginalMessage")
private Boolean useOriginalMessagePolicy;
+ @XmlAttribute(name = "useOriginalBody")
+ private Boolean useOriginalBodyPolicy;
@XmlElementRef
private List<ProcessorDefinition<?>> outputs = new ArrayList<>();
@XmlTransient
@@ -148,6 +150,12 @@ public class OnExceptionDefinition extends ProcessorDefinition<OnExceptionDefini
throw new IllegalArgumentException("Only one of handled or continued is allowed to be configured on: " + this);
}
+ // you cannot turn on both of them
+ if (useOriginalMessagePolicy != null && useOriginalMessagePolicy
+ && useOriginalBodyPolicy != null && useOriginalBodyPolicy) {
+ throw new IllegalArgumentException("Cannot set both useOriginalMessage and useOriginalBody on: " + this);
+ }
+
// validate that at least some option is set as you cannot just have onException(Exception.class);
if (outputs == null || getOutputs().isEmpty()) {
// no outputs so there should be some sort of configuration
@@ -157,6 +165,7 @@ public class OnExceptionDefinition extends ProcessorDefinition<OnExceptionDefini
retryWhilePolicy,
redeliveryPolicyType,
useOriginalMessagePolicy,
+ useOriginalBodyPolicy,
onRedeliveryRef,
onRedelivery,
onExceptionOccurred)
@@ -636,7 +645,7 @@ public class OnExceptionDefinition extends ProcessorDefinition<OnExceptionDefini
}
/**
- * Will use the original input {@link org.apache.camel.Message} when an {@link org.apache.camel.Exchange}
+ * Will use the original input {@link org.apache.camel.Message} (original body and headers) when an {@link org.apache.camel.Exchange}
* is moved to the dead letter queue.
* <p/>
* <b>Notice:</b> this only applies when all redeliveries attempt have failed and the {@link org.apache.camel.Exchange}
@@ -650,9 +659,17 @@ public class OnExceptionDefinition extends ProcessorDefinition<OnExceptionDefini
* again as the IN message is the same as when Camel received it.
* So you should be able to send the {@link org.apache.camel.Exchange} to the same input.
* <p/>
+ * The difference between useOriginalMessage and useOriginalBody is that the former includes both the original
+ * body and headers, where as the latter only includes the original body. You can use the latter to enrich
+ * the message with custom headers and include the original message body. The former wont let you do this, as its
+ * using the original message body and headers as they are.
+ * <p/>
+ * You cannot enable both useOriginalMessage and useOriginalBody.
+ * <p/>
* By default this feature is off.
*
* @return the builder
+ * @see #useOriginalBody()
*/
public OnExceptionDefinition useOriginalMessage() {
setUseOriginalMessagePolicy(Boolean.TRUE);
@@ -660,6 +677,38 @@ public class OnExceptionDefinition extends ProcessorDefinition<OnExceptionDefini
}
/**
+ * Will use the original input {@link org.apache.camel.Message} body (original body only) when an {@link org.apache.camel.Exchange}
+ * is moved to the dead letter queue.
+ * <p/>
+ * <b>Notice:</b> this only applies when all redeliveries attempt have failed and the {@link org.apache.camel.Exchange}
+ * is doomed for failure.
+ * <br/>
+ * Instead of using the current inprogress {@link org.apache.camel.Exchange} IN message we use the original
+ * IN message instead. This allows you to store the original input in the dead letter queue instead of the inprogress
+ * snapshot of the IN message.
+ * For instance if you route transform the IN body during routing and then failed. With the original exchange
+ * store in the dead letter queue it might be easier to manually re submit the {@link org.apache.camel.Exchange}
+ * again as the IN message is the same as when Camel received it.
+ * So you should be able to send the {@link org.apache.camel.Exchange} to the same input.
+ * <p/>
+ * The difference between useOriginalMessage and useOriginalBody is that the former includes both the original
+ * body and headers, where as the latter only includes the original body. You can use the latter to enrich
+ * the message with custom headers and include the original message body. The former wont let you do this, as its
+ * using the original message body and headers as they are.
+ * <p/>
+ * You cannot enable both useOriginalMessage and useOriginalBody.
+ * <p/>
+ * By default this feature is off.
+ *
+ * @return the builder
+ * @see #useOriginalMessage()
+ */
+ public OnExceptionDefinition useOriginalBody() {
+ setUseOriginalBodyPolicy(Boolean.TRUE);
+ return this;
+ }
+
+ /**
* Sets a processor that should be processed <b>before</b> a redelivery attempt.
* <p/>
* Can be used to change the {@link org.apache.camel.Exchange} <b>before</b> its being redelivered.
@@ -842,6 +891,14 @@ public class OnExceptionDefinition extends ProcessorDefinition<OnExceptionDefini
this.useOriginalMessagePolicy = useOriginalMessagePolicy;
}
+ public Boolean getUseOriginalBodyPolicy() {
+ return useOriginalBodyPolicy;
+ }
+
+ public void setUseOriginalBodyPolicy(Boolean useOriginalBodyPolicy) {
+ this.useOriginalBodyPolicy = useOriginalBodyPolicy;
+ }
+
// Implementation methods
//-------------------------------------------------------------------------
diff --git a/core/camel-core/src/main/java/org/apache/camel/reifier/errorhandler/DeadLetterChannelReifier.java b/core/camel-core/src/main/java/org/apache/camel/reifier/errorhandler/DeadLetterChannelReifier.java
index 9f995b0..b4a2e37 100644
--- a/core/camel-core/src/main/java/org/apache/camel/reifier/errorhandler/DeadLetterChannelReifier.java
+++ b/core/camel-core/src/main/java/org/apache/camel/reifier/errorhandler/DeadLetterChannelReifier.java
@@ -38,7 +38,7 @@ public class DeadLetterChannelReifier extends DefaultErrorHandlerReifier<DeadLet
definition.getLogger(), definition.getOnRedelivery(),
definition.getRedeliveryPolicy(), definition.getExceptionPolicyStrategy(),
definition.getFailureProcessor(), definition.getDeadLetterUri(),
- definition.isDeadLetterHandleNewException(), definition.isUseOriginalMessage(),
+ definition.isDeadLetterHandleNewException(), definition.isUseOriginalMessage(), definition.isUseOriginalBody(),
definition.getRetryWhilePolicy(routeContext.getCamelContext()),
getExecutorService(routeContext.getCamelContext()),
definition.getOnPrepareFailure(), definition.getOnExceptionOccurred());
diff --git a/core/camel-core/src/main/java/org/apache/camel/reifier/errorhandler/ErrorHandlerReifier.java b/core/camel-core/src/main/java/org/apache/camel/reifier/errorhandler/ErrorHandlerReifier.java
index 8f1216c..a185b6d 100644
--- a/core/camel-core/src/main/java/org/apache/camel/reifier/errorhandler/ErrorHandlerReifier.java
+++ b/core/camel-core/src/main/java/org/apache/camel/reifier/errorhandler/ErrorHandlerReifier.java
@@ -92,6 +92,7 @@ public abstract class ErrorHandlerReifier<T extends ErrorHandlerBuilderSupport>
def.getId(),
CamelContextHelper.getRouteId(def),
def.getUseOriginalMessagePolicy() != null && def.getUseOriginalMessagePolicy(),
+ def.getUseOriginalBodyPolicy() != null && def.getUseOriginalBodyPolicy(),
ObjectHelper.isNotEmpty(def.getOutputs()),
def.getHandledPolicy(),
def.getContinuedPolicy(),
@@ -255,7 +256,7 @@ public abstract class ErrorHandlerReifier<T extends ErrorHandlerBuilderSupport>
}
}
if (handler instanceof RedeliveryErrorHandler) {
- boolean original = ((RedeliveryErrorHandler) handler).isUseOriginalMessagePolicy();
+ boolean original = ((RedeliveryErrorHandler) handler).isUseOriginalMessagePolicy() || ((RedeliveryErrorHandler) handler).isUseOriginalMessagePolicy();
if (original) {
// ensure allow original is turned on
routeContext.setAllowUseOriginalMessage(true);
diff --git a/core/camel-core/src/test/java/org/apache/camel/issues/MulticastMixOriginalMessageBodyAndEnrichedHeadersUseOriginalMessageTest.java b/core/camel-core/src/test/java/org/apache/camel/issues/MulticastMixOriginalMessageBodyAndEnrichedHeadersUseOriginalBodyTest.java
similarity index 93%
rename from core/camel-core/src/test/java/org/apache/camel/issues/MulticastMixOriginalMessageBodyAndEnrichedHeadersUseOriginalMessageTest.java
rename to core/camel-core/src/test/java/org/apache/camel/issues/MulticastMixOriginalMessageBodyAndEnrichedHeadersUseOriginalBodyTest.java
index 7c140e2..5b3bcfe 100644
--- a/core/camel-core/src/test/java/org/apache/camel/issues/MulticastMixOriginalMessageBodyAndEnrichedHeadersUseOriginalMessageTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/issues/MulticastMixOriginalMessageBodyAndEnrichedHeadersUseOriginalBodyTest.java
@@ -18,11 +18,9 @@ package org.apache.camel.issues;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.model.ClaimCheckOperation;
-import org.junit.Ignore;
import org.junit.Test;
-public class MulticastMixOriginalMessageBodyAndEnrichedHeadersUseOriginalMessageTest extends ContextTestSupport {
+public class MulticastMixOriginalMessageBodyAndEnrichedHeadersUseOriginalBodyTest extends ContextTestSupport {
@Override
public boolean isUseRouteBuilder() {
@@ -30,7 +28,6 @@ public class MulticastMixOriginalMessageBodyAndEnrichedHeadersUseOriginalMessage
}
@Test
- @Ignore("CAMEL-13175")
public void testMulticastMixOriginalAndHeaders() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
@@ -38,7 +35,7 @@ public class MulticastMixOriginalMessageBodyAndEnrichedHeadersUseOriginalMessage
context.setAllowUseOriginalMessage(true);
onException(Exception.class)
- .useOriginalMessage()
+ .useOriginalBody()
.handled(true)
.to("mock:b");
diff --git a/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedErrorHandlerMBean.java b/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedErrorHandlerMBean.java
index 6cffac8..674f17e 100644
--- a/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedErrorHandlerMBean.java
+++ b/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedErrorHandlerMBean.java
@@ -35,6 +35,9 @@ public interface ManagedErrorHandlerMBean {
@ManagedAttribute(description = "When a message is moved to dead letter channel is it the original message or recent message")
boolean isDeadLetterUseOriginalMessage();
+ @ManagedAttribute(description = "When a message is moved to dead letter channel is it the original message body or recent message body")
+ boolean isDeadLetterUseOriginalBody();
+
@ManagedAttribute(description = "Does this error handler handle new exceptions which may occur during error handling")
boolean isDeadLetterHandleNewException();
diff --git a/core/camel-management-impl/src/main/java/org/apache/camel/management/mbean/ManagedErrorHandler.java b/core/camel-management-impl/src/main/java/org/apache/camel/management/mbean/ManagedErrorHandler.java
index c4fe924..92511d5 100644
--- a/core/camel-management-impl/src/main/java/org/apache/camel/management/mbean/ManagedErrorHandler.java
+++ b/core/camel-management-impl/src/main/java/org/apache/camel/management/mbean/ManagedErrorHandler.java
@@ -84,6 +84,15 @@ public class ManagedErrorHandler implements ManagedErrorHandlerMBean {
return redelivery.isUseOriginalMessagePolicy();
}
+ public boolean isDeadLetterUseOriginalBody() {
+ if (!isSupportRedelivery()) {
+ return false;
+ }
+
+ RedeliveryErrorHandler redelivery = (RedeliveryErrorHandler) errorHandler;
+ return redelivery.isUseOriginalBodyPolicy();
+ }
+
public boolean isDeadLetterHandleNewException() {
if (!isSupportRedelivery()) {
return false;