"goja" wrote : 
  | It looks like a JBoss standalone client cannot browse the JNDI binding 
because of a dependency of the client jars on a sar and jboss-server.jar, which 
in turns throws an exception complaining about "No 'jboss' MBeanServer found!".
  | 
  | Any other ideas?
  | 
  | 
  | 
  |   | public class ListJNDIBindings {
  |   | 
  |   |     public static void main(String[] args) {
  |   | 
  |   |         Properties props = new Properties();
  |   |         props.put(Context.INITIAL_CONTEXT_FACTORY, 
org.jnp.interfaces.NamingContextFactory.class.getName());
  |   |         props.put(Context.PROVIDER_URL, "jnp://localhost:1099");
  |   |         props.put(Context.URL_PKG_PREFIXES, 
"org.jboss.naming:org.jnp.interfaces");
  |   | 
  |   |         try {
  |   |             Context context = new InitialContext(props);
  |   |             NamingEnumeration<Binding> ne = context.listBindings("");
  |   |             while (ne.hasMore()) {
  |   |                 System.out.println(ne.nextElement());
  |   |             }
  |   |         } catch (NamingException e) {
  |   |             // TODO Auto-generated catch block
  |   |             e.printStackTrace();
  |   |         }
  |   |     }
  |   | }
  |   | 

Well, if you look at the code that you posted, you are using the listBindings 
API on the Context, which as per the javadoc:

anonymous wrote : Enumerates the names bound in the named context, along with 
the objects bound to them.

Any application can bind any object to the JNDI tree and if you use the 
listBindings API on the client side then effectively you will have to have the 
class/jar files of those objects on the client side. 

If you want to browse the JNDI tree then you can use the list() API available 
on the Context as follows:
  | 
  | package org.myapp;
  | 
  | import java.util.Properties;
  | 
  | import javax.naming.Binding;
  | import javax.naming.Context;
  | import javax.naming.InitialContext;
  | import javax.naming.NamingEnumeration;
  | import javax.naming.NamingException;
  | 
  | public class ListJNDIBindings {
  | 
  |     public static void main(String[] args) {
  | 
  |         Properties props = new Properties();
  |         props.put(Context.INITIAL_CONTEXT_FACTORY, 
org.jnp.interfaces.NamingContextFactory.class.getName());
  |         props.put(Context.PROVIDER_URL, "jnp://localhost:1099");
  |         props.put(Context.URL_PKG_PREFIXES, 
"org.jboss.naming:org.jnp.interfaces");
  | 
  |         try {
  |             Context context = new InitialContext(props);
  |             NamingEnumeration ne = context.list("");
  |             
  |             while (ne.hasMore()) {
  |                 System.out.println(ne.nextElement());
  |             }
  |         } catch (NamingException e) {
  |             // TODO Auto-generated catch block
  |             e.printStackTrace();
  |         }
  |     }
  | }

The javadoc of the list API mentions:

anonymous wrote : Enumerates the names bound in the named context, along with 
the class names of objects bound to them

In this case you need not have the jar/class files of the all the objects bound 
to the JNDI tree. I was able to get this code working by including the 
jbossall-client.jar file in the client's classpath.


View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4112596#4112596

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4112596
_______________________________________________
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to