Hi,

Camel 2.19.2

Running on localhost by itself, no container. Querying LDAP for user details 
with a timer. First query works ok (shown on line 5 of the log), second query 
and all subsequent queries after that give a 
"javax.naming.NoInitialContextException: Need to specify class name in 
environment or system property, or as an applet parameter, or in an application 
resource file:  java.naming.factory.initial" error.

I've checked that the properties object I give to the route is used on the 
first poll, but on the second poll it is replaced by the system properties 
object which does not contain the properties I've set up when starting the 
route. Am I missing something obvious here ?

Main:

public class LocalTest {

    public static void main(String[] args) {
        InitialLdapContext context = null;
        Properties props = new Properties();
        props.setProperty(Context.INITIAL_CONTEXT_FACTORY, 
"com.sun.jndi.ldap.LdapCtxFactory");
        props.setProperty(Context.PROVIDER_URL, "ldap://xxxxxxxxx.zzz:389";);
        props.setProperty(Context.URL_PKG_PREFIXES, "com.sun.jndi.url");
        props.setProperty(Context.REFERRAL, "ignore");
        props.setProperty(Context.SECURITY_AUTHENTICATION, "simple");
        props.setProperty(Context.SECURITY_PRINCIPAL, "user@domain");
        props.setProperty(Context.SECURITY_CREDENTIALS, "password");
        try {
            context = new InitialLdapContext(props, null);
        } catch (NamingException e) {
            e.printStackTrace();
        }
        Main main = new Main();
        main.bind("myldap", context);
        main.addRouteBuilder(new MyRouteBuilder());
        try {
            main.run();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Route:

public class MyRouteBuilder extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("timer:determine?period=30000")
                .transform().simple("(&(objectClass=user) 
(sAMAccountName=MY_USER_NAME))")
                .log("Query body: ${body}")
                // Tee ldap query
                .to("ldap:myldap?base=ou=XXXXXX,dc=YYYYYY,dc=ZZZ")
                // loki
                .log("Received body: ${body}")
        .end();
    }
}

Log snip:

2017-08-28 10:46:27,268 [main           ] INFO  DefaultCamelContext            
- Total 1 routes, of which 1 are started.
2017-08-28 10:46:27,269 [main           ] INFO  DefaultCamelContext            
- Apache Camel 2.19.2 (CamelContext: camel-1) started in 0.369 seconds
2017-08-28 10:46:28,289 [mer://determine] INFO  route1                         
- Query body: (&(objectClass=user) (sAMAccountName=MY_USER_NAME))
2017-08-28 10:46:28,291 [mer://determine] DEBUG SendProcessor                  
- >>>> ldap://myldap?base=ou%3DXXXXXXX%2Cdc%3DXXXXXXXnet%2Cdc%3DZZZ 
Exchange[ID-XXXXXXXXXXX-59010-1503906386453-0-2]
2017-08-28 10:46:29,241 [mer://determine] INFO  route1                         
- Received body: [CN=Pakarinen Jari,OU=ZZZ etc.
2017-08-28 10:46:58,270 [mer://determine] INFO  route1                         
- Query body: (&(objectClass=user) (sAMAccountName=MY_USER_NAME))
2017-08-28 10:46:58,270 [mer://determine] DEBUG SendProcessor                  
- >>>> ldap://myldap?base=ou%3DXXXXXXX%2Cdc%3DXXXXXXXnet%2Cdc%3DZZZ 
Exchange[ID-XXXXXXXXXXX-59010-1503906386453-0-4]
2017-08-28 10:46:58,271 [mer://determine] DEBUG DefaultErrorHandler            
- Failed delivery for (MessageId: ID-WL109160-59010-1503906386453-0-3 on 
ExchangeId: ID-XXXXXXXXXXX-59010-1503906386453-0-4). On delivery attempt: 0 
caught: javax.naming.NoInitialContextException: Need to specify class name in 
environment or system property, or as an applet parameter, or in an application 
resource file:  java.naming.factory.initial
2017-08-28 10:46:58,279 [mer://determine] ERROR DefaultErrorHandler            
- Failed delivery for (MessageId: ID-WL109160-59010-1503906386453-0-3 on 
ExchangeId: ID-WL109160-59010-1503906386453-0-4). Exhausted after delivery 
attempt: 1 caught: javax.naming.NoInitialContextException: Need to specify 
class name in environment or system property, or as an applet parameter, or in 
an application resource file:  java.naming.factory.initial

Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId              ProcessorId          Processor                             
                                           Elapsed (ms)
[route1            ] [route1            ] [timer://some_timer?period=30000      
                                          ] [         7]
[route1            ] [transform1        ] 
[transform[simple{(&(objectClass=user) (sAMAccountName=MY_USER_NAME))}]         
     ] [         0]
[route1            ] [log1              ] [log                                  
                                         ] [         0]
[route1            ] [to1               ] 
[ldap:myldap?base=ou=XXXXXX,dc=YYYYYY,dc=ZZZ                                  ] 
[         2]

Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------
javax.naming.NoInitialContextException: Need to specify class name in 
environment or system property, or as an applet parameter, or in an application 
resource file:  java.naming.factory.initial
        at 
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
        at 
javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
        at 
javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:350)
        at 
javax.naming.directory.InitialDirContext.getURLOrDefaultInitDirCtx(InitialDirContext.java:106)
        at 
javax.naming.directory.InitialDirContext.search(InitialDirContext.java:267)
        at 
org.apache.camel.component.ldap.LdapProducer.simpleSearch(LdapProducer.java:102)
        at 
org.apache.camel.component.ldap.LdapProducer.process(LdapProducer.java:71)
        at 
org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
        at 
org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)
        at 
org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
        at 
org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:541)
        at 
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:198)
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:120)
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
        at 
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:198)
        at 
org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:197)
        at 
org.apache.camel.component.timer.TimerConsumer$1.run(TimerConsumer.java:79)
        at java.util.TimerThread.mainLoop(Timer.java:555)
        at java.util.TimerThread.run(Timer.java:505)


--
Jari


Reply via email to