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/06 12:03:44 UTC
[camel] 01/03: CAMEL-16834: error handler in model DSL. WIP
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch errorhandler-in-dsl
in repository https://gitbox.apache.org/repos/asf/camel.git
commit bdfda05b2bd3183d98f7ea009f27de7a744fd533
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Apr 6 11:12:38 2022 +0200
CAMEL-16834: error handler in model DSL. WIP
---
.../java/org/apache/camel/ErrorHandlerFactory.java | 1 -
.../services/org/apache/camel/model.properties | 1 +
.../camel/model/errorhandler/errorHandlerRef.json | 18 ++++++
.../org/apache/camel/model/errorhandler/jaxb.index | 1 +
.../apache/camel/builder/ErrorHandlerBuilder.java | 2 +
.../org/apache/camel/builder/RouteBuilder.java | 4 +-
.../org/apache/camel/model/RouteDefinition.java | 16 ++---
.../model/errorhandler/ErrorHandlerHelper.java | 10 ++--
.../errorhandler/ErrorHandlerRefDefinition.java | 70 ++++++++++++++++++++++
.../reifier/errorhandler/ErrorHandlerReifier.java | 17 +++---
.../errorhandler/NewErrorHandlerRefReifier.java | 48 +++++++++++++++
.../core/xml/AbstractCamelContextFactoryBean.java | 5 +-
.../builder/RouteTemplateErrorHandlerTest.java | 5 +-
...ExceptionErrorHandlerRefIssueTwoRoutesTest.java | 6 +-
...HandledRouteScopedErrorHandlerRefIssueTest.java | 4 +-
...uteScopedErrorHandlerRefIssueTwoRoutesTest.java | 5 +-
...ceptionRouteScopedErrorHandlerRefIssueTest.java | 4 +-
...uteScopedErrorHandlerRefIssueTwoRoutesTest.java | 5 +-
...HandledRouteScopedErrorHandlerRefIssueTest.java | 3 +-
...uteScopedErrorHandlerRefIssueTwoRoutesTest.java | 5 +-
...ceptionRouteScopedErrorHandlerRefIssueTest.java | 3 +-
...uteScopedErrorHandlerRefIssueTwoRoutesTest.java | 5 +-
.../java/org/apache/camel/xml/in/ModelParser.java | 9 +++
23 files changed, 195 insertions(+), 52 deletions(-)
diff --git a/core/camel-api/src/main/java/org/apache/camel/ErrorHandlerFactory.java b/core/camel-api/src/main/java/org/apache/camel/ErrorHandlerFactory.java
index 4a881b143c0..9941a6ae1c4 100644
--- a/core/camel-api/src/main/java/org/apache/camel/ErrorHandlerFactory.java
+++ b/core/camel-api/src/main/java/org/apache/camel/ErrorHandlerFactory.java
@@ -19,7 +19,6 @@ package org.apache.camel;
/**
* Factory for creating {@link org.apache.camel.spi.ErrorHandler}s.
*/
-@Deprecated
public interface ErrorHandlerFactory {
}
diff --git a/core/camel-core-model/src/generated/resources/META-INF/services/org/apache/camel/model.properties b/core/camel-core-model/src/generated/resources/META-INF/services/org/apache/camel/model.properties
index 51a47545bba..ba5cbb629f9 100644
--- a/core/camel-core-model/src/generated/resources/META-INF/services/org/apache/camel/model.properties
+++ b/core/camel-core-model/src/generated/resources/META-INF/services/org/apache/camel/model.properties
@@ -47,6 +47,7 @@ dynamicRouter
enrich
errorHandler
errorHandler
+errorHandlerRef
etcdServiceDiscovery
exchangeProperty
expression
diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/errorhandler/errorHandlerRef.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/errorhandler/errorHandlerRef.json
new file mode 100644
index 00000000000..b1cc07bde2a
--- /dev/null
+++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/errorhandler/errorHandlerRef.json
@@ -0,0 +1,18 @@
+{
+ "model": {
+ "kind": "model",
+ "name": "errorHandlerRef",
+ "title": "Error Handler Ref",
+ "description": "Dead letter channel error handler.",
+ "deprecated": false,
+ "label": "configuration,error",
+ "javaType": "org.apache.camel.model.errorhandler.ErrorHandlerRefDefinition",
+ "abstract": false,
+ "input": false,
+ "output": false
+ },
+ "properties": {
+ "ref": { "kind": "attribute", "displayName": "Ref", "required": false, "type": "object", "javaType": "org.apache.camel.ErrorHandlerFactory", "deprecated": false, "autowired": false, "secret": false, "description": "References to an existing or custom error handler." },
+ "id": { "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The id of this node" }
+ }
+}
diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/errorhandler/jaxb.index b/core/camel-core-model/src/generated/resources/org/apache/camel/model/errorhandler/jaxb.index
index f4fe4082b36..0fb3a1aa359 100644
--- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/errorhandler/jaxb.index
+++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/errorhandler/jaxb.index
@@ -1,5 +1,6 @@
# Generated by camel build tools - do NOT edit this file!
DeadLetterChannelDefinition
DefaultErrorHandlerDefinition
+ErrorHandlerRefDefinition
NoErrorHandlerDefinition
TransactionErrorHandlerDefinition
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/builder/ErrorHandlerBuilder.java b/core/camel-core-model/src/main/java/org/apache/camel/builder/ErrorHandlerBuilder.java
index 0e41e6d9317..8d5bbf9daa0 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/builder/ErrorHandlerBuilder.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/builder/ErrorHandlerBuilder.java
@@ -24,6 +24,8 @@ import org.apache.camel.ErrorHandlerFactory;
@Deprecated
public interface ErrorHandlerBuilder extends ErrorHandlerFactory {
+ // TODO: Move these to ErrorHandlerFactory and remove this
+
/**
* Whether this error handler supports transacted exchanges.
*/
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/builder/RouteBuilder.java b/core/camel-core-model/src/main/java/org/apache/camel/builder/RouteBuilder.java
index f20e21886be..240dc8f5d64 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/builder/RouteBuilder.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/builder/RouteBuilder.java
@@ -45,6 +45,7 @@ import org.apache.camel.model.RouteTemplatesDefinition;
import org.apache.camel.model.RoutesDefinition;
import org.apache.camel.model.TemplatedRouteDefinition;
import org.apache.camel.model.TemplatedRoutesDefinition;
+import org.apache.camel.model.errorhandler.ErrorHandlerRefDefinition;
import org.apache.camel.model.rest.RestConfigurationDefinition;
import org.apache.camel.model.rest.RestDefinition;
import org.apache.camel.model.rest.RestsDefinition;
@@ -368,13 +369,12 @@ public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
*
* @param ref reference to the error handler to use
*/
- @Deprecated
public void errorHandler(String ref) {
if (!getRouteCollection().getRoutes().isEmpty()) {
throw new IllegalArgumentException("errorHandler must be defined before any routes in the RouteBuilder");
}
getRouteCollection().setCamelContext(getContext());
- setErrorHandlerBuilder(new ErrorHandlerBuilderRef(ref));
+ setErrorHandlerBuilder(new ErrorHandlerRefDefinition(ref));
}
/**
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/RouteDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/RouteDefinition.java
index 893d91316a6..1fb31671a2c 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/RouteDefinition.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/RouteDefinition.java
@@ -42,7 +42,7 @@ import org.apache.camel.RouteTemplateContext;
import org.apache.camel.ShutdownRoute;
import org.apache.camel.ShutdownRunningTask;
import org.apache.camel.builder.EndpointConsumerBuilder;
-import org.apache.camel.builder.ErrorHandlerBuilderRef;
+import org.apache.camel.model.errorhandler.ErrorHandlerRefDefinition;
import org.apache.camel.model.rest.RestBindingDefinition;
import org.apache.camel.model.rest.RestDefinition;
import org.apache.camel.spi.AsEndpointUri;
@@ -420,11 +420,11 @@ public class RouteDefinition extends OutputDefinition<RouteDefinition>
/**
* Installs the given <a href="http://camel.apache.org/error-handler.html">error handler</a> builder.
*
- * @param errorHandlerBuilder the error handler to be used by default for all child routes
- * @return the current builder with the error handler configured
+ * @param ref reference to existing error handler
+ * @return the current builder with the error handler configured
*/
- public RouteDefinition errorHandler2(ErrorHandlerDefinition errorHandlerBuilder) {
- setErrorHandlerFactory(errorHandlerBuilder);
+ public RouteDefinition errorHandler(String ref) {
+ setErrorHandlerRef(ref);
// we are now using a route scoped error handler
contextScopedErrorHandler = false;
return this;
@@ -989,7 +989,7 @@ public class RouteDefinition extends OutputDefinition<RouteDefinition>
// we use an specific error handler ref (from Spring DSL) then wrap that
// with a error handler build ref so Camel knows its not just the
// default one
- setErrorHandlerFactory(new ErrorHandlerBuilderRef(errorHandlerRef));
+ setErrorHandlerFactory(new ErrorHandlerRefDefinition(errorHandlerRef));
}
}
@@ -1069,11 +1069,11 @@ public class RouteDefinition extends OutputDefinition<RouteDefinition>
private ErrorHandlerFactory createErrorHandlerBuilder() {
if (errorHandlerRef != null) {
- return new ErrorHandlerBuilderRef(errorHandlerRef);
+ return new ErrorHandlerRefDefinition(errorHandlerRef);
}
// return a reference to the default error handler
- return new ErrorHandlerBuilderRef(ErrorHandlerBuilderRef.DEFAULT_ERROR_HANDLER_BUILDER);
+ return new ErrorHandlerRefDefinition(ErrorHandlerRefDefinition.DEFAULT_ERROR_HANDLER_BUILDER);
}
public ErrorHandlerFactory getErrorHandlerFactory() {
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/errorhandler/ErrorHandlerHelper.java b/core/camel-core-model/src/main/java/org/apache/camel/model/errorhandler/ErrorHandlerHelper.java
index 1642ff4eb19..7a50e52f45c 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/errorhandler/ErrorHandlerHelper.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/errorhandler/ErrorHandlerHelper.java
@@ -54,8 +54,8 @@ public final class ErrorHandlerHelper {
// see if there has been configured a error handler builder on the route
source = route.getErrorHandlerFactory();
// check if its also a ref with no error handler configuration like me
- if (source instanceof ErrorHandlerRefProperties) {
- ErrorHandlerRefProperties other = (ErrorHandlerRefProperties) source;
+ if (source instanceof ErrorHandlerRefDefinition) {
+ ErrorHandlerRefDefinition other = (ErrorHandlerRefDefinition) source;
String otherRef = other.getRef();
if (!isErrorHandlerFactoryConfigured(otherRef)) {
// the other has also no explicit error handler configured
@@ -90,8 +90,8 @@ public final class ErrorHandlerHelper {
protected static ErrorHandlerFactory lookupErrorHandlerFactory(CamelContext camelContext) {
ErrorHandlerFactory answer = camelContext.adapt(ExtendedCamelContext.class).getErrorHandlerFactory();
- if (answer instanceof ErrorHandlerRefProperties) {
- ErrorHandlerRefProperties other = (ErrorHandlerRefProperties) answer;
+ if (answer instanceof ErrorHandlerRefDefinition) {
+ ErrorHandlerRefDefinition other = (ErrorHandlerRefDefinition) answer;
String otherRef = other.getRef();
if (isErrorHandlerFactoryConfigured(otherRef)) {
answer = CamelContextHelper.lookup(camelContext, otherRef, ErrorHandlerFactory.class);
@@ -112,7 +112,7 @@ public final class ErrorHandlerHelper {
* This is for instance used by the transacted policy to setup a TransactedErrorHandlerBuilder in camel-spring.
*/
public static boolean isErrorHandlerFactoryConfigured(String ref) {
- return !ErrorHandlerRefProperties.DEFAULT_ERROR_HANDLER_BUILDER.equals(ref);
+ return !ErrorHandlerRefDefinition.DEFAULT_ERROR_HANDLER_BUILDER.equals(ref);
}
}
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/errorhandler/ErrorHandlerRefDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/errorhandler/ErrorHandlerRefDefinition.java
new file mode 100644
index 00000000000..8454d297298
--- /dev/null
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/errorhandler/ErrorHandlerRefDefinition.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.model.errorhandler;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.builder.ErrorHandlerBuilder;
+import org.apache.camel.spi.Metadata;
+
+/**
+ * Dead letter channel error handler.
+ */
+@Metadata(label = "configuration,error")
+@XmlRootElement(name = "errorHandlerRef")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class ErrorHandlerRefDefinition extends BaseErrorHandlerDefinition implements ErrorHandlerBuilder {
+
+ public static final String DEFAULT_ERROR_HANDLER_BUILDER = "CamelDefaultErrorHandlerBuilder";
+
+ @XmlAttribute(required = true)
+ @Metadata(javaType = "org.apache.camel.ErrorHandlerFactory")
+ private String ref;
+
+ public ErrorHandlerRefDefinition() {
+ }
+
+ public ErrorHandlerRefDefinition(String ref) {
+ this.ref = ref;
+ }
+
+ @Override
+ public boolean supportTransacted() {
+ return false;
+ }
+
+ @Override
+ public ErrorHandlerBuilder cloneBuilder() {
+ // clone not needed
+ return this;
+ }
+
+ public String getRef() {
+ return ref;
+ }
+
+ /**
+ * References to an existing or custom error handler.
+ */
+ public void setRef(String ref) {
+ this.ref = ref;
+ }
+
+}
diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/errorhandler/ErrorHandlerReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/errorhandler/ErrorHandlerReifier.java
index 2aacae75f21..6ce7cdbf6bc 100644
--- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/errorhandler/ErrorHandlerReifier.java
+++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/errorhandler/ErrorHandlerReifier.java
@@ -36,7 +36,7 @@ import org.apache.camel.model.OnExceptionDefinition;
import org.apache.camel.model.RedeliveryPolicyDefinition;
import org.apache.camel.model.errorhandler.DeadLetterChannelDefinition;
import org.apache.camel.model.errorhandler.DefaultErrorHandlerDefinition;
-import org.apache.camel.model.errorhandler.ErrorHandlerRefProperties;
+import org.apache.camel.model.errorhandler.ErrorHandlerRefDefinition;
import org.apache.camel.model.errorhandler.NoErrorHandlerDefinition;
import org.apache.camel.processor.errorhandler.ErrorHandlerSupport;
import org.apache.camel.processor.errorhandler.ExceptionPolicy;
@@ -97,11 +97,11 @@ public abstract class ErrorHandlerReifier<T extends ErrorHandlerFactory> extends
// } else if (definition instanceof DefaultErrorHandlerProperties) {
// return new DefaultErrorHandlerReifier<>(route, definition);
// } else if (definition instanceof ErrorHandlerRefProperties) {
- if (definition instanceof ErrorHandlerRefProperties) {
- return new ErrorHandlerRefReifier(route, definition);
- // } else if (definition instanceof NoErrorHandlerProperties) {
- // return new NoErrorHandlerReifier(route, definition);
- }
+ // if (definition instanceof ErrorHandlerRefProperties) {
+ // return new ErrorHandlerRefReifier(route, definition);
+ // } else if (definition instanceof NoErrorHandlerProperties) {
+ // return new NoErrorHandlerReifier(route, definition);
+ // }
if (definition instanceof DeadLetterChannelDefinition) {
return new NewDeadLetterChannelReifier(route, (DeadLetterChannelDefinition) definition);
@@ -109,10 +109,9 @@ public abstract class ErrorHandlerReifier<T extends ErrorHandlerFactory> extends
return new NewDefaultErrorHandlerReifier(route, (DefaultErrorHandlerDefinition) definition);
} else if (definition instanceof NoErrorHandlerDefinition) {
return new NewNoErrorHandlerReifier(route, definition);
+ } else if (definition instanceof ErrorHandlerRefDefinition) {
+ return new NewErrorHandlerRefReifier(route, definition);
}
- // TODO: ref properties? used by spring
- // } else if (definition instanceof ErrorHandlerRefProperties) {
- // return new ErrorHandlerRefReifier(route, definition);
return null;
}
diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/errorhandler/NewErrorHandlerRefReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/errorhandler/NewErrorHandlerRefReifier.java
new file mode 100644
index 00000000000..7959b084a7a
--- /dev/null
+++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/errorhandler/NewErrorHandlerRefReifier.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.reifier.errorhandler;
+
+import org.apache.camel.ErrorHandlerFactory;
+import org.apache.camel.Processor;
+import org.apache.camel.Route;
+import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.model.errorhandler.ErrorHandlerHelper;
+import org.apache.camel.model.errorhandler.ErrorHandlerRefDefinition;
+import org.apache.camel.util.ObjectHelper;
+
+public class NewErrorHandlerRefReifier extends ErrorHandlerReifier<ErrorHandlerRefDefinition> {
+
+ // TODO: Rename when working
+
+ public NewErrorHandlerRefReifier(Route route, ErrorHandlerFactory definition) {
+ super(route, (ErrorHandlerRefDefinition) definition);
+ }
+
+ @Override
+ public Processor createErrorHandler(Processor processor) throws Exception {
+ ErrorHandlerFactory handler = lookupErrorHandler(route);
+ return camelContext.adapt(ModelCamelContext.class).getModelReifierFactory().createErrorHandler(route, handler,
+ processor);
+ }
+
+ private ErrorHandlerFactory lookupErrorHandler(Route route) {
+ ErrorHandlerFactory handler = ErrorHandlerHelper.lookupErrorHandlerFactory(route, definition.getRef(), true);
+ ObjectHelper.notNull(handler, "error handler '" + definition.getRef() + "'");
+ route.addErrorHandlerFactoryReference(definition, handler);
+ return handler;
+ }
+}
diff --git a/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java b/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
index 7bae96b6a41..adbd809e0c9 100644
--- a/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
+++ b/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
@@ -42,7 +42,6 @@ import org.apache.camel.StartupSummaryLevel;
import org.apache.camel.TypeConverterExists;
import org.apache.camel.TypeConverters;
import org.apache.camel.ValueHolder;
-import org.apache.camel.builder.ErrorHandlerBuilderRef;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.cloud.ServiceRegistry;
import org.apache.camel.cluster.CamelClusterService;
@@ -88,6 +87,7 @@ import org.apache.camel.model.TemplatedRouteDefinition;
import org.apache.camel.model.ThreadPoolProfileDefinition;
import org.apache.camel.model.cloud.ServiceCallConfigurationDefinition;
import org.apache.camel.model.dataformat.DataFormatsDefinition;
+import org.apache.camel.model.errorhandler.ErrorHandlerRefDefinition;
import org.apache.camel.model.rest.RestConfigurationDefinition;
import org.apache.camel.model.rest.RestContainer;
import org.apache.camel.model.rest.RestDefinition;
@@ -1165,7 +1165,8 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex
context.setDelayer(CamelContextHelper.parseLong(context, getDelayer()));
}
if (getErrorHandlerRef() != null) {
- context.adapt(ExtendedCamelContext.class).setErrorHandlerFactory(new ErrorHandlerBuilderRef(getErrorHandlerRef()));
+ context.adapt(ExtendedCamelContext.class)
+ .setErrorHandlerFactory(new ErrorHandlerRefDefinition(getErrorHandlerRef()));
}
if (getAutoStartup() != null) {
context.setAutoStartup(CamelContextHelper.parseBoolean(context, getAutoStartup()));
diff --git a/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplateErrorHandlerTest.java b/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplateErrorHandlerTest.java
index 907dcea1e84..6b31dd78b8d 100644
--- a/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplateErrorHandlerTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplateErrorHandlerTest.java
@@ -19,6 +19,7 @@ package org.apache.camel.builder;
import org.apache.camel.Channel;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.engine.DefaultRoute;
+import org.apache.camel.model.errorhandler.ErrorHandlerRefDefinition;
import org.apache.camel.model.errorhandler.NoErrorHandlerDefinition;
import org.apache.camel.processor.errorhandler.NoErrorHandler;
import org.junit.jupiter.api.Test;
@@ -49,13 +50,13 @@ public class RouteTemplateErrorHandlerTest {
});
assertThat(context.getRouteDefinitions()).first().satisfies(d -> {
- assertThat(d.getErrorHandlerFactory()).isInstanceOfSatisfying(ErrorHandlerBuilderRef.class, h -> {
+ assertThat(d.getErrorHandlerFactory()).isInstanceOfSatisfying(ErrorHandlerRefDefinition.class, h -> {
assertThat(h.getRef()).isEqualTo("myErrorHandler");
});
});
assertThat(context.getRouteTemplateDefinitions()).first().satisfies(d -> {
- assertThat(d.route().getErrorHandlerFactory()).isInstanceOfSatisfying(ErrorHandlerBuilderRef.class, h -> {
+ assertThat(d.route().getErrorHandlerFactory()).isInstanceOfSatisfying(ErrorHandlerRefDefinition.class, h -> {
assertThat(h.getRef()).isEqualTo("myErrorHandler");
});
});
diff --git a/core/camel-core/src/test/java/org/apache/camel/issues/ContextScopedOnExceptionErrorHandlerRefIssueTwoRoutesTest.java b/core/camel-core/src/test/java/org/apache/camel/issues/ContextScopedOnExceptionErrorHandlerRefIssueTwoRoutesTest.java
index 3e191840b6a..996bc550acd 100644
--- a/core/camel-core/src/test/java/org/apache/camel/issues/ContextScopedOnExceptionErrorHandlerRefIssueTwoRoutesTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/issues/ContextScopedOnExceptionErrorHandlerRefIssueTwoRoutesTest.java
@@ -19,9 +19,9 @@ package org.apache.camel.issues;
import java.io.IOException;
import org.apache.camel.ContextTestSupport;
-import org.apache.camel.builder.ErrorHandlerBuilderRef;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.errorhandler.DeadLetterChannelDefinition;
+import org.apache.camel.model.errorhandler.ErrorHandlerRefDefinition;
import org.apache.camel.spi.Registry;
import org.junit.jupiter.api.Test;
@@ -66,10 +66,10 @@ public class ContextScopedOnExceptionErrorHandlerRefIssueTwoRoutesTest extends C
public void configure() throws Exception {
onException(IllegalArgumentException.class).handled(true).to("mock:handled").end();
- from("direct:foo").errorHandler(new ErrorHandlerBuilderRef("myDLC")).to("mock:foo")
+ from("direct:foo").errorHandler(new ErrorHandlerRefDefinition("myDLC")).to("mock:foo")
.throwException(new IOException("Damn IO"));
- from("direct:start").errorHandler(new ErrorHandlerBuilderRef("myDLC")).to("mock:a")
+ from("direct:start").errorHandler(new ErrorHandlerRefDefinition("myDLC")).to("mock:a")
.throwException(new IllegalArgumentException("Damn"));
}
};
diff --git a/core/camel-core/src/test/java/org/apache/camel/issues/ContextScopedOnExceptionNotHandledRouteScopedErrorHandlerRefIssueTest.java b/core/camel-core/src/test/java/org/apache/camel/issues/ContextScopedOnExceptionNotHandledRouteScopedErrorHandlerRefIssueTest.java
index aa0c069c931..9e676538152 100644
--- a/core/camel-core/src/test/java/org/apache/camel/issues/ContextScopedOnExceptionNotHandledRouteScopedErrorHandlerRefIssueTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/issues/ContextScopedOnExceptionNotHandledRouteScopedErrorHandlerRefIssueTest.java
@@ -18,9 +18,9 @@ package org.apache.camel.issues;
import org.apache.camel.CamelExecutionException;
import org.apache.camel.ContextTestSupport;
-import org.apache.camel.builder.ErrorHandlerBuilderRef;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.errorhandler.DeadLetterChannelDefinition;
+import org.apache.camel.model.errorhandler.ErrorHandlerRefDefinition;
import org.apache.camel.spi.Registry;
import org.junit.jupiter.api.Test;
@@ -61,7 +61,7 @@ public class ContextScopedOnExceptionNotHandledRouteScopedErrorHandlerRefIssueTe
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- from("direct:start").errorHandler(new ErrorHandlerBuilderRef("myDLC"))
+ from("direct:start").errorHandler(new ErrorHandlerRefDefinition("myDLC"))
.onException(IllegalArgumentException.class).handled(false).to("mock:handled").end()
.to("mock:a").throwException(new IllegalArgumentException("Damn"));
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/issues/ContextScopedOnExceptionNotHandledRouteScopedErrorHandlerRefIssueTwoRoutesTest.java b/core/camel-core/src/test/java/org/apache/camel/issues/ContextScopedOnExceptionNotHandledRouteScopedErrorHandlerRefIssueTwoRoutesTest.java
index a24466012cb..785de559012 100644
--- a/core/camel-core/src/test/java/org/apache/camel/issues/ContextScopedOnExceptionNotHandledRouteScopedErrorHandlerRefIssueTwoRoutesTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/issues/ContextScopedOnExceptionNotHandledRouteScopedErrorHandlerRefIssueTwoRoutesTest.java
@@ -20,7 +20,6 @@ import java.io.IOException;
import org.apache.camel.CamelExecutionException;
import org.apache.camel.ContextTestSupport;
-import org.apache.camel.builder.ErrorHandlerBuilderRef;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.errorhandler.DeadLetterChannelDefinition;
import org.apache.camel.spi.Registry;
@@ -76,10 +75,10 @@ public class ContextScopedOnExceptionNotHandledRouteScopedErrorHandlerRefIssueTw
public void configure() throws Exception {
onException(IllegalArgumentException.class).handled(false).to("mock:handled").end();
- from("direct:foo").errorHandler(new ErrorHandlerBuilderRef("myDLC")).to("mock:foo")
+ from("direct:foo").errorHandler("myDLC").to("mock:foo")
.throwException(new IOException("Damn IO"));
- from("direct:start").errorHandler(new ErrorHandlerBuilderRef("myDLC")).to("mock:a")
+ from("direct:start").errorHandler("myDLC").to("mock:a")
.throwException(new IllegalArgumentException("Damn"));
}
};
diff --git a/core/camel-core/src/test/java/org/apache/camel/issues/ContextScopedOnExceptionRouteScopedErrorHandlerRefIssueTest.java b/core/camel-core/src/test/java/org/apache/camel/issues/ContextScopedOnExceptionRouteScopedErrorHandlerRefIssueTest.java
index fd6fcd87b8f..402085981b9 100644
--- a/core/camel-core/src/test/java/org/apache/camel/issues/ContextScopedOnExceptionRouteScopedErrorHandlerRefIssueTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/issues/ContextScopedOnExceptionRouteScopedErrorHandlerRefIssueTest.java
@@ -17,9 +17,9 @@
package org.apache.camel.issues;
import org.apache.camel.ContextTestSupport;
-import org.apache.camel.builder.ErrorHandlerBuilderRef;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.errorhandler.DeadLetterChannelDefinition;
+import org.apache.camel.model.errorhandler.ErrorHandlerRefDefinition;
import org.apache.camel.spi.Registry;
import org.junit.jupiter.api.Test;
@@ -54,7 +54,7 @@ public class ContextScopedOnExceptionRouteScopedErrorHandlerRefIssueTest extends
onException(IllegalArgumentException.class).handled(true).to("mock:handled").end();
- from("direct:start").errorHandler(new ErrorHandlerBuilderRef("myDLC")).to("mock:a")
+ from("direct:start").errorHandler(new ErrorHandlerRefDefinition("myDLC")).to("mock:a")
.throwException(new IllegalArgumentException("Damn"));
}
};
diff --git a/core/camel-core/src/test/java/org/apache/camel/issues/ContextScopedOnExceptionRouteScopedErrorHandlerRefIssueTwoRoutesTest.java b/core/camel-core/src/test/java/org/apache/camel/issues/ContextScopedOnExceptionRouteScopedErrorHandlerRefIssueTwoRoutesTest.java
index 853a5102af6..18db4f2877d 100644
--- a/core/camel-core/src/test/java/org/apache/camel/issues/ContextScopedOnExceptionRouteScopedErrorHandlerRefIssueTwoRoutesTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/issues/ContextScopedOnExceptionRouteScopedErrorHandlerRefIssueTwoRoutesTest.java
@@ -19,7 +19,6 @@ package org.apache.camel.issues;
import java.io.IOException;
import org.apache.camel.ContextTestSupport;
-import org.apache.camel.builder.ErrorHandlerBuilderRef;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.errorhandler.DeadLetterChannelDefinition;
import org.apache.camel.spi.Registry;
@@ -66,10 +65,10 @@ public class ContextScopedOnExceptionRouteScopedErrorHandlerRefIssueTwoRoutesTes
public void configure() throws Exception {
onException(IllegalArgumentException.class).handled(true).to("mock:handled").end();
- from("direct:foo").errorHandler(new ErrorHandlerBuilderRef("myDLC")).to("mock:foo")
+ from("direct:foo").errorHandler("myDLC").to("mock:foo")
.throwException(new IOException("Damn IO"));
- from("direct:start").errorHandler(new ErrorHandlerBuilderRef("myDLC")).to("mock:a")
+ from("direct:start").errorHandler("myDLC").to("mock:a")
.throwException(new IllegalArgumentException("Damn"));
}
};
diff --git a/core/camel-core/src/test/java/org/apache/camel/issues/OnExceptionNotHandledRouteScopedErrorHandlerRefIssueTest.java b/core/camel-core/src/test/java/org/apache/camel/issues/OnExceptionNotHandledRouteScopedErrorHandlerRefIssueTest.java
index c262e0c2429..9c70b6bc518 100644
--- a/core/camel-core/src/test/java/org/apache/camel/issues/OnExceptionNotHandledRouteScopedErrorHandlerRefIssueTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/issues/OnExceptionNotHandledRouteScopedErrorHandlerRefIssueTest.java
@@ -18,7 +18,6 @@ package org.apache.camel.issues;
import org.apache.camel.CamelExecutionException;
import org.apache.camel.ContextTestSupport;
-import org.apache.camel.builder.ErrorHandlerBuilderRef;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.errorhandler.DeadLetterChannelDefinition;
import org.apache.camel.spi.Registry;
@@ -61,7 +60,7 @@ public class OnExceptionNotHandledRouteScopedErrorHandlerRefIssueTest extends Co
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- from("direct:start").errorHandler(new ErrorHandlerBuilderRef("myDLC"))
+ from("direct:start").errorHandler("myDLC")
.onException(IllegalArgumentException.class).handled(false).to("mock:handled").end()
.to("mock:a").throwException(new IllegalArgumentException("Damn"));
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/issues/OnExceptionNotHandledRouteScopedErrorHandlerRefIssueTwoRoutesTest.java b/core/camel-core/src/test/java/org/apache/camel/issues/OnExceptionNotHandledRouteScopedErrorHandlerRefIssueTwoRoutesTest.java
index 838ddabd639..9c5451e6466 100644
--- a/core/camel-core/src/test/java/org/apache/camel/issues/OnExceptionNotHandledRouteScopedErrorHandlerRefIssueTwoRoutesTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/issues/OnExceptionNotHandledRouteScopedErrorHandlerRefIssueTwoRoutesTest.java
@@ -18,7 +18,6 @@ package org.apache.camel.issues;
import org.apache.camel.CamelExecutionException;
import org.apache.camel.ContextTestSupport;
-import org.apache.camel.builder.ErrorHandlerBuilderRef;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.errorhandler.DeadLetterChannelDefinition;
import org.apache.camel.spi.Registry;
@@ -72,10 +71,10 @@ public class OnExceptionNotHandledRouteScopedErrorHandlerRefIssueTwoRoutesTest e
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- from("direct:foo").errorHandler(new ErrorHandlerBuilderRef("myDLC")).to("mock:foo")
+ from("direct:foo").errorHandler("myDLC").to("mock:foo")
.throwException(new IllegalArgumentException("Damn Foo"));
- from("direct:start").errorHandler(new ErrorHandlerBuilderRef("myDLC"))
+ from("direct:start").errorHandler("myDLC")
.onException(IllegalArgumentException.class).handled(false).to("mock:handled").end()
.to("mock:a").throwException(new IllegalArgumentException("Damn"));
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/issues/OnExceptionRouteScopedErrorHandlerRefIssueTest.java b/core/camel-core/src/test/java/org/apache/camel/issues/OnExceptionRouteScopedErrorHandlerRefIssueTest.java
index d8b28186360..a3930f70062 100644
--- a/core/camel-core/src/test/java/org/apache/camel/issues/OnExceptionRouteScopedErrorHandlerRefIssueTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/issues/OnExceptionRouteScopedErrorHandlerRefIssueTest.java
@@ -17,7 +17,6 @@
package org.apache.camel.issues;
import org.apache.camel.ContextTestSupport;
-import org.apache.camel.builder.ErrorHandlerBuilderRef;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.errorhandler.DeadLetterChannelDefinition;
import org.apache.camel.spi.Registry;
@@ -51,7 +50,7 @@ public class OnExceptionRouteScopedErrorHandlerRefIssueTest extends ContextTestS
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- from("direct:start").errorHandler(new ErrorHandlerBuilderRef("myDLC"))
+ from("direct:start").errorHandler("myDLC")
.onException(IllegalArgumentException.class).handled(true).to("mock:handled").end()
.to("mock:a").throwException(new IllegalArgumentException("Damn"));
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/issues/OnExceptionRouteScopedErrorHandlerRefIssueTwoRoutesTest.java b/core/camel-core/src/test/java/org/apache/camel/issues/OnExceptionRouteScopedErrorHandlerRefIssueTwoRoutesTest.java
index 5c126dd1296..a5ca4b19655 100644
--- a/core/camel-core/src/test/java/org/apache/camel/issues/OnExceptionRouteScopedErrorHandlerRefIssueTwoRoutesTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/issues/OnExceptionRouteScopedErrorHandlerRefIssueTwoRoutesTest.java
@@ -17,7 +17,6 @@
package org.apache.camel.issues;
import org.apache.camel.ContextTestSupport;
-import org.apache.camel.builder.ErrorHandlerBuilderRef;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.errorhandler.DeadLetterChannelDefinition;
import org.apache.camel.spi.Registry;
@@ -62,10 +61,10 @@ public class OnExceptionRouteScopedErrorHandlerRefIssueTwoRoutesTest extends Con
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- from("direct:foo").errorHandler(new ErrorHandlerBuilderRef("myDLC")).to("mock:foo")
+ from("direct:foo").errorHandler("myDLC").to("mock:foo")
.throwException(new IllegalArgumentException("Damn Foo"));
- from("direct:start").errorHandler(new ErrorHandlerBuilderRef("myDLC"))
+ from("direct:start").errorHandler("myDLC")
.onException(IllegalArgumentException.class).handled(true).to("mock:handled").end()
.to("mock:a").throwException(new IllegalArgumentException("Damn"));
}
diff --git a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java
index 860d83138cd..346d0a04eb9 100644
--- a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java
+++ b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java
@@ -2575,6 +2575,15 @@ public class ModelParser extends BaseParser {
protected DefaultErrorHandlerDefinition doParseDefaultErrorHandlerDefinition() throws IOException, XmlPullParserException {
return doParse(new DefaultErrorHandlerDefinition(), defaultErrorHandlerDefinitionAttributeHandler(), defaultErrorHandlerDefinitionElementHandler(), noValueHandler());
}
+ protected ErrorHandlerRefDefinition doParseErrorHandlerRefDefinition() throws IOException, XmlPullParserException {
+ return doParse(new ErrorHandlerRefDefinition(), (def, key, val) -> {
+ if ("ref".equals(key)) {
+ def.setRef(val);
+ return true;
+ }
+ return identifiedTypeAttributeHandler().accept(def, key, val);
+ }, noElementHandler(), noValueHandler());
+ }
protected NoErrorHandlerDefinition doParseNoErrorHandlerDefinition() throws IOException, XmlPullParserException {
return doParse(new NoErrorHandlerDefinition(),
identifiedTypeAttributeHandler(), noElementHandler(), noValueHandler());