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 2020/09/22 05:04:21 UTC
[camel] branch master updated: CAMEL-15565: camel-main beans
configuration should lookup existing bean first. CAMEL-15563: Fixed logging
sensitive details in summary.
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
The following commit(s) were added to refs/heads/master by this push:
new d36a4ca CAMEL-15565: camel-main beans configuration should lookup existing bean first. CAMEL-15563: Fixed logging sensitive details in summary.
d36a4ca is described below
commit d36a4cac77786e7da268c5f75cbd0417e74b01d1
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Sep 22 07:03:51 2020 +0200
CAMEL-15565: camel-main beans configuration should lookup existing bean first. CAMEL-15563: Fixed logging sensitive details in summary.
---
.../org/apache/camel/main/BaseMainSupport.java | 28 ++++++++++++++++------
.../java/org/apache/camel/main/MainExample.java | 20 ++++++++++++++++
.../src/test/resources/example.properties | 5 +++-
3 files changed, 45 insertions(+), 8 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 3c0fea9..48a96b0 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
@@ -21,6 +21,7 @@ import java.io.FileInputStream;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
@@ -583,7 +584,8 @@ public abstract class BaseMainSupport extends BaseService {
if (mainConfigurationProperties.isAutoConfigurationLogSummary() && !autoConfiguredProperties.isEmpty()) {
LOG.info("Auto-configuration summary:");
autoConfiguredProperties.forEach((k, v) -> {
- boolean sensitive = SENSITIVE_KEYS.contains(k.toLowerCase(Locale.ENGLISH));
+ boolean sensitive
+ = Arrays.stream(SENSITIVE_KEYS.split("\\|")).anyMatch(s -> k.toLowerCase(Locale.ENGLISH).contains(s));
if (sensitive) {
LOG.info("\t{}=xxxxxx", k);
} else {
@@ -1188,9 +1190,9 @@ public abstract class BaseMainSupport extends BaseService {
// make defensive copy as we mutate the map
Set<String> keys = new LinkedHashSet<>(properties.keySet());
+ // create beans first
for (String key : keys) {
if (key.indexOf('.') == -1) {
- // create beans first and then set properties
String name = key;
Object value = properties.remove(key);
Object bean = PropertyBindingSupport.resolveBean(camelContext, name, value);
@@ -1199,13 +1201,25 @@ public abstract class BaseMainSupport extends BaseService {
"Cannot create/resolve bean with name " + name + " from value: " + value);
}
// register bean
+ LOG.info("Binding bean: {} (type: {}) to the registry", key, ObjectHelper.classCanonicalName(bean));
camelContext.getRegistry().bind(name, bean);
- autoConfiguredProperties.put(optionPrefix + key, value.toString());
- // and then configure properties on the beans afterwards
- Map<String, Object> config = PropertiesHelper.extractProperties(properties, key + ".");
- setPropertiesOnTarget(camelContext, bean, config, optionPrefix + key + ".", failIfNotSet, ignoreCase,
+ }
+ }
+ // then set properties
+ for (String key : keys) {
+ if (key.indexOf('.') != -1) {
+ String name = StringHelper.before(key, ".");
+ String valueKey = StringHelper.after(key, ".");
+ Object value = properties.remove(key);
+ Object bean = camelContext.getRegistry().lookupByName(name);
+ if (bean == null) {
+ throw new IllegalArgumentException(
+ "Cannot resolve bean with name " + name);
+ }
+ Map<String, Object> map = new HashMap<>();
+ map.put(valueKey, value);
+ setPropertiesOnTarget(camelContext, bean, map, optionPrefix + name + ".", failIfNotSet, ignoreCase,
autoConfiguredProperties);
- LOG.info("Binding bean: {} (type: {}) to the registry", key, ObjectHelper.classCanonicalName(bean));
}
}
}
diff --git a/core/camel-main/src/test/java/org/apache/camel/main/MainExample.java b/core/camel-main/src/test/java/org/apache/camel/main/MainExample.java
index 6a7a913..106c3d2 100644
--- a/core/camel-main/src/test/java/org/apache/camel/main/MainExample.java
+++ b/core/camel-main/src/test/java/org/apache/camel/main/MainExample.java
@@ -64,6 +64,26 @@ public class MainExample {
}
public static class MyBean {
+
+ private String username;
+ private String password;
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
public void callMe() {
System.out.println("MyBean.callMe method has been called");
}
diff --git a/core/camel-main/src/test/resources/example.properties b/core/camel-main/src/test/resources/example.properties
index 73fe31c..5ae98c5 100644
--- a/core/camel-main/src/test/resources/example.properties
+++ b/core/camel-main/src/test/resources/example.properties
@@ -14,4 +14,7 @@
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
-millisecs = 5000
\ No newline at end of file
+millisecs = 5000
+
+camel.beans.foo.username=scott
+camel.beans.foo.password=tiger
\ No newline at end of file