Listing JMS Destinations ON a JNDI TREE

Hi All, Is there anyay we can get the JMS Destinations that is currently bound to the JNDI Tree? I am very interested in the JNDI names of Queues that are bound on the JNDI.
[187 byte] By [reflex2javaa] at [2007-10-2 16:16:55]
# 1
One more point which I forgot is that I want to list this on my application running on my Application Server.
reflex2javaa at 2007-7-13 17:08:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

you might want to try the code snippet of listing contexts from any java code which is available while server is running.

Context ctx = new InitialContext();

NamingEnumeration list = ctx.list("");

while (list.hasMore()) {

NameClassPair nc = (NameClassPair) list.next();

System.out.println(nc);

}

Two points to take care

1. You might have to initialize intial context with your server specific jndi properties(if its not done already)

2. Once you get the context list , you can repeat this operation on any sub context that is printed to you ..which will effectively lead to navigation on the jndi tree

warrior_rebela at 2007-7-13 17:08:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

Just to add on a bit..in the above mail instead of trying to list try listing bindings

as in ctx.listBindings(). Since you are intrested only in Queues. Listing bindings also gives you the option to see the kind of object on the jndi tree. Modify code a bit accordingly.

Any other optimized approaches from others are welcome coz i am just a beginner.

warrior_rebela at 2007-7-13 17:08:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

Dear Warrior,

I had managed to recursivly browse through the JNDI and get the hashtable which I require. Here is the sample.

/**

* Generates a Hashtable with JNDI name as key and Object type as value.

*

* @param jndiList - the hashtable to append to

* @param ctx- the context for which the bindings are to be listed

* @param path- the path to be listed under a context

*

* @since 0.1

*/

private static void listContext(Hashtable jndiList, Context ctx, String path) {

if (ctx == null) {

return;

}

try {

NamingEnumeration list = ctx.listBindings(path);

while (list.hasMore()) {

Binding item = (Binding) list.next();

String className = item.getClassName();

String name = item.getName();

if (name != null) {

if (name.equals("")) {

continue;

}

} else {

continue;

}

Object o = item.getObject();

if ((className != null) && (name != null) && (o != null)) {

if (o instanceof javax.naming.Context) {

listContext(jndiList, ctx, path + "/" + name);

} else {

jndiList.put(path + "/" + name, className);

}

}

}

} catch (NamingException ne) {

System.err.println(

"Caught NamingException <" + ne.getMessage() + "><"

+ ne.getExplanation() + "><" + ne.toString(true) + ">");

} catch (Exception e) {

System.err.println("Caught Exception <" + e.getMessage() + ">");

}

}

Hope this solves the problem.

reflex2javaa at 2007-7-13 17:08:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5
Can you be kind enough to post the values of input Parameters to this method as well as the output..so that i can visualize the bigger picture?Thanks,Rahul
warrior_rebela at 2007-7-13 17:08:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6

Yes my friend,

listContext(jndiList, ctx, "jms");

And the output table is,

jms/queues/app/APP_QCF=com.ibm.mq.jms.MQQueueConnectionFactorycom.ibm.mq.jms.MQQueueConnectionFactory

jms/queues/app/APP.IN.Q.IE=com.ibm.mq.jms.MQQueuecom.ibm.mq.jms.MQQueue

jms/queues/app/APP.IN.Q.CD=com.ibm.mq.jms.MQQueuecom.ibm.mq.jms.MQQueue

jms/queues/app/APP.IN.Q.IO=com.ibm.mq.jms.MQQueuecom.ibm.mq.jms.MQQueue

reflex2javaa at 2007-7-13 17:08:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 7
One more point I would like to put in front is.It all depends on by what structure you bind objects. In my case I have a convention like all jms stuff will start with "jms". So the same may not work for all. :-(
reflex2javaa at 2007-7-13 17:08:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 8
Well you using the sub context as "jms" for jms binding is an accepted standrard practice, so that shouldnt be a problem :)
warrior_rebela at 2007-7-13 17:08:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 9
Yes you are correct!Check this out If you are interested!!! http://docs.sun.com/app/docs/doc/819-4721/6n6rrfqms?a=view#beant
reflex2javaa at 2007-7-13 17:08:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 10
There you go: http://tripoverit.blogspot.com/2007/03/print-jndi-tree.html
ryanfernandesa at 2007-7-13 17:08:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...