First of all, I am a new Glasfish user, so hi everyone :-)
I wrote code to recursively list JNDI in glassfish):
[code]
public class JNDITestServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
try {
InitialContext ictx = new InitialContext();
Context ctx = (Context) ictx.lookup("java:");
out.println("java: = " + ctx.getClass().getName());
printContext(out, ctx, 1);
} catch (Exception exc) {
throw new ServletException(exc);
}
}
private void printContext(PrintWriter out, Context ctx, int indent) throws ServletException, IOException, NamingException {
NamingEnumeration<Binding> en = ctx.listBindings("");
while (en.hasMore()) {
Binding b = en.next();
char[] tabs = new char[indent];
Arrays.fill(tabs, '\t');
out.println(new String(tabs) + b.getName() + " = " + b.getClassName());
try {
if (b.getObject() instanceof Context) {
printContext(out, (Context) b.getObject(), indent + 1);
}
} catch (Exception exc) {
throw new ServletException(exc);
}
}
}
}
[/code]
The only thing that happens when I go to the page generated by this servlet is:
[code]java: = com.sun.enterprise.naming.java.javaURLContext[/code]
When I debug, it turns out that the enumeration is empty. The same happens no matter if I start with "java:" (as posted), "java:/comp", "java:comp/env" - it only prints the context url and class, and that's it. When I run ths code in tomcat 6.0.18, and start with "java:", the "comp", then "env" context are listed, and their respective bindings are also listed. What am I doing wrong here? Version used:
[code]Version = Sun Java System Application Server 9.1_02[/code]
as printed by "asadmin version".
Thanks.
[Message sent by forum member 'szczyp' (szczyp)]
http://forums.java.net/jive/thread.jspa?messageID=315546