Class CamelPropertiesHelper


  • public final class CamelPropertiesHelper
    extends Object
    To help configuring Camel properties that have been defined in Spring Boot configuration files.
    • Method Detail

      • copyProperties

        public static void copyProperties​(org.apache.camel.CamelContext camelContext,
                                          Object source,
                                          Object target)
      • setCamelProperties

        public static boolean setCamelProperties​(org.apache.camel.CamelContext context,
                                                 Object target,
                                                 Map<String,​Object> properties,
                                                 boolean failIfNotSet)
        Sets the properties on the target bean.

        This method uses PropertyBindingSupport and therefore offers its capabilities such as:

        • property placeholders - Keys and values using Camels property placeholder will be resolved
        • nested - Properties can be nested using the dot syntax (OGNL and builder pattern using with as prefix), eg foo.bar=123
        • map
        • - Properties can lookup in Map's using map syntax, eg foo[bar] where foo is the name of the property that is a Map instance, and bar is the name of the key.
        • list
        • - Properties can refer or add to in List's using list syntax, eg foo[0] where foo is the name of the property that is a List instance, and 0 is the index. To refer to the last element, then use last as key.
        This implementation sets the properties using the following algorithm in the given order:
        • reference by bean id - Values can refer to other beans in the registry by prefixing with with # or #bean: eg #myBean or #bean:myBean
        • reference by type - Values can refer to singleton beans by their type in the registry by prefixing with #type: syntax, eg #type:com.foo.MyClassType
        • autowire by type - Values can refer to singleton beans by auto wiring by setting the value to #autowired
        • reference new class - Values can refer to creating new beans by their class name by prefixing with #class, eg #class:com.foo.MyClassType
        • value as lookup - The value is used as-is (eg like #value) to lookup in the Registry if there is a bean then its set on the target
        When an option has been set on the target bean, then its removed from the given properties map. If all the options has been set, then the map will be empty. The implementation ignores case for the property keys.
        Parameters:
        context - the CamelContext
        target - the target bean
        properties - the properties
        failIfNotSet - whether to fail if an option either does not exists on the target bean or if the option cannot be due no suitable setter methods with the given type
        Returns:
        true if at least one option was configured
        Throws:
        IllegalArgumentException - is thrown if an option cannot be configured on the bean because there is no suitable setter method and failOnNoSet is true.