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

commit cd169175b396db3066184d8cc349958a595489ad
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Apr 14 15:17:54 2022 +0200

    CAMEL-17969: properties component - Add lookup listener so we can cature 
from where a property placeholder was from.
---
 .../component/properties/DefaultPropertiesParser.java    | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git 
a/core/camel-base/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
 
b/core/camel-base/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
index 2ad37754af3..ef2f75bbd08 100644
--- 
a/core/camel-base/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
+++ 
b/core/camel-base/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
@@ -20,6 +20,7 @@ import java.util.HashSet;
 import java.util.Properties;
 import java.util.Set;
 
+import org.apache.camel.PropertiesLookupListener;
 import org.apache.camel.spi.PropertiesFunction;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.StringHelper;
@@ -313,6 +314,7 @@ public class DefaultPropertiesParser implements 
PropertiesParser {
             if (local != null) {
                 value = local.getProperty(key);
                 if (value != null) {
+                    onLookup(key, value, "LocalProperties");
                     log.debug("Found local property: {} with value: {} to be 
used.", key, value);
                 }
             }
@@ -328,12 +330,14 @@ public class DefaultPropertiesParser implements 
PropertiesParser {
             if (value == null && envMode == 
PropertiesComponent.ENVIRONMENT_VARIABLES_MODE_OVERRIDE) {
                 value = lookupEnvironmentVariable(key);
                 if (value != null) {
+                    onLookup(key, value, "ENV");
                     log.debug("Found an OS environment property: {} with 
value: {} to be used.", key, value);
                 }
             }
             if (value == null && sysMode == 
PropertiesComponent.SYSTEM_PROPERTIES_MODE_OVERRIDE) {
                 value = System.getProperty(key);
                 if (value != null) {
+                    onLookup(key, value, "SYS");
                     log.debug("Found a JVM system property: {} with value: {} 
to be used.", key, value);
                 }
             }
@@ -348,12 +352,14 @@ public class DefaultPropertiesParser implements 
PropertiesParser {
             if (value == null && envMode == 
PropertiesComponent.ENVIRONMENT_VARIABLES_MODE_FALLBACK) {
                 value = lookupEnvironmentVariable(key);
                 if (value != null) {
+                    onLookup(key, value, "ENV");
                     log.debug("Found an OS environment property: {} with 
value: {} to be used.", key, value);
                 }
             }
             if (value == null && sysMode == 
PropertiesComponent.SYSTEM_PROPERTIES_MODE_FALLBACK) {
                 value = System.getProperty(key);
                 if (value != null) {
+                    onLookup(key, value, "SYS");
                     log.debug("Found a JVM system property: {} with value: {} 
to be used.", key, value);
                 }
             }
@@ -367,6 +373,16 @@ public class DefaultPropertiesParser implements 
PropertiesParser {
         }
     }
 
+    private void onLookup(String name, String value, String source) {
+        for (PropertiesLookupListener listener : 
propertiesComponent.getPropertiesLookupListeners()) {
+            try {
+                listener.onLookup(name, value, source);
+            } catch (Exception e) {
+                // ignore
+            }
+        }
+    }
+
     /**
      * This inner class is the definition of a property used in a string
      */

Reply via email to