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
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.
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.
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