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 4b71a46ac6672b4fc8fcf6e9ce4dfde440646972 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Sun Aug 25 09:39:23 2019 +0200 CAMEL-13907: Lets clear bean introspection cache after bootstrap of Camel as the cache was used during initialization. --- .../org/apache/camel/spi/BeanIntrospection.java | 25 +++++++++++++-- .../impl/engine/CamelPostProcessorHelper.java | 4 +-- .../impl/engine/DefaultBeanIntrospection.java | 37 ++++++++++------------ .../management/ManagedBeanIntrospectionTest.java | 2 +- .../camel/support/PropertyBindingSupport.java | 2 +- 5 files changed, 43 insertions(+), 27 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 d4a5192..9680037 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 @@ -129,12 +129,31 @@ public interface BeanIntrospection extends StaticService { */ ClassInfo cacheClass(Class<?> clazz); - Object getOrElseProperty(Object target, String propertyName, Object defaultValue); + /** + * Clears the introspection cache. + */ + void clearCache(); + /** + * Gets the property or else returning the default value. + * + * @param target the target bean + * @param propertyName the property name + * @param defaultValue the default value + * @param ignoreCase whether to ignore case for matching the property name + * @return the property value, or the default value if the target does not have a property with the given name + */ Object getOrElseProperty(Object target, String propertyName, Object defaultValue, boolean ignoreCase); - Method getPropertyGetter(Class<?> type, String propertyName) throws NoSuchMethodException; - + /** + * Gets the getter method for the property. + * + * @param type the target class + * @param propertyName the property name + * @param ignoreCase whether to ignore case for matching the property name + * @return the getter method + * @throws NoSuchMethodException is thrown if there are no getter method for the property + */ Method getPropertyGetter(Class<?> type, String propertyName, boolean ignoreCase) throws NoSuchMethodException; /** diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/CamelPostProcessorHelper.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/CamelPostProcessorHelper.java index b28cf0f..c6e65dd 100644 --- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/CamelPostProcessorHelper.java +++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/CamelPostProcessorHelper.java @@ -178,10 +178,10 @@ public class CamelPostProcessorHelper implements CamelContextAware { // 2. then the getter with Endpoint as postfix // 3. then if start with on then try step 1 and 2 again, but omit the on prefix try { - Object value = getCamelContext().adapt(ExtendedCamelContext.class).getBeanIntrospection().getOrElseProperty(bean, propertyName, null); + Object value = getCamelContext().adapt(ExtendedCamelContext.class).getBeanIntrospection().getOrElseProperty(bean, propertyName, null, false); if (value == null) { // try endpoint as postfix - value = getCamelContext().adapt(ExtendedCamelContext.class).getBeanIntrospection().getOrElseProperty(bean, propertyName + "Endpoint", null); + value = getCamelContext().adapt(ExtendedCamelContext.class).getBeanIntrospection().getOrElseProperty(bean, propertyName + "Endpoint", null, false); } if (value == null && propertyName.startsWith("on")) { // retry but without the on as prefix 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 ca8bca9..2d02c38 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 @@ -77,41 +77,47 @@ public class DefaultBeanIntrospection extends ServiceSupport implements BeanIntr if (args != null && args.length > 0) { obj = Arrays.asList(args); } - logger.log("Invoked: " + invoked.get() + " times (overall) [Method: " + method + ", Target: " + target + ", Arguments: " + obj + " ]"); + if (target == null) { + logger.log("Invoked: " + invoked.get() + " times (overall) [Method: " + method + " ]"); + } else if (args == null) { + logger.log("Invoked: " + invoked.get() + " times (overall) [Method: " + method + ", Target: " + target + "]"); + } else { + logger.log("Invoked: " + invoked.get() + " times (overall) [Method: " + method + ", Target: " + target + ", Arguments: " + obj + " ]"); + } } @Override public ClassInfo cacheClass(Class<?> clazz) { - log("cacheClass", clazz); + if (logger.shouldLog()) { + log("cacheClass", clazz); + } invoked.incrementAndGet(); return IntrospectionSupport.cacheClass(clazz); } @Override - public boolean getProperties(Object target, Map<String, Object> properties, String optionPrefix) { - invoked.incrementAndGet(); + public void clearCache() { if (logger.shouldLog()) { - log("getProperties", target); + log("clearCache", null); } - return IntrospectionSupport.getProperties(target, properties, optionPrefix); } @Override - public boolean getProperties(Object target, Map<String, Object> properties, String optionPrefix, boolean includeNull) { + public boolean getProperties(Object target, Map<String, Object> properties, String optionPrefix) { invoked.incrementAndGet(); if (logger.shouldLog()) { log("getProperties", target); } - return IntrospectionSupport.getProperties(target, properties, optionPrefix, includeNull); + return IntrospectionSupport.getProperties(target, properties, optionPrefix); } @Override - public Object getOrElseProperty(Object target, String propertyName, Object defaultValue) { + public boolean getProperties(Object target, Map<String, Object> properties, String optionPrefix, boolean includeNull) { invoked.incrementAndGet(); if (logger.shouldLog()) { - log("getOrElseProperty", target, propertyName); + log("getProperties", target); } - return IntrospectionSupport.getOrElseProperty(target, propertyName, defaultValue); + return IntrospectionSupport.getProperties(target, properties, optionPrefix, includeNull); } @Override @@ -124,15 +130,6 @@ public class DefaultBeanIntrospection extends ServiceSupport implements BeanIntr } @Override - public Method getPropertyGetter(Class<?> type, String propertyName) throws NoSuchMethodException { - invoked.incrementAndGet(); - 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(); if (logger.shouldLog()) { diff --git a/core/camel-management-impl/src/test/java/org/apache/camel/management/ManagedBeanIntrospectionTest.java b/core/camel-management-impl/src/test/java/org/apache/camel/management/ManagedBeanIntrospectionTest.java index 0ec992b..3e356a8 100644 --- a/core/camel-management-impl/src/test/java/org/apache/camel/management/ManagedBeanIntrospectionTest.java +++ b/core/camel-management-impl/src/test/java/org/apache/camel/management/ManagedBeanIntrospectionTest.java @@ -65,7 +65,7 @@ public class ManagedBeanIntrospectionTest extends ManagementTestSupport { Long counter = (Long) mbeanServer.getAttribute(on, "InvokedCounter"); assertEquals("Should not have been invoked", 0, counter.intValue()); - Object dummy = context.adapt(ExtendedCamelContext.class).getBeanIntrospection().getOrElseProperty(this, "dummy", null); + Object dummy = context.adapt(ExtendedCamelContext.class).getBeanIntrospection().getOrElseProperty(this, "dummy", null, false); assertEquals("MyDummy", dummy); counter = (Long) mbeanServer.getAttribute(on, "InvokedCounter"); diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java index 3974bb1..0d70e88 100644 --- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java +++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java @@ -713,7 +713,7 @@ public final class PropertyBindingSupport { return getter.getReturnType(); } } else { - Method getter = context.adapt(ExtendedCamelContext.class).getBeanIntrospection().getPropertyGetter(target.getClass(), name); + Method getter = context.adapt(ExtendedCamelContext.class).getBeanIntrospection().getPropertyGetter(target.getClass(), name, false); if (getter != null) { return getter.getReturnType(); }