This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch observefix in repository https://gitbox.apache.org/repos/asf/camel.git
commit 562b1b12431b1de00a9a4e8ef3b2406b0f40b4a8 Author: Claus Ibsen <[email protected]> AuthorDate: Tue Nov 18 14:12:35 2025 +0100 CAMEL-22695: camel-jbang - Fix --observe to load always regardless if there is a custom application.properties. --- .../org/apache/camel/main/BaseMainSupport.java | 32 +++++++++++++++++++--- .../java/org/apache/camel/main/MainConstants.java | 2 -- 2 files changed, 28 insertions(+), 6 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 140a3d48ee29..8e2914eb6e38 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 @@ -109,6 +109,7 @@ import org.apache.camel.support.startup.EnvStartupCondition; import org.apache.camel.support.startup.FileStartupCondition; import org.apache.camel.support.startup.LoggingStartupStepRecorder; import org.apache.camel.util.FileUtil; +import org.apache.camel.util.IOHelper; import org.apache.camel.util.ObjectHelper; import org.apache.camel.util.OrderedLocationProperties; import org.apache.camel.util.OrderedProperties; @@ -147,9 +148,7 @@ public abstract class BaseMainSupport extends BaseService { protected final OrderedLocationProperties wildcardProperties = new OrderedLocationProperties(); protected RoutesCollector routesCollector = new DefaultRoutesCollector(); protected String propertyPlaceholderLocations; - protected String defaultPropertyPlaceholderLocation - = MainConstants.DEFAULT_PROPERTY_PLACEHOLDER_LOCATION + "," - + MainConstants.DEFAULT_OBSERVABILITY_SERVICES_PROPERTY_LOCATION; + protected String defaultPropertyPlaceholderLocation = MainConstants.DEFAULT_PROPERTY_PLACEHOLDER_LOCATION; protected Properties initialProperties; protected Properties overrideProperties; protected boolean standalone = true; @@ -445,6 +444,17 @@ public abstract class BaseMainSupport extends BaseService { } } + // load optional observability configuration from inside JAR + final Properties osp = tryLoadObservabilityProperties(camelContext, "observability-services.properties"); + if (!osp.isEmpty()) { + // only add observability properties if not already defined as initial + osp.forEach((k, v) -> { + if (!initialProperties.containsKey(k)) { + initialProperties.setProperty(k.toString(), v.toString()); + } + }); + } + final Properties ip = tryLoadProperties(initialProperties, MainConstants.INITIAL_PROPERTIES_LOCATION, camelContext); if (ip != null) { pc.setInitialProperties(ip); @@ -480,6 +490,20 @@ public abstract class BaseMainSupport extends BaseService { return ip; } + private static Properties tryLoadObservabilityProperties(CamelContext camelContext, String location) { + Properties p = new Properties(); + InputStream is = null; + try { + is = ResourceHelper.resolveResourceAsInputStream(camelContext, location); + p.load(is); + } catch (Exception e) { + // ignore + } finally { + IOHelper.close(is); + } + return p; + } + private static Properties tryLoadCloudProperties( Properties overridProperties, String cloudPropertiesLocations) { final OrderedLocationProperties cp = new OrderedLocationProperties(); @@ -488,7 +512,7 @@ public abstract class BaseMainSupport extends BaseService { for (String loc : locations) { Path confPath = Paths.get(loc); if (Files.exists(confPath) && Files.isDirectory(confPath)) { - Files.walkFileTree(confPath, new SimpleFileVisitor<Path>() { + Files.walkFileTree(confPath, new SimpleFileVisitor<>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { if (!Files.isDirectory(file)) { diff --git a/core/camel-main/src/main/java/org/apache/camel/main/MainConstants.java b/core/camel-main/src/main/java/org/apache/camel/main/MainConstants.java index 03d7d7ab360a..0304faa0acef 100644 --- a/core/camel-main/src/main/java/org/apache/camel/main/MainConstants.java +++ b/core/camel-main/src/main/java/org/apache/camel/main/MainConstants.java @@ -19,8 +19,6 @@ package org.apache.camel.main; public final class MainConstants { public static final String DEFAULT_PROPERTY_PLACEHOLDER_LOCATION = "classpath:application.properties;optional=true"; - public static final String DEFAULT_OBSERVABILITY_SERVICES_PROPERTY_LOCATION - = "classpath:observability-services.properties;optional=true"; public static final String INITIAL_PROPERTIES_LOCATION = "camel.main.initial-properties-location"; public static final String OVERRIDE_PROPERTIES_LOCATION = "camel.main.override-properties-location"; public static final String CLOUD_PROPERTIES_LOCATION = "camel.main.cloud-properties-location";
