You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/03/06 14:29:49 UTC

[camel] branch bind updated: CAMEL-13288: Properties component lookup ENV should use uppercase keys and fallback to use underscore instead of dash.

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

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


The following commit(s) were added to refs/heads/bind by this push:
     new 87cb426  CAMEL-13288: Properties component lookup ENV should use uppercase keys and fallback to use underscore instead of dash.
87cb426 is described below

commit 87cb426a21050241b5695e3e617c91c7de797a91
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Mar 6 15:29:32 2019 +0100

    CAMEL-13288: Properties component lookup ENV should use uppercase keys and fallback to use underscore instead of dash.
---
 .../properties/DefaultPropertiesParser.java        | 33 ++++++++++++----------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java b/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
index 638cda7..fb793ee 100644
--- a/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
+++ b/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
@@ -318,14 +318,7 @@ public class DefaultPropertiesParser implements AugmentedPropertyNameAwareProper
                 }
             }
             if (value == null && envMode == PropertiesComponent.ENVIRONMENT_VARIABLES_MODE_OVERRIDE) {
-                // lookup OS env with upper case key
-                String upperKey = key.toUpperCase();
-                value = System.getenv(upperKey);
-                // some OS do not support dashes in keys, so replace with underscore
-                if (value == null) {
-                    String noDashKey = upperKey.replace('-', '_');
-                    value = System.getenv(noDashKey);
-                }
+                value = lookupEnvironmentVariable(key);
                 if (value != null) {
                     log.debug("Found a environment property: {} with value: {} to be used.", key, value);
                 }
@@ -346,13 +339,7 @@ public class DefaultPropertiesParser implements AugmentedPropertyNameAwareProper
             }
             if (value == null && envMode == PropertiesComponent.ENVIRONMENT_VARIABLES_MODE_FALLBACK) {
                 // lookup OS env with upper case key
-                String upperKey = key.toUpperCase();
-                value = System.getenv(upperKey);
-                // some OS do not support dashes in keys, so replace with underscore
-                if (value == null) {
-                    String noDashKey = upperKey.replace('-', '_');
-                    value = System.getenv(noDashKey);
-                }
+                value = lookupEnvironmentVariable(key);
                 if (value != null) {
                     log.debug("Found a environment property: {} with value: {} to be used.", key, value);
                 }
@@ -363,6 +350,22 @@ public class DefaultPropertiesParser implements AugmentedPropertyNameAwareProper
     }
 
     /**
+     * Lookup the OS environment variable in a safe manner by
+     * using upper case keys and underscore instead of dash.
+     */
+    private static String lookupEnvironmentVariable(String key) {
+        // lookup OS env with upper case key
+        String upperKey = key.toUpperCase();
+        String value = System.getenv(upperKey);
+        // some OS do not support dashes in keys, so replace with underscore
+        if (value == null) {
+            String noDashKey = upperKey.replace('-', '_');
+            value = System.getenv(noDashKey);
+        }
+        return value;
+    }
+
+    /**
      * This inner class is the definition of a property used in a string
      */
     private static final class Property {