An ejb-jar deployed to jboss 7 has a jdni binding "java:global/foo!IFoo". Jboss management console shows this binding. The jndi port is 1099 as by default. A client on jboss gets an object to that binding but a standalone client running on the same machine does not.
Properties properties = new Properties();
properties.put("java.naming.factory.initial",
"org.jboss.as.naming.InitialContextFactory");
properties.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
properties.put("java.naming.provider.url","jnp://localhost:1099");
Context ctx = new InitialContext(properties);
NamingEnumeration<NameClassPair> list = ctx.list("");
while (list.hasMore()) {
System.out.println(list.next().getName());
}
produces no results. Also the lookup to the name above fails. Where is the problem ?
It seems remote JNDI lookup support was implemented only on JBoss AS 7.1.0.Final (AS7-1338).
The JNDI properties to perform remote lookups has also changed. Could you try to instantiate the InitialContext
with these JNDI properties?
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
properties.put(Context.PROVIDER_URL, "remote://localhost:4447");
properties.put(Context.SECURITY_PRINCIPAL, "user");
properties.put(Context.SECURITY_CREDENTIALS, "password");
The remote access to the JNDI tree is secured, so you need to provide a user and a password (add an Application User via add-user.sh
/add-user.bat
script).
I did this on my own local server, but the NamingEnumeration
returned by InitialContext.list()
is still empty, even though the lookup below works fine. I posted an answer on JBoss forum, but no luck so far.
// This lookup works fine
System.out.println(ctx.lookup("jms/RemoteConnectionFactory").getClass().getName());
// ... but this list doesn't (empty enumeration)
NamingEnumeration<NameClassPair> list = ctx.list("");