You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2018/12/10 07:32:34 UTC

[camel] 01/03: CAMEL-12985: TransactionErrorHandler fails if UnitOfWork is null

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch camel-2.22.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit c8c96c4ddea0db4fb5429701b9484e78145ddf62
Author: Jess Sightler <je...@gmail.com>
AuthorDate: Fri Dec 7 13:07:43 2018 -0500

    CAMEL-12985: TransactionErrorHandler fails if UnitOfWork is null
---
 .../java/org/apache/camel/spring/spi/TransactionErrorHandler.java | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

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 653ea84..6436476 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
@@ -95,7 +95,7 @@ public class TransactionErrorHandler extends RedeliveryErrorHandler {
     public void process(Exchange exchange) throws Exception {
         // we have to run this synchronously as Spring Transaction does *not* support
         // using multiple threads to span a transaction
-        if (transactionTemplate.getPropagationBehavior() != TransactionDefinition.PROPAGATION_REQUIRES_NEW && exchange.getUnitOfWork().isTransactedBy(transactionKey)) {
+        if (transactionTemplate.getPropagationBehavior() != TransactionDefinition.PROPAGATION_REQUIRES_NEW && exchange.getUnitOfWork() != null && exchange.getUnitOfWork().isTransactedBy(transactionKey)) {
             // already transacted by this transaction template
             // so lets just let the error handler process it
             processByErrorHandler(exchange);
@@ -129,7 +129,8 @@ public class TransactionErrorHandler extends RedeliveryErrorHandler {
 
         try {
             // mark the beginning of this transaction boundary
-            exchange.getUnitOfWork().beginTransactedBy(transactionKey);
+            if (exchange.getUnitOfWork() != null)
+                exchange.getUnitOfWork().beginTransactedBy(transactionKey);
 
             // do in transaction
             logTransactionBegin(redelivered, ids);
@@ -144,7 +145,8 @@ public class TransactionErrorHandler extends RedeliveryErrorHandler {
             logTransactionRollback(redelivered, ids, e, false);
         } finally {
             // mark the end of this transaction boundary
-            exchange.getUnitOfWork().endTransactedBy(transactionKey);
+            if (exchange.getUnitOfWork() != null)
+                exchange.getUnitOfWork().endTransactedBy(transactionKey);
         }
 
         // if it was a local rollback only then remove its marker so outer transaction wont see the marker