Jump to content

JNDI with different InitialContexts


Recommended Posts

OK, this is a really long shot, but maybe one of you programming geeks has experience of JNDI and NameServers? I can't find the answers anywhere and it's driving me crazy.

 

What I want to do is use JNDI to access a remote NameServer, so I give the parameters of my server into the InitialContext:

Properties props = new Properties();
// set up properties including URL of NameServer etc
InitialContext ctx = new InitialContext(props);
Object obj = ctx.lookup(lookupName);

This works.

 

The problem comes when I (well actually not me, but we can reproduce the problem this way) make a different lookup before using a raw InitialContext:

Object obj2 = new InitialContext().lookup(anything); // works!

Properties props = new Properties();
// set up properties including URL of NameServer etc
InitialContext ctx = new InitialContext(props);
Object obj = ctx.lookup(lookupName); // FAILS

This fails because it doesn't even ask the remote nameserver any more, it continues to just look in the local nameserver.

 

We can look at the ctx object and it looks exactly as it did in the first example, all the properties are still there but it just doesn't use them - it just looks in the local namespace and doesn't find the name any more.

 

Take out the first call, the second call works. Put the first call back in again, the second call fails. How can we persuade the second call to really access the remote nameserver?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...