This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-4.8.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-4.8.x by this push:
     new 1c5c399bfe1 CAMEL-21404: camel-core - Routes loader should skip 
failing if file has no extension and its optional. (#16123)
1c5c399bfe1 is described below

commit 1c5c399bfe194e63b023ad79629c3d4f7a7cc47a
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Wed Oct 30 12:14:32 2024 +0100

    CAMEL-21404: camel-core - Routes loader should skip failing if file has no 
extension and its optional. (#16123)
---
 .../org/apache/camel/impl/engine/DefaultRoutesLoader.java   | 13 ++++++-------
 .../main/java/org/apache/camel/main/RoutesConfigurer.java   | 13 ++++++-------
 2 files changed, 12 insertions(+), 14 deletions(-)

diff --git 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultRoutesLoader.java
 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultRoutesLoader.java
index 309d8bb4047..7fcd12ab306 100644
--- 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultRoutesLoader.java
+++ 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultRoutesLoader.java
@@ -306,20 +306,19 @@ public class DefaultRoutesLoader extends ServiceSupport 
implements RoutesLoader,
     }
 
     protected RoutesBuilderLoader resolveRoutesBuilderLoader(Resource 
resource, boolean optional) throws Exception {
+        RoutesBuilderLoader answer = null;
+
         // the loader to use is derived from the file extension
         final String extension = FileUtil.onlyExt(resource.getLocation(), 
false);
 
-        if (ObjectHelper.isEmpty(extension)) {
-            throw new IllegalArgumentException(
-                    "Unable to determine file extension for resource: " + 
resource.getLocation());
+        if (extension != null) {
+            answer = getRoutesLoader(extension);
         }
-
-        RoutesBuilderLoader loader = getRoutesLoader(extension);
-        if (!optional && loader == null) {
+        if (!optional && answer == null) {
             throw new IllegalArgumentException(
                     "Cannot find RoutesBuilderLoader in classpath supporting 
file extension: " + extension);
         }
-        return loader;
+        return answer;
     }
 
 }
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 5695fe508ef..c7299e1eab0 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
@@ -37,7 +37,6 @@ import org.apache.camel.spi.RoutesLoader;
 import org.apache.camel.support.OrderedComparator;
 import org.apache.camel.support.PluginHelper;
 import org.apache.camel.util.FileUtil;
-import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.StopWatch;
 import org.apache.camel.util.TimeUtils;
 import org.slf4j.Logger;
@@ -440,16 +439,16 @@ public class RoutesConfigurer {
             CamelContext camelContext, Resource resource,
             boolean optional)
             throws Exception {
+
+        RoutesBuilderLoader answer = null;
+
         // the loader to use is derived from the file extension
         final String extension = FileUtil.onlyExt(resource.getLocation(), 
false);
 
-        if (ObjectHelper.isEmpty(extension)) {
-            throw new IllegalArgumentException(
-                    "Unable to determine file extension for resource: " + 
resource.getLocation());
+        if (extension != null) {
+            RoutesLoader loader = PluginHelper.getRoutesLoader(camelContext);
+            answer = loader.getRoutesLoader(extension);
         }
-
-        RoutesLoader loader = PluginHelper.getRoutesLoader(camelContext);
-        RoutesBuilderLoader answer = loader.getRoutesLoader(extension);
         if (!optional && answer == null) {
             throw new IllegalArgumentException(
                     "Cannot find RoutesBuilderLoader in classpath supporting 
file extension: " + extension);

Reply via email to