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
The following commit(s) were added to refs/heads/main by this push:
new 5a36384bf96 CAMEL-21139: camel-jbang - Export to Q or SB should work
with ignore-loading-error option
5a36384bf96 is described below
commit 5a36384bf96458a0b915f419c070b15a7891f32b
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Aug 29 11:17:25 2024 +0200
CAMEL-21139: camel-jbang - Export to Q or SB should work with
ignore-loading-error option
---
.../apache/camel/main/DefaultRoutesCollector.java | 2 +-
.../org/apache/camel/main/RoutesConfigurer.java | 107 +++++++++++++++------
2 files changed, 81 insertions(+), 28 deletions(-)
diff --git
a/core/camel-main/src/main/java/org/apache/camel/main/DefaultRoutesCollector.java
b/core/camel-main/src/main/java/org/apache/camel/main/DefaultRoutesCollector.java
index 7df07acd9a5..2a93cddcc03 100644
---
a/core/camel-main/src/main/java/org/apache/camel/main/DefaultRoutesCollector.java
+++
b/core/camel-main/src/main/java/org/apache/camel/main/DefaultRoutesCollector.java
@@ -207,7 +207,7 @@ public class DefaultRoutesCollector implements
RoutesCollector {
}
} catch (Exception e) {
if (isIgnoreLoadingError()) {
- log.warn("Loading resources error: {} due to: {}. This
exception is ignored.", accepted, e.getMessage());
+ log.warn("Ignore Loading error: {} due to: {}. This exception
is ignored.", accepted, e.getMessage());
} else {
throw RuntimeCamelException.wrapRuntimeException(e);
}
diff --git
a/core/camel-main/src/main/java/org/apache/camel/main/RoutesConfigurer.java
b/core/camel-main/src/main/java/org/apache/camel/main/RoutesConfigurer.java
index f2e7dbe0a3f..5695fe508ef 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/RoutesConfigurer.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/RoutesConfigurer.java
@@ -164,15 +164,24 @@ public class RoutesConfigurer {
if (getRoutesBuilderClasses() != null) {
String[] routeClasses = getRoutesBuilderClasses().split(",");
for (String routeClass : routeClasses) {
- Class<RoutesBuilder> routeClazz =
camelContext.getClassResolver().resolveClass(routeClass, RoutesBuilder.class);
- if (routeClazz == null) {
- LOG.warn("Unable to resolve class: {}", routeClass);
- continue;
- }
+ try {
+ Class<RoutesBuilder> routeClazz
+ =
camelContext.getClassResolver().resolveClass(routeClass, RoutesBuilder.class);
+ if (routeClazz == null) {
+ LOG.warn("Unable to resolve class: {}", routeClass);
+ continue;
+ }
- // lets use Camel's injector so the class has some support for
dependency injection
- RoutesBuilder builder =
camelContext.getInjector().newInstance(routeClazz);
- routes.add(builder);
+ // lets use Camel's injector so the class has some support
for dependency injection
+ RoutesBuilder builder =
camelContext.getInjector().newInstance(routeClazz);
+ routes.add(builder);
+ } catch (Exception e) {
+ if (isIgnoreLoadingError()) {
+ LOG.warn("Ignore loading error due to: {}. This
exception is ignored.", e.getMessage());
+ } else {
+ throw RuntimeCamelException.wrapRuntimeException(e);
+ }
+ }
}
}
@@ -181,11 +190,19 @@ public class RoutesConfigurer {
Set<Class<?>> set =
PluginHelper.getPackageScanClassResolver(camelContext)
.findImplementations(RoutesBuilder.class, pkgs);
for (Class<?> routeClazz : set) {
- Object builder =
camelContext.getInjector().newInstance(routeClazz);
- if (builder instanceof RoutesBuilder routesBuilder) {
- routes.add(routesBuilder);
- } else {
- LOG.warn("Class {} is not a RouteBuilder class",
routeClazz);
+ try {
+ Object builder =
camelContext.getInjector().newInstance(routeClazz);
+ if (builder instanceof RoutesBuilder routesBuilder) {
+ routes.add(routesBuilder);
+ } else {
+ LOG.warn("Class {} is not a RouteBuilder class",
routeClazz);
+ }
+ } catch (Exception e) {
+ if (isIgnoreLoadingError()) {
+ LOG.warn("Ignore loading error due to: {}. This
exception is ignored.", e.getMessage());
+ } else {
+ throw RuntimeCamelException.wrapRuntimeException(e);
+ }
}
}
}
@@ -219,7 +236,11 @@ public class RoutesConfigurer {
getRoutesIncludePattern(),
TimeUtils.printDuration(watch.taken(), true));
}
} catch (Exception e) {
- throw RuntimeCamelException.wrapRuntimeException(e);
+ if (isIgnoreLoadingError()) {
+ LOG.warn("Ignore loading error due to: {}. This exception
is ignored.", e.getMessage());
+ } else {
+ throw RuntimeCamelException.wrapRuntimeException(e);
+ }
}
}
@@ -227,8 +248,16 @@ public class RoutesConfigurer {
// lets use Camel's bean post processor on any existing route
builder classes
// so the instance has some support for dependency injection
for (RoutesBuilder routeBuilder : routes) {
-
getBeanPostProcessor().postProcessBeforeInitialization(routeBuilder,
routeBuilder.getClass().getName());
-
getBeanPostProcessor().postProcessAfterInitialization(routeBuilder,
routeBuilder.getClass().getName());
+ try {
+
getBeanPostProcessor().postProcessBeforeInitialization(routeBuilder,
routeBuilder.getClass().getName());
+
getBeanPostProcessor().postProcessAfterInitialization(routeBuilder,
routeBuilder.getClass().getName());
+ } catch (Exception e) {
+ if (isIgnoreLoadingError()) {
+ LOG.warn("Ignore loading error due to: {}. This
exception is ignored.", e.getMessage());
+ } else {
+ throw RuntimeCamelException.wrapRuntimeException(e);
+ }
+ }
}
}
@@ -242,20 +271,44 @@ public class RoutesConfigurer {
// first add the routes configurations as they are globally for all
routes
for (RoutesBuilder builder : routes) {
- if (builder instanceof RouteConfigurationsBuilder rcb) {
- LOG.debug("Adding routes configurations into CamelContext from
RouteConfigurationsBuilder: {}", rcb);
- camelContext.addRoutesConfigurations(rcb);
+ try {
+ if (builder instanceof RouteConfigurationsBuilder rcb) {
+ LOG.debug("Adding routes configurations into CamelContext
from RouteConfigurationsBuilder: {}", rcb);
+ camelContext.addRoutesConfigurations(rcb);
+ }
+ } catch (Exception e) {
+ if (isIgnoreLoadingError()) {
+ LOG.warn("Ignore loading error due to: {}. This exception
is ignored.", e.getMessage());
+ } else {
+ throw RuntimeCamelException.wrapRuntimeException(e);
+ }
}
}
// then add the routes
for (RoutesBuilder builder : routes) {
- LOG.debug("Adding routes into CamelContext from RoutesBuilder:
{}", builder);
- camelContext.addRoutes(builder);
+ try {
+ LOG.debug("Adding routes into CamelContext from RoutesBuilder:
{}", builder);
+ camelContext.addRoutes(builder);
+ } catch (Exception e) {
+ if (isIgnoreLoadingError()) {
+ LOG.warn("Ignore loading error due to: {}. This exception
is ignored.", e.getMessage());
+ } else {
+ throw RuntimeCamelException.wrapRuntimeException(e);
+ }
+ }
}
// then add templated routes last
for (RoutesBuilder builder : routes) {
- LOG.debug("Adding templated routes into CamelContext from
RoutesBuilder: {}", builder);
- camelContext.addTemplatedRoutes(builder);
+ try {
+ LOG.debug("Adding templated routes into CamelContext from
RoutesBuilder: {}", builder);
+ camelContext.addTemplatedRoutes(builder);
+ } catch (Exception e) {
+ if (isIgnoreLoadingError()) {
+ LOG.warn("Ignore loading error due to: {}. This exception
is ignored.", e.getMessage());
+ } else {
+ throw RuntimeCamelException.wrapRuntimeException(e);
+ }
+ }
}
}
@@ -360,8 +413,8 @@ public class RoutesConfigurer {
try {
extLoader.preParseRoutes(files);
} catch (Exception e) {
- if (ignoreLoadingError) {
- LOG.warn("Loading resources error: {} due to: {}. This
exception is ignored.", files, e.getMessage());
+ if (isIgnoreLoadingError()) {
+ LOG.warn("Ignore loading error: {} due to: {}. This
exception is ignored.", files, e.getMessage());
} else {
throw e;
}
@@ -371,8 +424,8 @@ public class RoutesConfigurer {
try {
loader.preParseRoute(resource);
} catch (Exception e) {
- if (ignoreLoadingError) {
- LOG.warn("Loading resources error: {} due to: {}.
This exception is ignored.", resource,
+ if (isIgnoreLoadingError()) {
+ LOG.warn("Ignore loading error: {} due to: {}.
This exception is ignored.", resource,
e.getMessage());
} else {
throw e;