title: javax.naming.NotContextException for Custom LdapContextSource implementation on tomcat
body: <p>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 if I use the LdapContextSource from Spring [but some of my operations fail and works with the context from OID API]
  Appreciate any help on this.
  Below is the config and the code</p>
  
  <pre><code>&lt;!-- LDAP Connection pool configuration --&gt;
  &lt;bean id="contextSource"
      class="org.springframework.ldap.pool.factory.PoolingContextSource"&gt;
      &lt;property name="contextSource" ref="contextSourceTarget" /&gt;
      &lt;property name="dirContextValidator" ref="dirContextValidator" /&gt;
      &lt;property name="testOnBorrow" value="false" /&gt;
      &lt;property name="testOnReturn" value="false" /&gt;
      &lt;property name="testWhileIdle" value="true" /&gt;
      &lt;property name="timeBetweenEvictionRunsMillis" value="900000" /&gt;
      &lt;property name="minEvictableIdleTimeMillis" value="1800000" /&gt;
      &lt;property name="maxActive" value="8" /&gt; 
      &lt;property name="minIdle" value="3" /&gt; 
      &lt;property name="maxIdle" value="8" /&gt;
      &lt;property name="maxWait" value="30000" /&gt; 
      &lt;property name="maxTotal" value="-1" /&gt; 
      &lt;property name="whenExhaustedAction" value="0" /&gt; 
  &lt;/bean&gt;
  
  &lt;bean id="dirContextValidator"
      class="org.springframework.ldap.pool.validation.DefaultDirContextValidator" /&gt;
  &lt;bean id="contextSourceTarget" class="com.ticketmaster.platform.identity.core.dao.ldap.CustomLdapContextSource"&gt;
      &lt;property name="url" value="${ldap.url}" /&gt;
      &lt;property name="userDn" value="${ldap.username}" /&gt;
      &lt;property name="password" value="${ldap.password}" /&gt;
      &lt;property name="dirObjectFactory"
          value="org.springframework.ldap.core.support.DefaultDirObjectFactory" /&gt;
      &lt;property name="pooled" value="false" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate"&gt;
      &lt;constructor-arg ref="contextSource" /&gt; &lt;!-- connection pool reference --&gt;
  &lt;/bean&gt;
  
  public class CustomLdapContextSource extends LdapContextSource {
  
      @Override
      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;
      }
  </code></pre>