Problems creating a root context using DirContext::createSubcontext

I am new to both JNDI and LDAP, and I am having a problem with the following basic JNDI code sample. When trying to create arootContext withctx.createSubcontext, an exception is thrown stating:

javax.naming.OperationNotSupportedException: [LDAP: error code 53 - no global superior knowledge]; remaining name 'o=jndiTest'

What does this error mean?

finalstatic String ldapServerName ="backbone.seamonkey";

finalstatic String rootContext ="o=jndiTest";

publicstaticvoid main( String[] args )

{

// set up environment to access the server

Hashtable<Object,Object> env =new Hashtable<Object,Object>();

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

env.put( Context.PROVIDER_URL,"ldap://" + ldapServerName +":389/" );

try{

// obtain initial directory context using the environment

DirContext ctx =new InitialDirContext( env );

// now, create the root context, which is just a subcontext

// of this initial directory context.

ctx.createSubcontext( rootContext );

ctx.close();

}catch ( NameAlreadyBoundException nabe ){

System.err.println( rootContext +" has already been bound!" );

}catch ( Exception e ){

System.err.println( e );

}

}

[2238 byte] By [jeff_seattlea] at [2007-11-27 6:05:40]
# 1

If I modify the Context.PROVIDER_URL to be:

hashEnv.put( Context.PROVIDER_URL, "ldap://" + ldapServerName + ":389/dc=seamonkey, dc=bigfish, dc=lan" );

Then ctx.createSubcontext( rootContext );

throws the following exception:

javax.naming.InvalidNameException: o=jndiTest: [LDAP: error code 34 - invalid DN]; remaining name 'o=jndiTest'

jeff_seattlea at 2007-7-12 16:52:09 > top of Java-index,Core,Core APIs...
# 2

> If I modify the Context.PROVIDER_URL to be:

>

> hashEnv.put( Context.PROVIDER_URL,

> "ldap://" + ldapServerName + ":389/dc=seamonkey,

> dc=bigfish, dc=lan" );

>

> Then ctx.createSubcontext( rootContext

> );

throws the following exception:

>

> javax.naming.InvalidNameException: o=jndiTest:

> [LDAP: error code 34 - invalid DN]; remaining name

> 'o=jndiTest'

This is a tricky error to track down, its essentially telling you when it tried to build up the whole dn including your subcontext it wasn't a valid dn

First I would try removing the spaces from the PROVIDER_URL as they are not escaped

Next do you have attributes that are mandatory, pass those in as the second argument.

Attributes nattrs = new BasicAttributes(true)

Attribute objclass = new BasicAttribute("objectclass");

objclass.add("top")

nattrs.put(objclass);

If you still get an error use a tool like luma to browse your ldap tree and double check the hierachy

accountida at 2007-7-12 16:52:09 > top of Java-index,Core,Core APIs...