This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git
The following commit(s) were added to refs/heads/main by this push:
new 0d5a3e9d fix(core): Error handler regression
0d5a3e9d is described below
commit 0d5a3e9d28485a893a9825aefb4d1c61c6c7b0c9
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Tue Aug 30 10:16:20 2022 +0200
fix(core): Error handler regression
Workaround reintroduced to fix a Camel regression as specified in
https://github.com/apache/camel-k/issues/3560#issuecomment-1230042204
---
.../org/apache/camel/k/support/SourcesSupport.java | 23 +++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git
a/camel-k-core/support/src/main/java/org/apache/camel/k/support/SourcesSupport.java
b/camel-k-core/support/src/main/java/org/apache/camel/k/support/SourcesSupport.java
index 6e993ce0..67e00952 100644
---
a/camel-k-core/support/src/main/java/org/apache/camel/k/support/SourcesSupport.java
+++
b/camel-k-core/support/src/main/java/org/apache/camel/k/support/SourcesSupport.java
@@ -16,9 +16,11 @@
*/
package org.apache.camel.k.support;
+import java.lang.reflect.Field;
import java.util.Collection;
import java.util.List;
+import org.apache.camel.ErrorHandlerFactory;
import org.apache.camel.ExtendedCamelContext;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.RuntimeCamelException;
@@ -149,9 +151,10 @@ public final class SourcesSupport {
throw new IllegalArgumentException(
"There should not be any template definition
when configuring error handler, got " + templates.size());
}
-
- LOGGER.debug("Setting default error handler builder
factory as {}", builder.getErrorHandlerFactory());
-
runtime.getCamelContext().adapt(ExtendedCamelContext.class).setErrorHandlerFactory(builder.getErrorHandlerFactory());
+ if (hasErrorHandlerFactory(builder)){
+ LOGGER.debug("Setting default error handler
builder factory as type {}", builder.getErrorHandlerFactory().getClass());
+
runtime.getCamelContext().adapt(ExtendedCamelContext.class).setErrorHandlerFactory(builder.getErrorHandlerFactory());
+ }
}
});
break;
@@ -173,6 +176,20 @@ public final class SourcesSupport {
}
}
+ static boolean hasErrorHandlerFactory(RouteBuilder builder) {
+ //return builder.hasErrorHandlerFactory();
+ // TODO We need to replace the following workaround with the statement
above once we switch to > camel-3.18
+ try {
+ Field f =
RouteBuilder.class.getSuperclass().getDeclaredField("errorHandlerFactory");
+ f.setAccessible(true);
+ ErrorHandlerFactory privateErrorHandlerFactory =
(ErrorHandlerFactory) f.get(builder);
+ LOGGER.debug("Looking up for private error handler factory: {}",
privateErrorHandlerFactory);
+ return privateErrorHandlerFactory != null;
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Something went wrong while
checking the error handler factory", e);
+ }
+ }
+
public static void loadErrorHandlerSource(Runtime runtime,
SourceDefinition errorHandlerSourceDefinition) {
LOGGER.info("Loading error handler from: {}",
errorHandlerSourceDefinition);
load(runtime, Sources.fromDefinition(errorHandlerSourceDefinition));