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 50b2fc5a198 CAMEL-20663: camel-main - Reading properties file should 
support mixed case and dash vs no-dash style all combinations (#13779)
50b2fc5a198 is described below

commit 50b2fc5a19844ca1de95095db645876fa893fdb3
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Sat Apr 13 09:35:37 2024 +0200

    CAMEL-20663: camel-main - Reading properties file should support mixed case 
and dash vs no-dash style all combinations (#13779)
---
 .../org/apache/camel/main/BaseMainSupport.java     | 41 +++++++++++-----------
 .../main/MainSupervisingRouteControllerTest.java   | 40 +++++++++++++++++++++
 .../src/test/resources/route-controller.properties | 24 +++++++++++++
 3 files changed, 85 insertions(+), 20 deletions(-)

diff --git 
a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java 
b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index 810b445b657..74b4ca1a78b 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -110,6 +110,7 @@ import static 
org.apache.camel.main.MainHelper.setPropertiesOnTarget;
 import static org.apache.camel.main.MainHelper.validateOptionAndValue;
 import static org.apache.camel.util.LocationHelper.locationSummary;
 import static org.apache.camel.util.StringHelper.matches;
+import static org.apache.camel.util.StringHelper.startsWithIgnoreCase;
 
 /**
  * Base class for main implementations to allow bootstrapping Camel in 
standalone mode.
@@ -986,121 +987,121 @@ public abstract class BaseMainSupport extends 
BaseService {
         OrderedLocationProperties routeControllerProperties = new 
OrderedLocationProperties();
         for (String key : prop.stringPropertyNames()) {
             String loc = prop.getLocation(key);
-            if (key.startsWith("camel.context.")) {
+            if (startsWithIgnoreCase(key, "camel.context.")) {
                 // grab the value
                 String value = prop.getProperty(key);
                 String option = key.substring(14);
                 validateOptionAndValue(key, option, value);
                 contextProperties.put(loc, optionKey(option), value);
-            } else if (key.startsWith("camel.resilience4j.")) {
+            } else if (startsWithIgnoreCase(key, "camel.resilience4j.")) {
                 // grab the value
                 String value = prop.getProperty(key);
                 String option = key.substring(19);
                 validateOptionAndValue(key, option, value);
                 resilience4jProperties.put(loc, optionKey(option), value);
-            } else if (key.startsWith("camel.faulttolerance.")) {
+            } else if (startsWithIgnoreCase(key, "camel.faulttolerance.")) {
                 // grab the value
                 String value = prop.getProperty(key);
                 String option = key.substring(21);
                 validateOptionAndValue(key, option, value);
                 faultToleranceProperties.put(loc, optionKey(option), value);
-            } else if (key.startsWith("camel.rest.")) {
+            } else if (startsWithIgnoreCase(key, "camel.rest.")) {
                 // grab the value
                 String value = prop.getProperty(key);
                 String option = key.substring(11);
                 validateOptionAndValue(key, option, value);
                 restProperties.put(loc, optionKey(option), value);
-            } else if (key.startsWith("camel.vault.")) {
+            } else if (startsWithIgnoreCase(key, "camel.vault.")) {
                 // grab the value
                 String value = prop.getProperty(key);
                 String option = key.substring(12);
                 validateOptionAndValue(key, option, value);
                 vaultProperties.put(loc, optionKey(option), value);
-            } else if (key.startsWith("camel.threadpool.")) {
+            } else if (startsWithIgnoreCase(key, "camel.threadpool.")) {
                 // grab the value
                 String value = prop.getProperty(key);
                 String option = key.substring(17);
                 validateOptionAndValue(key, option, value);
                 threadPoolProperties.put(loc, optionKey(option), value);
-            } else if (key.startsWith("camel.health.")) {
+            } else if (startsWithIgnoreCase(key, "camel.health.")) {
                 // grab the value
                 String value = prop.getProperty(key);
                 String option = key.substring(13);
                 validateOptionAndValue(key, option, value);
                 healthProperties.put(loc, optionKey(option), value);
-            } else if (key.startsWith("camel.lra.")) {
+            } else if (startsWithIgnoreCase(key, "camel.lra.")) {
                 // grab the value
                 String value = prop.getProperty(key);
                 String option = key.substring(10);
                 validateOptionAndValue(key, option, value);
                 lraProperties.put(loc, optionKey(option), value);
-            } else if (key.startsWith("camel.opentelemetry.")) {
+            } else if (startsWithIgnoreCase(key, "camel.opentelemetry.")) {
                 // grab the value
                 String value = prop.getProperty(key);
                 String option = key.substring(20);
                 validateOptionAndValue(key, option, value);
                 otelProperties.put(loc, optionKey(option), value);
-            } else if (key.startsWith("camel.metrics.")) {
+            } else if (startsWithIgnoreCase(key, "camel.metrics.")) {
                 // grab the value
                 String value = prop.getProperty(key);
                 String option = key.substring(14);
                 validateOptionAndValue(key, option, value);
                 metricsProperties.put(loc, optionKey(option), value);
-            } else if (key.startsWith("camel.routeTemplate")) {
+            } else if (startsWithIgnoreCase(key, "camel.routeTemplate")) {
                 // grab the value
                 String value = prop.getProperty(key);
                 String option = key.substring(19);
                 validateOptionAndValue(key, option, value);
                 routeTemplateProperties.put(loc, optionKey(option), value);
-            } else if (key.startsWith("camel.devConsole.")) {
+            } else if (startsWithIgnoreCase(key, "camel.devConsole.")) {
                 // grab the value
                 String value = prop.getProperty(key);
                 String option = key.substring(17);
                 validateOptionAndValue(key, option, value);
                 devConsoleProperties.put(loc, optionKey(option), value);
-            } else if (key.startsWith("camel.variable.")) {
+            } else if (startsWithIgnoreCase(key, "camel.variable.")) {
                 // grab the value
                 String value = prop.getProperty(key);
                 String option = key.substring(15);
                 validateOptionAndValue(key, option, value);
                 variableProperties.put(loc, optionKey(option), value);
-            } else if (key.startsWith("camel.beans.")) {
+            } else if (startsWithIgnoreCase(key, "camel.beans.")) {
                 // grab the value
                 String value = prop.getProperty(key);
                 String option = key.substring(12);
                 validateOptionAndValue(key, option, value);
                 beansProperties.put(loc, optionKey(option), value);
-            } else if (key.startsWith("camel.globalOptions.")) {
+            } else if (startsWithIgnoreCase(key, "camel.globalOptions.")) {
                 // grab the value
                 String value = prop.getProperty(key);
                 String option = key.substring(20);
                 validateOptionAndValue(key, option, value);
                 globalOptions.put(loc, optionKey(option), value);
-            } else if (key.startsWith("camel.server.")) {
+            } else if (startsWithIgnoreCase(key, "camel.server.")) {
                 // grab the value
                 String value = prop.getProperty(key);
                 String option = key.substring(13);
                 validateOptionAndValue(key, option, value);
                 httpServerProperties.put(loc, optionKey(option), value);
-            } else if (key.startsWith("camel.ssl.")) {
+            } else if (startsWithIgnoreCase(key, "camel.ssl.")) {
                 // grab the value
                 String value = prop.getProperty(key);
                 String option = key.substring(10);
                 validateOptionAndValue(key, option, value);
                 sslProperties.put(loc, optionKey(option), value);
-            } else if (key.startsWith("camel.debug.")) {
+            } else if (startsWithIgnoreCase(key, "camel.debug.")) {
                 // grab the value
                 String value = prop.getProperty(key);
                 String option = key.substring(12);
                 validateOptionAndValue(key, option, value);
                 debuggerProperties.put(loc, optionKey(option), value);
-            } else if (key.startsWith("camel.trace.")) {
+            } else if (startsWithIgnoreCase(key, "camel.trace.")) {
                 // grab the value
                 String value = prop.getProperty(key);
                 String option = key.substring(12);
                 validateOptionAndValue(key, option, value);
                 tracerProperties.put(loc, optionKey(option), value);
-            } else if (key.startsWith("camel.routeController.")) {
+            } else if (startsWithIgnoreCase(key, "camel.routeController.")) {
                 // grab the value
                 String value = prop.getProperty(key);
                 String option = key.substring(22);
diff --git 
a/core/camel-main/src/test/java/org/apache/camel/main/MainSupervisingRouteControllerTest.java
 
b/core/camel-main/src/test/java/org/apache/camel/main/MainSupervisingRouteControllerTest.java
index 4c3d5673f91..c90db7f41cb 100644
--- 
a/core/camel-main/src/test/java/org/apache/camel/main/MainSupervisingRouteControllerTest.java
+++ 
b/core/camel-main/src/test/java/org/apache/camel/main/MainSupervisingRouteControllerTest.java
@@ -119,6 +119,46 @@ public class MainSupervisingRouteControllerTest {
         main.stop();
     }
 
+    @Test
+    public void testMainApplicationProperties() throws Exception {
+        // lets make a simple route
+        Main main = new Main();
+        
main.setDefaultPropertyPlaceholderLocation("classpath:route-controller.properties");
+        main.configure().addRoutesBuilder(new MyRoute());
+        main.start();
+
+        MockEndpoint mock = main.getCamelContext().getEndpoint("mock:foo", 
MockEndpoint.class);
+        mock.expectedMinimumMessageCount(3);
+
+        MockEndpoint mock2 = main.getCamelContext().getEndpoint("mock:cheese", 
MockEndpoint.class);
+        mock2.expectedMessageCount(0);
+
+        MockEndpoint mock3 = main.getCamelContext().getEndpoint("mock:cake", 
MockEndpoint.class);
+        mock3.expectedMessageCount(0);
+
+        MockEndpoint mock4 = main.getCamelContext().getEndpoint("mock:bar", 
MockEndpoint.class);
+        mock4.expectedMessageCount(0);
+
+        MockEndpoint.assertIsSatisfied(5, TimeUnit.SECONDS, mock, mock2, 
mock3, mock4);
+
+        assertEquals("Started", 
main.camelContext.getRouteController().getRouteStatus("foo").toString());
+        // cheese was not able to start
+        assertEquals("Stopped", 
main.camelContext.getRouteController().getRouteStatus("cheese").toString());
+        // cake was not able to start
+        assertEquals("Stopped", 
main.camelContext.getRouteController().getRouteStatus("cake").toString());
+
+        SupervisingRouteController src = (SupervisingRouteController) 
main.camelContext.getRouteController();
+        Throwable e = src.getRestartException("cake");
+        assertNotNull(e);
+        assertEquals("Cannot start", e.getMessage());
+        assertInstanceOf(IllegalArgumentException.class, e);
+
+        // bar is no auto startup
+        assertEquals("Stopped", 
main.camelContext.getRouteController().getRouteStatus("bar").toString());
+
+        main.stop();
+    }
+
     private class MyRoute extends RouteBuilder {
         @Override
         public void configure() throws Exception {
diff --git a/core/camel-main/src/test/resources/route-controller.properties 
b/core/camel-main/src/test/resources/route-controller.properties
new file mode 100644
index 00000000000..93ca0c1e162
--- /dev/null
+++ b/core/camel-main/src/test/resources/route-controller.properties
@@ -0,0 +1,24 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+# test with different case and dash vs no-dash
+camel.routecontroller.enabled = true
+camel.routecontroller.back-off-delay = 25
+camel.routeController.backOffMaxAttempts = 3
+camel.route-controller.initial-delay = 1000
+camel.routeController.threadpoolsize = 2
+camel.routecontroller.exclude-routes = timer*

Reply via email to