Announcement Announcement Module
No announcement yet.
javax.naming.NotContextException for Custom LdapContextSource implementation Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • javax.naming.NotContextException for Custom LdapContextSource implementation

    I am using Spring-ldap connection pooling and a custom implementation for the contextSource for connecting using Oracle Internet Directory APIs. This works when testing standalone on eclipse. However it fails with "Not an instance of DirContext" when deployed on tomcat. It works fine on tomcat if I use the LdapContextSource from Spring [but some of my operations fail and works with the context from OID API only] Appreciate any help on this. Below is the config and the code
    public class CustomLdapContextSource extends LdapContextSource {
        protected DirContext getDirContextInstance(Hashtable environment) throws NamingException {
        String url = (String) environment.get("java.naming.provider.url");
        URL aURL = null;
        InitialLdapContext ctx = null;
        StringTokenizer st = new StringTokenizer(url, "://");
        String protocol = st.nextToken();
        String host = st.nextToken();
        String port = st.nextToken();
        ctx = ConnectionUtil.getDefaultDirCtx(host, port, userDn, password);
        return ctx;
    <!-- LDAP Connection pool configuration -->
    <bean id="contextSource"
        <property name="contextSource" ref="contextSourceTarget" />
        <property name="dirContextValidator" ref="dirContextValidator" />
        <property name="testOnBorrow" value="false" />
        <property name="testOnReturn" value="false" />
        <property name="testWhileIdle" value="true" />
        <property name="timeBetweenEvictionRunsMillis" value="900000" />
        <property name="minEvictableIdleTimeMillis" value="1800000" />
        <property name="maxActive" value="8" /> 
        <property name="minIdle" value="3" /> 
        <property name="maxIdle" value="8" />
        <property name="maxWait" value="30000" /> 
        <property name="maxTotal" value="-1" /> 
        <property name="whenExhaustedAction" value="0" /> 
    <bean id="dirContextValidator"
        class="org.springframework.ldap.pool.validation.DefaultDirContextValidator" />
    <bean id="contextSourceTarget" class="com.ticketmaster.platform.identity.core.dao.ldap.CustomLdapContextSource">
        <property name="url" value="${ldap.url}" />
        <property name="userDn" value="${ldap.username}" />
        <property name="password" value="${ldap.password}" />
        <property name="dirObjectFactory"
            value="" />
        <property name="pooled" value="false" />
    <bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
        <constructor-arg ref="contextSource" /> <!-- connection pool reference -->