views:

92

answers:

2

Good morning / afternoon,

I have a problem with LDAP connector, when I use it in my unit test no problem, but when it was called in a application server environment, it seems to have classpath issue, but this class is delivred with java 1.6.17 (version I use).

I use spring-ldap to initiate my connection.

public static LdapContextSource getLdapContextSource(final String url, final String base) throws Exception {
    LdapContextSource ldapContextSource = new LdapContextSource();

    ldapContextSource.setUrl(url);
    ldapContextSource.setBase(base);
    ldapContextSource.setPooled(true);
    //ldapContextSource.setContextFactory(LdapCtxFactory.class);

    ldapContextSource.afterPropertiesSet();

    return ldapContextSource;
}

Here is the log :

2010-08-10 09:46:38,183 : StandardWrapperValve.invoke : Servlet.service() for servlet default threw exception
java.lang.ClassNotFoundException: com.sun.jndi.ldap.LdapCtxFactory
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at org.ow2.easybeans.loader.EasyBeansClassLoader.findClass(EasyBeansClassLoader.java:134)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
    at org.ow2.easybeans.loader.EasyBeansClassLoader.loadClass(EasyBeansClassLoader.java:238)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:169)
    at org.springframework.ldap.core.support.AbstractContextSource.class$(AbstractContextSource.java:67)
    at org.springframework.ldap.core.support.AbstractContextSource.<clinit>(AbstractContextSource.java:67)
    at org.zenithar.security.connectors.impl.ldap.LdapContextFactory.getLdapContextSource(LdapContextFactory.java:16)

Thanks for all. Regards.

+1  A: 

Your unit test and app server must not be using the same JRE if that's the case. Check to see what your app server is using.

com.sun.jndi.ldap.LdapCtxFactory is in rt.jar. Can you validate that?

How do you know that the server is using the same JVM? Is it running locally? What do you have JAVA_HOME set to? Which app server?

Don't assume that the class loader suddenly stopped working. When you get information that contradicts your assumptions about how the world works, check your assumptions.

It's far more likely that your app server isn't configured properly than the class loader forgot how to do its job between your successful test and your unsuccessful deployment.

duffymo
It the same VM (1.6.0u17), i've tried to update to u21 but it's the same error.
Zenithar
It seems to be a Classloader problem ... any suggestion ?
Zenithar
Maybe an OSGi problem, i run my webapp on Jonas 5.1. Investigation in progress ...
Zenithar
+1  A: 

I found the solution ^^

It was a problem with Jonas 5 wich is an app server running on OSGI platform. My application is a common core jar (containing spring context with DAO) shared by 3 wars. It seems that the JVM used to host the common core is not the same as used for the 3 wars.

I add to my felix-config.properties

org.osgi.framework.bootdelegation=....
    sun.util.calendar; \
    com.sun.jndi.ldap; \
    version="1.5.0"

And

org.osgi.framework.bootdelegation=com.sun.corba, \
....
com.sun.jndi.ldap.*

So that I can load com.sun.jndi.ldap.LdapCtxFactory in my Common Core.

Thanks for your help.

Zenithar