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 2022/04/11 05:04:08 UTC
[camel] 03/03: CAMEL-16834: error handler in DSL model
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 392acab47965d481a9e36a2b1df4306ae290626f
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Apr 11 07:03:47 2022 +0200
CAMEL-16834: error handler in DSL model
---
.../apache/camel/jta/JtaTransactionErrorHandler.java | 13 -------------
.../java/org/apache/camel/jta/JtaTransactionPolicy.java | 12 ++++++++++++
.../camel/spring/spi/SpringTransactionPolicy.java | 17 ++++++++++++++++-
.../spring/spi/TransactionErrorHandlerReifier.java | 11 -----------
4 files changed, 28 insertions(+), 25 deletions(-)
diff --git a/components/camel-jta/src/main/java/org/apache/camel/jta/JtaTransactionErrorHandler.java b/components/camel-jta/src/main/java/org/apache/camel/jta/JtaTransactionErrorHandler.java
index 1d6c48cb414..dd3542e8894 100644
--- a/components/camel-jta/src/main/java/org/apache/camel/jta/JtaTransactionErrorHandler.java
+++ b/components/camel-jta/src/main/java/org/apache/camel/jta/JtaTransactionErrorHandler.java
@@ -24,11 +24,8 @@ import org.apache.camel.Exchange;
import org.apache.camel.LoggingLevel;
import org.apache.camel.Predicate;
import org.apache.camel.Processor;
-import org.apache.camel.builder.JtaTransactionErrorHandlerBuilder;
-import org.apache.camel.model.errorhandler.JtaTransactionErrorHandlerDefinition;
import org.apache.camel.processor.errorhandler.RedeliveryErrorHandler;
import org.apache.camel.processor.errorhandler.RedeliveryPolicy;
-import org.apache.camel.reifier.errorhandler.ErrorHandlerReifier;
import org.apache.camel.spi.CamelLogger;
import org.apache.camel.spi.ErrorHandler;
import org.slf4j.Logger;
@@ -41,16 +38,6 @@ import org.slf4j.LoggerFactory;
*/
public class JtaTransactionErrorHandler extends RedeliveryErrorHandler {
- static {
- // register camel-jta as transaction error handler (both builder and definition)
- ErrorHandlerReifier.registerReifier(JtaTransactionErrorHandlerBuilder.class,
- (route, errorHandlerFactory) -> new JtaTransactionErrorHandlerReifier(
- route, (JtaTransactionErrorHandlerDefinition) errorHandlerFactory));
- ErrorHandlerReifier.registerReifier(JtaTransactionErrorHandlerDefinition.class,
- (route, errorHandlerFactory) -> new JtaTransactionErrorHandlerReifier(
- route, (JtaTransactionErrorHandlerDefinition) errorHandlerFactory));
- }
-
private static final Logger LOG = LoggerFactory.getLogger(JtaTransactionErrorHandler.class);
private final JtaTransactionPolicy transactionPolicy;
private final LoggingLevel rollbackLoggingLevel;
diff --git a/components/camel-jta/src/main/java/org/apache/camel/jta/JtaTransactionPolicy.java b/components/camel-jta/src/main/java/org/apache/camel/jta/JtaTransactionPolicy.java
index e8672e11531..855818b0f9b 100644
--- a/components/camel-jta/src/main/java/org/apache/camel/jta/JtaTransactionPolicy.java
+++ b/components/camel-jta/src/main/java/org/apache/camel/jta/JtaTransactionPolicy.java
@@ -21,12 +21,14 @@ import org.apache.camel.NamedNode;
import org.apache.camel.Processor;
import org.apache.camel.Route;
import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.builder.JtaTransactionErrorHandlerBuilder;
import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.errorhandler.ErrorHandlerHelper;
import org.apache.camel.model.errorhandler.ErrorHandlerRefDefinition;
import org.apache.camel.model.errorhandler.JtaTransactionErrorHandlerDefinition;
+import org.apache.camel.reifier.errorhandler.ErrorHandlerReifier;
import org.apache.camel.spi.TransactedPolicy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,6 +41,16 @@ import org.slf4j.LoggerFactory;
*/
public abstract class JtaTransactionPolicy implements TransactedPolicy {
+ static {
+ // register camel-jta as transaction error handler (both builder and definition)
+ ErrorHandlerReifier.registerReifier(JtaTransactionErrorHandlerBuilder.class,
+ (route, errorHandlerFactory) -> new JtaTransactionErrorHandlerReifier(
+ route, (JtaTransactionErrorHandlerDefinition) errorHandlerFactory));
+ ErrorHandlerReifier.registerReifier(JtaTransactionErrorHandlerDefinition.class,
+ (route, errorHandlerFactory) -> new JtaTransactionErrorHandlerReifier(
+ route, (JtaTransactionErrorHandlerDefinition) errorHandlerFactory));
+ }
+
private static final Logger LOG = LoggerFactory.getLogger(JtaTransactionPolicy.class);
public interface Runnable {
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringTransactionPolicy.java b/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringTransactionPolicy.java
index 3611d689b62..a0ba6d41273 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringTransactionPolicy.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringTransactionPolicy.java
@@ -21,10 +21,13 @@ import org.apache.camel.NamedNode;
import org.apache.camel.Processor;
import org.apache.camel.Route;
import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.builder.SpringTransactionErrorHandlerBuilder;
import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.errorhandler.ErrorHandlerHelper;
import org.apache.camel.model.errorhandler.ErrorHandlerRefDefinition;
+import org.apache.camel.model.errorhandler.SpringTransactionErrorHandlerDefinition;
+import org.apache.camel.reifier.errorhandler.ErrorHandlerReifier;
import org.apache.camel.spi.TransactedPolicy;
import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
@@ -36,12 +39,23 @@ import org.springframework.transaction.support.TransactionTemplate;
* Spring transaction policy when using spring based transactions.
*/
public class SpringTransactionPolicy implements TransactedPolicy {
+
private static final Logger LOG = LoggerFactory.getLogger(SpringTransactionPolicy.class);
private TransactionTemplate template;
private String name;
private String propagationBehaviorName;
private PlatformTransactionManager transactionManager;
+ static {
+ // register camel-spring as transaction error handler (both builder and definition)
+ ErrorHandlerReifier.registerReifier(SpringTransactionErrorHandlerBuilder.class,
+ (route, errorHandlerFactory) -> new TransactionErrorHandlerReifier(
+ route, (SpringTransactionErrorHandlerDefinition) errorHandlerFactory));
+ ErrorHandlerReifier.registerReifier(SpringTransactionErrorHandlerDefinition.class,
+ (route, errorHandlerFactory) -> new TransactionErrorHandlerReifier(
+ route, (SpringTransactionErrorHandlerDefinition) errorHandlerFactory));
+ }
+
/**
* Default constructor for easy spring configuration.
*/
@@ -99,8 +113,9 @@ public class SpringTransactionPolicy implements TransactedPolicy {
if (builder != null) {
LOG.debug("The ErrorHandlerBuilder configured is not a TransactionErrorHandlerBuilder: {}", builder);
} else {
- LOG.debug("No ErrorHandlerBuilder configured, will use default TransactionErrorHandlerBuilder settings");
+ LOG.debug("No ErrorHandlerBuilder configured, will use default LegacyTransactionErrorHandlerBuilder settings");
}
+ // use legacy transaction to also support camel-spring-xml
LegacyTransactionErrorHandlerBuilder txBuilder = new LegacyTransactionErrorHandlerBuilder();
txBuilder.setTransactionTemplate(getTransactionTemplate());
txBuilder.setSpringTransactionPolicy(this);
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandlerReifier.java b/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandlerReifier.java
index 70937602c9f..46f51834bf8 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandlerReifier.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandlerReifier.java
@@ -24,7 +24,6 @@ import org.apache.camel.LoggingLevel;
import org.apache.camel.Predicate;
import org.apache.camel.Processor;
import org.apache.camel.Route;
-import org.apache.camel.builder.SpringTransactionErrorHandlerBuilder;
import org.apache.camel.model.RedeliveryPolicyDefinition;
import org.apache.camel.model.errorhandler.SpringTransactionErrorHandlerDefinition;
import org.apache.camel.model.errorhandler.TransactionErrorHandlerDefinition;
@@ -44,16 +43,6 @@ import static org.apache.camel.model.TransactedDefinition.PROPAGATION_REQUIRED;
public class TransactionErrorHandlerReifier extends ErrorHandlerReifier<SpringTransactionErrorHandlerDefinition> {
- static {
- // register camel-spring as transaction error handler (both builder and definition)
- ErrorHandlerReifier.registerReifier(SpringTransactionErrorHandlerBuilder.class,
- (route, errorHandlerFactory) -> new TransactionErrorHandlerReifier(
- route, (SpringTransactionErrorHandlerDefinition) errorHandlerFactory));
- ErrorHandlerReifier.registerReifier(SpringTransactionErrorHandlerDefinition.class,
- (route, errorHandlerFactory) -> new TransactionErrorHandlerReifier(
- route, (SpringTransactionErrorHandlerDefinition) errorHandlerFactory));
- }
-
private static final Logger LOG = LoggerFactory.getLogger(TransactionErrorHandlerReifier.class);
public TransactionErrorHandlerReifier(Route route, SpringTransactionErrorHandlerDefinition definition) {