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/06/26 12:46:36 UTC
[camel] 04/07: CAMEL-13681: Camel main should ignore case in
property keys
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 1076cc0e55b13a350e5bc7b3a800641a098ce5cc
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Jun 26 10:29:32 2019 +0200
CAMEL-13681: Camel main should ignore case in property keys
---
.../java/org/apache/camel/main/MainSupport.java | 38 ++++++++++++++++------
1 file changed, 28 insertions(+), 10 deletions(-)
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java
index fb8abff..a5d9993 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java
@@ -57,6 +57,7 @@ import org.apache.camel.util.FileUtil;
import org.apache.camel.util.IOHelper;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.OrderedProperties;
+import org.apache.camel.util.StringHelper;
import org.apache.camel.util.concurrent.ThreadHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -803,6 +804,17 @@ public abstract class MainSupport extends ServiceSupport {
// now configure context/hystrix/rest with additional properties
Properties prop = camelContext.getPropertiesComponent().loadProperties();
+
+ // load properties from ENV (override existing)
+ Properties propENV = loadEnvironmentVariablesAsProperties(new String[]{"camel.component.properties."});
+ if (!propENV.isEmpty()) {
+ prop.putAll(propENV);
+ LOG.debug("Properties from OS environment variables:");
+ for (String key : propENV.stringPropertyNames()) {
+ LOG.debug(" {}={}", key, propENV.getProperty(key));
+ }
+ }
+
Map<String, Object> properties = new LinkedHashMap<>();
Map<String, Object> hystrixProperties = new LinkedHashMap<>();
Map<String, Object> restProperties = new LinkedHashMap<>();
@@ -812,21 +824,21 @@ public abstract class MainSupport extends ServiceSupport {
String value = prop.getProperty(key);
String option = key.substring(14);
if (ObjectHelper.isNotEmpty(value) && ObjectHelper.isNotEmpty(option)) {
- properties.put(option, value);
+ properties.put(optionKey(option), value);
}
} else if (key.startsWith("camel.hystrix.")) {
// grab the value
String value = prop.getProperty(key);
String option = key.substring(14);
if (ObjectHelper.isNotEmpty(value) && ObjectHelper.isNotEmpty(option)) {
- hystrixProperties.put(option, value);
+ hystrixProperties.put(optionKey(option), value);
}
} else if (key.startsWith("camel.rest.")) {
// grab the value
String value = prop.getProperty(key);
String option = key.substring(11);
if (ObjectHelper.isNotEmpty(value) && ObjectHelper.isNotEmpty(option)) {
- restProperties.put(option, value);
+ restProperties.put(optionKey(option), value);
}
}
}
@@ -906,7 +918,7 @@ public abstract class MainSupport extends ServiceSupport {
String option = key.substring(dot + 1);
if (ObjectHelper.isNotEmpty(value) && ObjectHelper.isNotEmpty(option)) {
Map<String, Object> values = properties.getOrDefault(component, new LinkedHashMap<>());
- values.put(option, value);
+ values.put(optionKey(option), value);
properties.put(component, values);
}
}
@@ -949,7 +961,7 @@ public abstract class MainSupport extends ServiceSupport {
String value = prop.getProperty(key);
String option = key.substring(11);
if (ObjectHelper.isNotEmpty(value) && ObjectHelper.isNotEmpty(option)) {
- properties.put(option, value);
+ properties.put(optionKey(option), value);
}
}
}
@@ -1017,7 +1029,8 @@ public abstract class MainSupport extends ServiceSupport {
String option = key.substring(dot + 1);
if (component != null && ObjectHelper.isNotEmpty(value) && ObjectHelper.isNotEmpty(option)) {
Map<String, Object> values = properties.getOrDefault(component, new LinkedHashMap<>());
- values.put(option, value);
+ // we ignore case for property keys (so we should store them in canonical style
+ values.put(optionKey(option), value);
properties.put(component, values);
}
}
@@ -1031,7 +1044,7 @@ public abstract class MainSupport extends ServiceSupport {
String option = key.substring(dot + 1);
if (dataformat != null && ObjectHelper.isNotEmpty(value) && ObjectHelper.isNotEmpty(option)) {
Map<String, Object> values = properties.getOrDefault(dataformat, new LinkedHashMap<>());
- values.put(option, value);
+ values.put(optionKey(option), value);
properties.put(dataformat, values);
}
}
@@ -1045,14 +1058,12 @@ public abstract class MainSupport extends ServiceSupport {
String option = key.substring(dot + 1);
if (language != null && ObjectHelper.isNotEmpty(value) && ObjectHelper.isNotEmpty(option)) {
Map<String, Object> values = properties.getOrDefault(language, new LinkedHashMap<>());
- values.put(option, value);
+ values.put(optionKey(option), value);
properties.put(language, values);
}
}
}
- // TODO: filter out duplicte properties due to ignore-case
-
if (!properties.isEmpty()) {
long total = properties.values().stream().mapToLong(Map::size).sum();
LOG.info("Auto configuring {} components/dataformat/languages from loaded properties: {}", properties.size(), total);
@@ -1079,6 +1090,13 @@ public abstract class MainSupport extends ServiceSupport {
});
}
+ private static String optionKey(String key) {
+ // as we ignore case for property names we should use keys in same case and without dashes
+ key = StringHelper.replaceAll(key, "-", "");
+ key = key.toLowerCase(Locale.US);
+ return key;
+ }
+
public void addRouteBuilder(RouteBuilder routeBuilder) {
getRouteBuilders().add(routeBuilder);
}