You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gg...@apache.org on 2020/03/26 06:58:35 UTC
[camel] branch camel-2.25.x updated: CAMEL-14792: Ensure
CAMEL-13468 works without sacrificing ClassLoader contract in OSGi
This is an automated email from the ASF dual-hosted git repository.
ggrzybek pushed a commit to branch camel-2.25.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-2.25.x by this push:
new 70e2ca3 CAMEL-14792: Ensure CAMEL-13468 works without sacrificing ClassLoader contract in OSGi
70e2ca3 is described below
commit 70e2ca3913226b4c532d80dbd2577d7d440439de
Author: Grzegorz Grzybek <gr...@gmail.com>
AuthorDate: Thu Mar 26 07:57:54 2020 +0100
CAMEL-14792: Ensure CAMEL-13468 works without sacrificing ClassLoader contract in OSGi
---
.../apache/camel/model/OnExceptionDefinition.java | 22 +++++++++++-
.../camel/processor/ErrorHandlerSupport.java | 42 ++++++----------------
2 files changed, 32 insertions(+), 32 deletions(-)
diff --git a/camel-core/src/main/java/org/apache/camel/model/OnExceptionDefinition.java b/camel-core/src/main/java/org/apache/camel/model/OnExceptionDefinition.java
index 8f9bd92..9b329a1 100644
--- a/camel-core/src/main/java/org/apache/camel/model/OnExceptionDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/OnExceptionDefinition.java
@@ -82,6 +82,8 @@ public class OnExceptionDefinition extends ProcessorDefinition<OnExceptionDefini
@XmlElementRef
private List<ProcessorDefinition<?>> outputs = new ArrayList<>();
@XmlTransient
+ private List<Class<? extends Throwable>> exceptionClasses = new ArrayList<Class<? extends Throwable>>();
+ @XmlTransient
private Predicate handledPolicy;
@XmlTransient
private Predicate continuedPolicy;
@@ -104,10 +106,12 @@ public class OnExceptionDefinition extends ProcessorDefinition<OnExceptionDefini
public OnExceptionDefinition(List<Class<? extends Throwable>> exceptionClasses) {
this.exceptions.addAll(exceptionClasses.stream().map(Class::getName).collect(Collectors.toList()));
+ this.exceptionClasses.addAll(exceptionClasses);
}
public OnExceptionDefinition(Class<? extends Throwable> exceptionType) {
this.exceptions.add(exceptionType.getName());
+ this.exceptionClasses.add(exceptionType);
}
public void setRouteScoped(boolean routeScoped) {
@@ -191,6 +195,11 @@ public class OnExceptionDefinition extends ProcessorDefinition<OnExceptionDefini
setOnRedeliveryFromRedeliveryRef(routeContext);
setOnExceptionOccurredFromOnExceptionOccurredRef(routeContext);
+ // load exception classes
+ if ((exceptionClasses == null || exceptionClasses.isEmpty()) && exceptions != null && !exceptions.isEmpty()) {
+ exceptionClasses = createExceptionClasses(routeContext.getCamelContext().getClassResolver());
+ }
+
// must validate configuration before creating processor
validateConfiguration();
@@ -217,7 +226,9 @@ public class OnExceptionDefinition extends ProcessorDefinition<OnExceptionDefini
public CatchProcessor createProcessor(RouteContext routeContext) throws Exception {
// load exception classes
List<Class<? extends Throwable>> exceptionClasses = null;
- if (exceptions != null && !exceptions.isEmpty()) {
+ if (this.exceptionClasses != null && !this.exceptionClasses.isEmpty()) {
+ exceptionClasses = this.exceptionClasses;
+ } else if (exceptions != null && !exceptions.isEmpty()) {
exceptionClasses = createExceptionClasses(routeContext.getCamelContext().getClassResolver());
}
@@ -281,6 +292,7 @@ public class OnExceptionDefinition extends ProcessorDefinition<OnExceptionDefini
@Override
public OnExceptionDefinition onException(Class<? extends Throwable> exceptionType) {
getExceptions().add(exceptionType.getName());
+ getExceptionClasses().add(exceptionType);
return this;
}
@@ -861,6 +873,14 @@ public class OnExceptionDefinition extends ProcessorDefinition<OnExceptionDefini
return true;
}
+ public List<Class<? extends Throwable>> getExceptionClasses() {
+ return exceptionClasses;
+ }
+
+ public void setExceptionClasses(List<Class<? extends Throwable>> exceptionClasses) {
+ this.exceptionClasses = exceptionClasses;
+ }
+
public List<String> getExceptions() {
return exceptions;
}
diff --git a/camel-core/src/main/java/org/apache/camel/processor/ErrorHandlerSupport.java b/camel-core/src/main/java/org/apache/camel/processor/ErrorHandlerSupport.java
index 27bfe3f..b505c62 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/ErrorHandlerSupport.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/ErrorHandlerSupport.java
@@ -16,21 +16,18 @@
*/
package org.apache.camel.processor;
-import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
-import org.apache.camel.RuntimeCamelException;
import org.apache.camel.model.OnExceptionDefinition;
import org.apache.camel.model.ProcessorDefinitionHelper;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.processor.exceptionpolicy.DefaultExceptionPolicyStrategy;
import org.apache.camel.processor.exceptionpolicy.ExceptionPolicyKey;
import org.apache.camel.processor.exceptionpolicy.ExceptionPolicyStrategy;
-import org.apache.camel.spi.ClassResolver;
import org.apache.camel.spi.RouteContext;
import org.apache.camel.support.ChildServiceSupport;
import org.slf4j.Logger;
@@ -56,37 +53,20 @@ public abstract class ErrorHandlerSupport extends ChildServiceSupport implements
addChildService(errorHandler);
}
- List<Class<? extends Throwable>> list = null;
- if (exceptionType.getExceptions() != null && !exceptionType.getExceptions().isEmpty()) {
- list = createExceptionClasses(exceptionType, routeContext.getCamelContext().getClassResolver());
- for (Class<? extends Throwable> clazz : list) {
- String routeId = null;
- // only get the route id, if the exception type is route scoped
- if (exceptionType.isRouteScoped()) {
- RouteDefinition route = ProcessorDefinitionHelper.getRoute(exceptionType);
- if (route != null) {
- routeId = route.getId();
- }
- }
- ExceptionPolicyKey key = new ExceptionPolicyKey(routeId, clazz, exceptionType.getOnWhen());
- exceptionPolicies.put(key, exceptionType);
- }
- }
}
- }
-
- protected List<Class<? extends Throwable>> createExceptionClasses(OnExceptionDefinition exceptionType, ClassResolver resolver) {
- List<String> list = exceptionType.getExceptions();
- List<Class<? extends Throwable>> answer = new ArrayList<>(list.size());
- for (String name : list) {
- try {
- Class<? extends Throwable> type = resolver.resolveMandatoryClass(name, Throwable.class);
- answer.add(type);
- } catch (ClassNotFoundException e) {
- throw new RuntimeCamelException(e);
+ List<Class<? extends Throwable>> list = exceptionType.getExceptionClasses();
+ for (Class<? extends Throwable> clazz : list) {
+ String routeId = null;
+ // only get the route id, if the exception type is route scoped
+ if (exceptionType.isRouteScoped()) {
+ RouteDefinition route = ProcessorDefinitionHelper.getRoute(exceptionType);
+ if (route != null) {
+ routeId = route.getId();
+ }
}
+ ExceptionPolicyKey key = new ExceptionPolicyKey(routeId, clazz, exceptionType.getOnWhen());
+ exceptionPolicies.put(key, exceptionType);
}
- return answer;
}
/**