Can any one tell or point me to code to list all the jndi entries in a remote machine
Can any one tell or point me to code to list all the jndi entries in a remote machine
It is possible to list all entries of an InitialContext. You can use this snippet:
InitialContext ctx = new InitialContext();
NamingEnumeration<NameClassPair> list = ctx.list("");
while (list.hasMore()) {
System.out.println(list.next().getName());
}
If you are using an application server, there is usually the option to browse the JNDI tree.
I'm using following code (not for production):
public void discoverJndi(String path, Context context) throws TestClientException, NamingException {
try {
NamingEnumeration<NameClassPair> list = context.list(path);
while (list.hasMore()) {
String name = list.next().getName();
String child = path.equals("") ? name : path + "/" + name;
System.out.println(child);
discoverJndi(child, context);
}
} catch (NotContextException e) {}
}