Skip to content

Instantly share code, notes, and snippets.

@thejavalistener
Last active August 29, 2015 14:02
Show Gist options
  • Save thejavalistener/46740887bb502c148895 to your computer and use it in GitHub Desktop.
Save thejavalistener/46740887bb502c148895 to your computer and use it in GitHub Desktop.
package com.thejavalistener.post.jndiintrospector;
import javax.naming.Binding;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingEnumeration;
public class JndiIntrospector
{
public static void print()
{
try
{
Context ctx = new InitialContext();
String n = ctx.getNameInNamespace();
_print(n);
}
catch(Exception ex)
{
ex.printStackTrace();
throw new RuntimeException();
}
}
private static void _print(String name) throws Exception
{
try
{
System.out.println("Name in manespace: "+name);
Context ctx = new InitialContext();
NamingEnumeration<Binding> list = ctx.listBindings(name);
while( list.hasMoreElements() )
{
Binding b = list.nextElement();
String s = b.getName();
_print(name+"/"+s);
}
}
catch(Exception ex)
{
// ignore
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment