I implemented a pool for LDAP connections using the Apache shared pool. I cannot use the join function provided by JNDI (http://download.oracle.com/javase/jndi/tutorial/ldap/connect/pool.html) because I am using an SSL connection (using a special (provided by Oracle) the factory socket ( java.naming.ldap.factory.socket
env value set, which disqualifies the context from the JNDI pool) to the LDAP server, and therefore the union tool inside JNDI is automatically disabled even if the corresponding union property is set.
Now it comes to the point that the pool with the InitialDirContext
instance InitialDirContext
returned to the pool and should be checked for its suitability and has not been closed by the user or lost connection to the LDAP server for other reasons.
Here I look at the DN of a specific user who is known to exist:
final InitialDirContext ctx = internalPooledLDAPConnection.getCtx(); final Subscriber sub = internalPooledLDAPConnection.getSub(); SearchControls ctls = new SearchControls(); ctls.setSearchScope(2); ctls.setReturningAttributes(new String[] { "dn"}); NamingEnumeration resultSet = ctx.search(sub.getUserSearchBase()[0], "(&(objectclass=*)(uid=orcladmin))", ctls);
In case this operation does not raise any exceptions, then the InitialDirContext
inside my internal merged Ldap connection can still be used and can be safely issued from the pool for reuse.
However, I am wondering if this is the "cheapest" connection health check that can be done here, or is there a much cheaper LDAP operation that I could use instead.
source share