Retrieving the factory from JNDI

 

To retrieve an object from a JNDI namespace, set up an initial context, as shown in this fragment taken from the IVTRun sample file:

import javax.jms.*;
import javax.naming.*;
import javax.naming.directory.*;
 .
 .
 .
  java.util.Hashtable environment = new java.util.Hashtable();
  environment.put(Context.INITIAL_CONTEXT_FACTORY, icf);
  environment.put(Context.PROVIDER_URL, url);
  Context ctx = new InitialDirContext( environment );
where:

icf

defines a factory class for the initial context

url

defines a context specific URL

For more details about JNDI usage, see Sun's JNDI documentation.

Some combinations of the JNDI packages and LDAP service providers can result in an LDAP error 84. To resolve the problem, insert the following line before the call to InitialDirContext.

environment.put(Context.REFERRAL, "throw");

Once an initial context is obtained, objects are retrieved from the namespace by using the lookup() method. The following code retrieves a QueueConnectionFactory named ivtQCF from an LDAP-based namespace:

QueueConnectionFactory factory;
factory = (QueueConnectionFactory)ctx.lookup("cn=ivtQCF");


uj24350_