0 Replies Latest reply on Apr 2, 2007 12:24 PM by redq

    NotContextException in ldap context created by MBean

    redq

      Hi,

      I have an mbean which creates ldap-contexts. Definition of the mbean is:

      <mbean code="org.jboss.naming.ExternalContext"
       name=":service=ExternalContext,jndiName=ldap/main" >
       <attribute name="JndiName">ldap/main</attribute>
       <attribute name="Properties">ldap.properties</attribute>
       <attribute name="InitialContext">
      javax.naming.ldap.InitialLdapContext</attribute>
       <attribute name="RemoteAccess">true</attribute>
       </mbean>


      When looking at the binding (using JNDIView), I see that the proxy created by jboss implements

      In the code, I request a context like this:
      LdapContext ctx = (LdapContext)new InitialContext().lookup( "ldap/main" );


      A check of the context by calling instanceof DirContext return true after the lookup.

      The problem is, that everytime any operation must actually be performed using the context (like ctx.search()), an exception is thrown:

      javax.naming.NotContextException: Not an instance of DirContext
       at javax.naming.directory.InitialDirContext.getURLOrDefaultInitDirCtx(Unknown Source)
       at javax.naming.directory.InitialDirContext.search(Unknown Source)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at org.jboss.naming.ExternalContext$CachedContext.invoke(ExternalContext.java:538)
       at $Proxy39.search(Unknown Source)


      I don't know if I'm misunderstanding the way that jboss is making the proxies.. The InitialDirContext.getURLOrDefaultInitDirCtx is also using instanceof to check the instance of the parameter.

      Could anyone advice how to overcome this problem, or maybe point me "in the right direction" ?