Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Bizarre Problem with LDAP and servlets/beans

3 views
Skip to first unread message

Michael Bartlett

unread,
Dec 4, 2000, 3:00:00 AM12/4/00
to
Hi there,
We are busy developing a project using Sun's JNDI libraries, to connect to
Microsoft's LDAP-enabled Active Directory. Using the LDAP provider libraries
that ship as part of JNDI 1.2, I am able to make LDAP connections and run
LDAP requests from a standard class file on my development box. I can even
run the classes on the application server at the command prompt just using
the JRE and not the app server environment. However, as soon as this
environment is moved into a Servlet Engine (New Atlanta's ServletExec ISAPI
running inside IIS 4.0), or moved into an EJB container and run as an EJB,
the classes fail to work. ServletExec consistently throws a ClassNotFound
Exception when the ClassLoader tries to classload
com.sun.jndi.ldap.LdapCtxFactory. We have also tried pulling down Allaire
JRUN, configured the environment, the classpaths and got EXACTLY the same
exception. Even though I have made sure that all classes are in the
classpath. I even tried extracting all JAR-ed classes into a folder in the
classpath and running it like that, still no look. The Error screen looks
something like this:

200: javax.naming.NoInitialContextException: Cannot instantiate class:

com.sun.jndi.ldap.LdapCtxFactory. Root exception is
java.lang.ClassNotFoundException: com/sun/jndi/ldap/LdapCtxFactory

200: at java.lang.Class.forName0(Native Method)

200: at java.lang.Class.forName(Class.java:199)

200: at
com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:49)

200: at
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:660)

200: at
javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:250)

200: at javax.naming.InitialContext.init(InitialContext.java:226)

200: at javax.naming.InitialContext.<init>(InitialContext.java:202)

200: at
javax.naming.directory.InitialDirContext.<init>(InitialDirContext.java:87)

200: at
MetODSRegistrationServlet.registerUser(MetODSRegistrationServlet.java,
Compiled Code)

200: at
MetODSRegistrationServlet.doPost(MetODSRegistrationServlet.java:203)

200: at javax.servlet.http.HttpServlet.service(HttpServlet.java:747)

200: at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)

200: at
newatlanta.servletexec.ServletExec.processServletRequest(ServletExec.java)

200: at
newatlanta.servletexec.ServletExec.ProcessRequest(ServletExec.java, Compiled
Code)

200: at
newatlanta.servletexec.ServletExec.ProcessRequest(ServletExec.java)

The error from the EJB is much the same. The source code is really simple,
and is stock-standard from our research on the net.

Hashtable env = new Hashtable();

env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");

env.put(javax.naming.Context.PROVIDER_URL, "ldap://localhost:389");

env.put(javax.naming.Context.SECURITY_AUTHENTICATION, "simple");

env.put(javax.naming.Context.SECURITY_PRINCIPAL, "username");

env.put(javax.naming.Context.SECURITY_CREDENTIALS, "password");

env.put("java.naming.ldap.version","3");

DirContext ctx = new InitialDirContext(env);

This just simply will not work in the Servlet, and breaks at the point of
trying to create the Initial Context. Does anyone know of any known issues
with this, we've found nothing to indicate this? Workarounds? What am I
doing wrong? Any help would be HUGELY appreciated!

Regards

Mike Bartlett


Jon Skeet

unread,
Dec 4, 2000, 3:00:00 AM12/4/00
to
[Posted and emailed]

cata...@eye2eye.net wrote:
> 200: javax.naming.NoInitialContextException: Cannot instantiate class:
> com.sun.jndi.ldap.LdapCtxFactory. Root exception is
> java.lang.ClassNotFoundException: com/sun/jndi/ldap/LdapCtxFactory

<snip>

> This just simply will not work in the Servlet, and breaks at the point of
> trying to create the Initial Context. Does anyone know of any known issues
> with this, we've found nothing to indicate this? Workarounds? What am I
> doing wrong? Any help would be HUGELY appreciated!

I've never been able to work out why, but I believe JNDI needs to be in
the original classpath for the JVM - letting it get loaded by
classloaders in servlets doesn't work, apparently :( I've seen this
problem in JServ and Tomcat, and am almost pleased to hear it happens
elsewhere - it means it's less likely to be something I'm doing wrong!

If you can, put jndi.jar, ldap.jar and providerutil.jar in the
jre/lib/ext directory of the VM. It saves a fair amount of hassle :) If
you can't do that, modify the startup classpath to include them all.

Hope this helps.

--
Jon Skeet - sk...@pobox.com
http://www.pobox.com/~skeet

0 new messages