Created
December 10, 2008 15:25
-
-
Save matthewmccullough/34347 to your computer and use it in GitHub Desktop.
Walk a Java JNDI tree of all nodes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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