Skip to content

Instantly share code, notes, and snippets.

@matthewmccullough
Created December 10, 2008 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewmccullough/34347 to your computer and use it in GitHub Desktop.
Save matthewmccullough/34347 to your computer and use it in GitHub Desktop.
Walk a Java JNDI tree of all nodes
InitialContext initialContext;
StringBuffer sb
try {
sb = new StringBuffer();
initialContext = new InitialContext();
loopLevel(sb, initialContext, "java:comp");
} catch (NamingException e) {
writer.println("<html><body>");
e.printStackTrace(writer);
writer.println("</html></body>");
} catch (Exception e) {
}
writer.println("<html><body>" + sb.toString() + "</html></body>");
}
private void loopLevel(StringBuffer sb, InitialContext initialContext, String name){
try {
NamingEnumeration ne = initialContext.list(name);
sb.append("<ul>");
while (ne.hasMoreElements()) {
NameClassPair ncp = (NameClassPair) ne.nextElement();
sb.append("<li> " + ncp.getName());
loopLevel(sb, initialContext, name + "/" + ncp.getName());
}
sb.append("</ul>");
} catch (NamingException e) {
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment