5 Replies Latest reply: Oct 25, 2012 2:37 AM by Marko Asplund RSS

In JBoss AS 7.1.1.Final InitialContext.list() returns empty list

Mauricio Nagaoka Newbie

Hi!

 

I'm trying to browse the JMS queue on a JBoss AS 7.1.1.Final using Hermes JMS, but I'm getting an "empty" JNDI tree. To investigate this, I wrote a simple program to dump the JNDI tree nodes from a JBoss server. The code is something like this:

 

public static void main(String[] args) throws Exception {

     final Properties jndiProperties = getJboss7Properties();
     // final Properties jndiProperties = getHornetQProperties();


     // Dumps the initial context contents
     InitialContext ctx = new InitialContext(jndiProperties);
     listRootJndiContext(ctx);


     // Simple lookup
     System.out.println(ctx.lookup("java:jms/RemoteConnectionFactory")
               .getClass().getName());
}

private static Properties getJboss7Properties() {
     final Properties jndiProperties = new Properties();
     jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY,
               "org.jboss.naming.remote.client.InitialContextFactory");
     jndiProperties.put(Context.PROVIDER_URL, "remote://localhost:4447");
     jndiProperties.put(Context.SECURITY_PRINCIPAL, "guest");
     jndiProperties.put(Context.SECURITY_CREDENTIALS, "guest123");
     return jndiProperties;
}

private static void listRootJndiContext(Context ctx) throws NamingException {
          System.out.println("Listing root JNDI context:");
          NamingEnumeration<NameClassPair> list = ctx.list("");
          if (list.hasMore()) {
                    while (list.hasMore()) {
                              NameClassPair ncp = list.next();
                              System.out.println(ncp.getName() + " (" + ncp.getClassName() + ")");
                    }
          } else {
                    System.out.println("Empty list!");
          }
}

 

When calling ctx.list(""), the returned list is always empty, even though a ctx.lookup("java:jms/RemoteConnectionFactory") returns a JMS Connection Factory as expected.

 

I tried to run the exact same code against a stand alone HornetQ server (2.2.14.Final), changing the InitialContext properties to use the "old" jnp protocol and the JNDI tree nodes were dumped correctly.

 

(Edit) I also tried to run the same code (except for invoking the default InitialContext() constructor) within the server (in a Servlet) and it also worked as expected (dumping the JNDI tree nodes).

 

Is there any permission to be configured on standard.xml or something like that?

Is this feature ("Remote JNDI browsing") implemented at all on JBoss AS 7.1.1.Final?

 

Thank you!

Mauricio