Christian Schubert-Huff created CAMEL-18700:
-----------------------------------------------

             Summary: camel-main - Unable to declare map bean with dotted keys
                 Key: CAMEL-18700
                 URL: https://issues.apache.org/jira/browse/CAMEL-18700
             Project: Camel
          Issue Type: Bug
          Components: camel-bean, camel-main
    Affects Versions: 3.19.0, 3.18.1
            Reporter: Christian Schubert-Huff


I have been trying to configure camel-ldap using camel-main:
|*dirContextName* (producer)|*Required* Name of either a 
javax.naming.directory.DirContext, or java.util.Hashtable, or Map bean to 
lookup in the registry. If the bean is either a Hashtable or Map then a new 
javax.naming.directory.DirContext instance is created for each use.|

It should be sufficient to declare a map bean like this:
{code:java}
camel.beans.ldapserver[java.naming.provider.url] = ldaps://ldap.local:636
camel.beans.ldapserver[java.naming.security.principal] = scott
camel.beans.ldapserver[java.naming.security.credentials] = tiger
{code}
However, this fails:
{noformat}
java.lang.IllegalArgumentException: Cannot find getter method: java on bean: 
class java.util.LinkedHashMap when binding property: java.naming.provider.url

        at 
org.apache.camel.support.PropertyBindingSupport.doBuildPropertyOgnlPath(PropertyBindingSupport.java:306)
        at 
org.apache.camel.support.PropertyBindingSupport.doBindProperties(PropertyBindingSupport.java:233)
        at 
org.apache.camel.support.PropertyBindingSupport$Builder.bind(PropertyBindingSupport.java:1854)
        at 
org.apache.camel.main.MainHelper.setPropertiesOnTarget(MainHelper.java:316)
        at 
org.apache.camel.main.BaseMainSupport.bindBeansToRegistry(BaseMainSupport.java:1440)
        at 
org.apache.camel.main.BaseMainSupport.doConfigureCamelContextFromMainConfiguration(BaseMainSupport.java:1065)
        at 
org.apache.camel.main.BaseMainSupport.autoconfigure(BaseMainSupport.java:492)
        at org.apache.camel.main.MainSupport.autoconfigure(MainSupport.java:74)
        at 
org.apache.camel.main.BaseMainSupport.postProcessCamelContext(BaseMainSupport.java:693)
        at 
org.apache.camel.main.MainSupport.initCamelContext(MainSupport.java:403)
        at org.apache.camel.main.Main.doInit(Main.java:133)
{noformat}
Note that the keys are - required - to be dotted, as they are known constants 
declared in {{javax.naming.Context}}

Reproduction is easy:
{code:java}
    @Test
    public void testBindBeansMapSquareDotted() {
        Main main = new Main();
        main.configure().addRoutesBuilder(new MyRouteBuilder());

        // create by class
        main.addProperty("camel.beans.ldapserver[java.naming.provider.url]", 
"ldaps://ldap.local:636");
        
main.addProperty("camel.beans.ldapserver[java.naming.security.principal]", 
"scott");
        
main.addProperty("camel.beans.ldapserver[java.naming.security.credentials]", 
"tiger");

        main.start();

        CamelContext camelContext = main.getCamelContext();
        assertNotNull(camelContext);

        Map foo = camelContext.getRegistry().lookupByNameAndType("ldapserver", 
Map.class);
        assertNotNull(foo);

        assertEquals(3, foo.size());
        assertEquals("ldaps://ldap.local:636", 
foo.get(javax.naming.Context.PROVIDER_URL));
        assertEquals("scott", foo.get(javax.naming.Context.SECURITY_PRINCIPAL));
        assertEquals("tiger", 
foo.get(javax.naming.Context.SECURITY_CREDENTIALS));

        main.stop();
    }
{code}
There is a workaround, which requires the declaration of an additional property 
for each entry, like this:
{noformat}
providerUrl = java.naming.provider.url
camel.beans.ldapserver[{{providerUrl}}] = ldaps://ldap.local:636
{noformat}

This affects both version 3.18.1 and the latest snapshot from main.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to