This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch CAMEL-13870
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/CAMEL-13870 by this push:
new ffb401e CAMEL-13870: Fast property configuration of Camel endpoints.
Work in progress.
ffb401e is described below
commit ffb401e2014667d39d15f21fbdd35800aed06ec5
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Aug 22 14:09:53 2019 +0200
CAMEL-13870: Fast property configuration of Camel endpoints. Work in
progress.
---
.../org/apache/camel/spi/BeanIntrospection.java | 4 +-
.../impl/engine/DefaultBeanIntrospection.java | 69 +++++++++++++++++-----
.../camel/main/DefaultConfigurationProperties.java | 2 +-
.../camel-main-configuration-metadata.json | 2 +-
4 files changed, 58 insertions(+), 19 deletions(-)
diff --git
a/core/camel-api/src/main/java/org/apache/camel/spi/BeanIntrospection.java
b/core/camel-api/src/main/java/org/apache/camel/spi/BeanIntrospection.java
index 74d8b94..d4a5192 100644
--- a/core/camel-api/src/main/java/org/apache/camel/spi/BeanIntrospection.java
+++ b/core/camel-api/src/main/java/org/apache/camel/spi/BeanIntrospection.java
@@ -83,12 +83,12 @@ public interface BeanIntrospection extends StaticService {
void setExtendedStatistics(boolean extendedStatistics);
/**
- * Logging level used for logging introspection usage. Is using DEBUG
level as default.
+ * Logging level used for logging introspection usage. Is using TRACE
level as default.
*/
LoggingLevel getLoggingLevel();
/**
- * Logging level used for logging introspection usage. Is using DEBUG
level as default.
+ * Logging level used for logging introspection usage. Is using TRACE
level as default.
*/
void setLoggingLevel(LoggingLevel loggingLevel);
diff --git
a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultBeanIntrospection.java
b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultBeanIntrospection.java
index f03286f..1560890 100644
---
a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultBeanIntrospection.java
+++
b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultBeanIntrospection.java
@@ -17,9 +17,11 @@
package org.apache.camel.impl.engine;
import java.lang.reflect.Method;
+import java.util.Arrays;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
+import java.util.regex.Pattern;
import org.apache.camel.CamelContext;
import org.apache.camel.LoggingLevel;
@@ -35,10 +37,11 @@ import org.slf4j.LoggerFactory;
public class DefaultBeanIntrospection extends ServiceSupport implements
BeanIntrospection {
private static final Logger LOG =
LoggerFactory.getLogger(DefaultBeanIntrospection.class);
+ private static final Pattern SECRETS =
Pattern.compile(".*(passphrase|password|secretKey).*",
Pattern.CASE_INSENSITIVE);
private final AtomicLong invoked = new AtomicLong();
private volatile boolean extendedStatistics;
- private LoggingLevel loggingLevel = LoggingLevel.DEBUG;
+ private LoggingLevel loggingLevel = LoggingLevel.TRACE;
private CamelLogger logger = new CamelLogger(LOG, loggingLevel);
@Override
@@ -69,10 +72,12 @@ public class DefaultBeanIntrospection extends
ServiceSupport implements BeanIntr
this.logger = new CamelLogger(LOG, loggingLevel);
}
- private void log(String method, Object bean) {
- if (logger.shouldLog()) {
- logger.log("Invoked: " + invoked.get() + " times (overall)
[Method: " + method + ", Argument: " + bean + "]");
+ private void log(String method, Object target, Object... args) {
+ Object obj = "null";
+ if (args != null && args.length > 0) {
+ obj = Arrays.asList(args);
}
+ logger.log("Invoked: " + invoked.get() + " times (overall) [Method: "
+ method + ", Target: " + target + ", Arguments: " + obj + " ]");
}
@Override
@@ -85,77 +90,111 @@ public class DefaultBeanIntrospection extends
ServiceSupport implements BeanIntr
@Override
public boolean getProperties(Object target, Map<String, Object>
properties, String optionPrefix) {
invoked.incrementAndGet();
- log("getProperties", target);
+ if (logger.shouldLog()) {
+ log("getProperties", target);
+ }
return IntrospectionSupport.getProperties(target, properties,
optionPrefix);
}
@Override
public boolean getProperties(Object target, Map<String, Object>
properties, String optionPrefix, boolean includeNull) {
invoked.incrementAndGet();
- log("getProperties", target);
+ if (logger.shouldLog()) {
+ log("getProperties", target);
+ }
return IntrospectionSupport.getProperties(target, properties,
optionPrefix, includeNull);
}
@Override
public Object getOrElseProperty(Object target, String propertyName, Object
defaultValue) {
invoked.incrementAndGet();
- log("getOrElseProperty", target);
+ if (logger.shouldLog()) {
+ log("getOrElseProperty", target, propertyName);
+ }
return IntrospectionSupport.getOrElseProperty(target, propertyName,
defaultValue);
}
@Override
public Object getOrElseProperty(Object target, String propertyName, Object
defaultValue, boolean ignoreCase) {
invoked.incrementAndGet();
- log("getOrElseProperty", target);
+ if (logger.shouldLog()) {
+ log("getOrElseProperty", target, propertyName);
+ }
return IntrospectionSupport.getOrElseProperty(target, propertyName,
defaultValue, ignoreCase);
}
@Override
public Method getPropertyGetter(Class<?> type, String propertyName) throws
NoSuchMethodException {
invoked.incrementAndGet();
- log("getPropertyGetter", type);
+ if (logger.shouldLog()) {
+ log("getPropertyGetter", type, propertyName);
+ }
return IntrospectionSupport.getPropertyGetter(type, propertyName);
}
@Override
public Method getPropertyGetter(Class<?> type, String propertyName,
boolean ignoreCase) throws NoSuchMethodException {
invoked.incrementAndGet();
- log("getPropertyGetter", type);
+ if (logger.shouldLog()) {
+ log("getPropertyGetter", type, propertyName);
+ }
return IntrospectionSupport.getPropertyGetter(type, propertyName,
ignoreCase);
}
@Override
public boolean setProperty(CamelContext context, TypeConverter
typeConverter, Object target, String name, Object value, String refName,
boolean allowBuilderPattern) throws Exception {
invoked.incrementAndGet();
- log("setProperty", target);
+ if (logger.shouldLog()) {
+ if (SECRETS.matcher(name).find()) {
+ value = "xxxxxx";
+ }
+ log("setProperty", target, name, value);
+ }
return IntrospectionSupport.setProperty(context, typeConverter,
target, name, value, refName, allowBuilderPattern);
}
@Override
public boolean setProperty(CamelContext context, TypeConverter
typeConverter, Object target, String name, Object value, String refName,
boolean allowBuilderPattern, boolean allowPrivateSetter, boolean ignoreCase)
throws Exception {
invoked.incrementAndGet();
- log("setProperty", target);
+ if (logger.shouldLog()) {
+ if (SECRETS.matcher(name).find()) {
+ value = "xxxxxx";
+ }
+ log("setProperty", target, name, value);
+ }
return IntrospectionSupport.setProperty(context, typeConverter,
target, name, value, refName, allowBuilderPattern, allowPrivateSetter,
ignoreCase);
}
@Override
public boolean setProperty(CamelContext context, Object target, String
name, Object value) throws Exception {
invoked.incrementAndGet();
- log("setProperty", target);
+ if (logger.shouldLog()) {
+ if (SECRETS.matcher(name).find()) {
+ value = "xxxxxx";
+ }
+ log("setProperty", target, name, value);
+ }
return IntrospectionSupport.setProperty(context, target, name, value);
}
@Override
public boolean setProperty(TypeConverter typeConverter, Object target,
String name, Object value) throws Exception {
invoked.incrementAndGet();
- log("setProperty", target);
+ if (logger.shouldLog()) {
+ if (SECRETS.matcher(name).find()) {
+ value = "xxxxxx";
+ }
+ log("setProperty", target, name, value);
+ }
return IntrospectionSupport.setProperty(typeConverter, target, name,
value);
}
@Override
public Set<Method> findSetterMethods(Class<?> clazz, String name, boolean
allowBuilderPattern, boolean allowPrivateSetter, boolean ignoreCase) {
invoked.incrementAndGet();
- log("findSetterMethods", clazz);
+ if (logger.shouldLog()) {
+ log("findSetterMethods", clazz);
+ }
return IntrospectionSupport.findSetterMethods(clazz, name,
allowBuilderPattern, allowPrivateSetter, ignoreCase);
}
diff --git
a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
index e2d451a..5be730d 100644
---
a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
+++
b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
@@ -698,7 +698,7 @@ public abstract class DefaultConfigurationProperties<T> {
/**
* Sets the logging level used by bean introspection, logging activity of
its usage.
- * The default is DEBUG.
+ * The default is TRACE.
*/
public void setBeanIntrospectionLoggingLevel(LoggingLevel
beanIntrospectionLoggingLevel) {
this.beanIntrospectionLoggingLevel = beanIntrospectionLoggingLevel;
diff --git
a/core/camel-main/src/main/resources/META-INF/camel-main-configuration-metadata.json
b/core/camel-main/src/main/resources/META-INF/camel-main-configuration-metadata.json
index 6758d86..8548426 100644
---
a/core/camel-main/src/main/resources/META-INF/camel-main-configuration-metadata.json
+++
b/core/camel-main/src/main/resources/META-INF/camel-main-configuration-metadata.json
@@ -94,7 +94,7 @@
"name":"camel.main.bean-introspection-logging-level",
"type":"org.apache.camel.LoggingLevel",
"sourceType":"org.apache.camel.main.DefaultConfigurationProperties",
- "description":"Sets the logging level used by bean
introspection, logging activity of its usage. The default is DEBUG."
+ "description":"Sets the logging level used by bean
introspection, logging activity of its usage. The default is TRACE."
},
{
"name":"camel.main.consumer-template-cache-size",