[ 
https://issues.apache.org/jira/browse/CAMEL-17105?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Claus Ibsen resolved CAMEL-17105.
---------------------------------
    Resolution: Fixed

Thanks for reporting and the PR

> Transactions - Ignored property Exchange.markRollbackOnlyLast
> -------------------------------------------------------------
>
>                 Key: CAMEL-17105
>                 URL: https://issues.apache.org/jira/browse/CAMEL-17105
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-spring
>    Affects Versions: 3.11.3, 3.12.0
>            Reporter: Nick Smith
>            Assignee: Claus Ibsen
>            Priority: Major
>             Fix For: 3.13.0, 3.11.4
>
>
> In Camel 3.x Exchange was refactored and markRollbackOnly was changed 
> from 
> [2.x|[https://github.com/apache/camel/blob/05a6bd786fc8beeae30f6e10197cb59650892a67/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java#L474]]
> {code:java}
>     public boolean isRollbackOnly() {
>         return Boolean.TRUE.equals(getProperty(Exchange.ROLLBACK_ONLY)) || 
> Boolean.TRUE.equals(getProperty(Exchange.ROLLBACK_ONLY_LAST));
>     }
> {code}
>  to 
> [3.x|[https://github.com/apache/camel/blob/ea065afc6d638ab72c4efdd67591cb9ca4c08d0d/core/camel-support/src/main/java/org/apache/camel/support/AbstractExchange.java#L689-L691]]
> {code:java}
>     public boolean isRollbackOnly() {
>         return rollbackOnly;
>     }
> {code}
> Now in 
> [TransactionErrorHandler.doInTransactionTemplate()|https://github.com/apache/camel/blob/ea065afc6d638ab72c4efdd67591cb9ca4c08d0d/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java#L210]
>  doesn't throw TransactionRollbackException, cause isRollbackOnly false.
> {code:java}
>             protected void doInTransactionWithoutResult(TransactionStatus 
> status) {
>                 // wrapper exception to throw if the exchange failed
>                 // IMPORTANT: Must be a runtime exception to let Spring 
> regard it as to do "rollback"
>                 RuntimeException rce;
>                 // and now let process the exchange by the error handler
>                 processByErrorHandler(exchange);
>                 // after handling and still an exception or marked as 
> rollback only then rollback
>                 if (exchange.getException() != null || 
> exchange.isRollbackOnly()) {
>                     // wrap exception in transacted exception
>                     if (exchange.getException() != null) {
>                         rce = 
> RuntimeCamelException.wrapRuntimeCamelException(exchange.getException());
>                     } else {
>                         // create dummy exception to force spring transaction 
> manager to rollback
>                         rce = new TransactionRollbackException();
>                     }
>                     if (!status.isRollbackOnly()) {
>                         status.setRollbackOnly();
>                     }
>                     // throw runtime exception to force rollback (which works 
> best to rollback with Spring transaction manager)
>                     if (LOG.isTraceEnabled()) {
>                         LOG.trace("Throwing runtime exception to force 
> transaction to rollback on {}",
>                                 transactionTemplate.getName());
>                     }
>                     throw rce;
>                 }
>             }
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to