Use the following code to create an AdminObjectFinder.java file IBM WebsphereMQ:

package jmsfromABL;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.TopicConnectionFactory;
import javax.jms.QueueConnectionFactory;
import javax.jms.Topic;
import javax.jms.Queue;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
import java.util.Hashtable;
 
public class AdminObjectFinder{
 
    public Context context = null;
    public AdminObjectFinder() throws Exception{
 
        Hashtable<String, String> env = new Hashtable<>();
        env.put(Context.INITIAL_CONTEXT_FACTORY, 
         "com.sun.jndi.fscontext.RefFSContextFactory");
        env.put(Context.PROVIDER_URL, "file:/C:/JNDI");
        env.put(Context.SECURITY_PRINCIPAL, "username");
        env.put(Context.SECURITY_CREDENTIALS, "password");
        context = new InitialContext(env);
    }
 
    public TopicConnectionFactory getTopicConnectionFactory(String name)
    throws Exception {
        TopicConnectionFactory factory = null;
        factory = (javax.jms.TopicConnectionFactory)context.lookup(name);
        return factory;
    }
 
    public QueueConnectionFactory getQueueConnectionFactory(String name)
    throws Exception {
        QueueConnectionFactory factory = null;
        factory = (javax.jms.QueueConnectionFactory)context.lookup(name);
        return factory;
    }
 
    public ConnectionFactory getConnectionFactory(String name)
    throws NamingException {
        return (ConnectionFactory) context.lookup(name);
    }
 
    public Topic getTopic(String name) throws Exception {
        Topic topic = null;
        Object object = null;
        object = context.lookup(name);
        if (object != null) {
            topic = (javax.jms.Topic) object;
        }
        return topic;
    }
 
    public Queue getQueue(String name) throws Exception {
        Queue queue = null;
        Object object = null;
        object = context.lookup(name);
        if (object != null) {
            queue = (javax.jms.Queue) object;
        }
        return queue;
    }
 
    public Destination getDestination(String name)
    throws NamingException {
        return (Destination) context.lookup(name);
    }
}

Where:

env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory")
Specifies the name of the context factory class for WebSphereMQ.
Note: This example assumes that JNDI .bindings file is placed at a physical location in the FileSystem and thus is referred to as RefFileSystemContextFactory. This .binding file contains attributes that are used to create a ConnectionFactory object and other JNDI resources. For WebSphereMQ, the attributes to create a connection factory resides in a .bindings file.
env.put(Context.PROVIDER_URL, "file:/C:/JNDI")
Specifies the location of the JNDI .bindings file. For WebSphereMQ, the location of .bindings file.
env.put(Context.SECURITY_PRINCIPAL, "username"); env.put(Context.SECURITY_CREDENTIALS, "password")
Specifies the security credentials to access the MQService.
Note:
  • The jmsfromABL.AdminObjectFinder name is mandatory in the class file.
  • The class and the get...() methods must be declared as a public element.