Try OpenEdge Now
skip to main content
Messaging and ESB
Working with the Generic JMS Adapter : Configuring and administering the Generic JMS Adapter : Configuring the Connection Factory : Using JNDI administered objects
 
Using JNDI administered objects
You can locate the connection factory by using JNDI to find the JMS-administered objects in the JNDI namespace.
To prevent class conflict with the AdminObjectFinder.java file, the generic JMS adapter packages the class in a different package, jmsfromABL(not jmsfrom4gl). This new class provides the adapter with the configuration to find the JMS-administered objects in the JNDI namespace.
1. Use the following example to create a jmsfromABL.AdminObjectFinder.java class file.
AdminObjectFinder.java for 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);
}
}
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory")
Specifies the name of the context factory class for WebSphereMQ.
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 connection factory resides in a .bindings file and for ActiveMQ, in the jndi.properties file.
env.put(Context.PROVIDER_URL, "file:/C:/JNDI")
Specifies the location of the JNDI .bindings file. For WebSphereMQ, the location of .bindings file and for ActiveMQ, the location of jndi.properties file.
env.put(Context.SECURITY_PRINCIPAL, "username"); env.put(Context.SECURITY_CREDENTIALS, "password")
Specifies the security credentials to access the MQService
*The jmsfromABL.AdminObjectFinder name is mandatory in the class file.
*The class and the get...() methods must be declared as a public element .
2. Compile the jmsfromABL.AdminObjectFinder.java class file and place it in a new JAR file.
3. Add the location of this new JAR file to the pluginclasspath and classpath variables in the AdminServerPlugins.properties file, as in the following example:
[PluginPolicy.Progress.SonicMQ]

pluginclasspath=C:\Progress115\OpenEdge/java/progress.jar,
C:\PROGRA~2\IBM\WEBSPH~1\java\lib\com.ibm.mqjms.jar,
C:\AdminObjectFinder.jar

classpath=C:\Progress115\OpenEdge/java/progress.jar,
C:\PROGRA~2\IBM\WEBSPH~1\java\lib\com.ibm.mqjms.jar,
C:\AdminObjectFinder.jar

jvmargs=-DsonicMQExtensions=false -DjmsProvider=WebSphereMQ