SUN LDAP Context Factory

From an IBM Developer Kit for the Java Platform configuration point of view, it is much easier to use the SUN LDAP Context Factory, since it is provided in the IBM Developer Kit for the Java Platform base and has no dependencies outside of it. However, because this context factory does not understand the namespace structure that exists on any LDAP server configured for WebSphere, it can be more demanding for the client application programmer. CICS provides some namespace helper functions that ease this added complexity. The com.ibm.cics.portable.CICSNameSpaceHelper class is provided in CICSEJBClient.jar. This JAR file is available in the utils subdirectory in the HFS area where CICS is installed.

Here is an example of using this class:
       import org.omg.CORBA.ORB;
       import java.io.*;
       import examples.helloworld.*;
       import javax.naming.*;
       import javax.naming.directory.*; 
       import java.util.*; 
       import com.ibm.cics.portable.CICSNameSpaceHelper;

       public class SUNNamingClient {

       public static void main(String[] argv) {

          try {
             Hashtable env = new Hashtable();

      // Set up the first two obvious properties, the Sun LDAP factory and LDAP server
             env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
             env.put(Context.PROVIDER_URL,   "ldap://wibble.hursley.ibm.com:389");
      // These two settings match the values from the CICS system
             env.put("com.ibm.ws.naming.ldap.containerdn",  "ibm-wsnTree=WASNaming,c=us");
             env.put("com.ibm.ws.naming.ldap.noderootrdn",  
                   "ibm-wsnName=legacyroot,ibm-wsnName=PLEX2,ibm-wsnName=domainRoots");        

      // Use the LDAPSNSLookup helper method to negotiate the WebSphere System Name
      // Space on wibble.hursley.ibm.com and locate our HelloWorld bean.  "samples"
      // is the JNDI prefix on the CICS CorbaServer that published the HelloWorld Bean.
     	       org.omg.CORBA.Object obj =   
             CICSNameSpaceHelper.LDAPSNSLookup(env,"samples/HelloWorld");

	         HelloWorldHome hhome = 
                  (HelloWorldHome)javax.rmi.PortableRemoteObject.narrow
                  (obj,HelloWorldHome.class);

	         System.out.println("HelloWorld home successfully found!");
	         Hello hello = hhome.create();
            System.out.println(hello.sayHello());
	      } catch (Exception e) {
	        System.err.println("Exception whilst looking up and calling the HelloWorld bean:");
        e.printStackTrace();
     }
   }
 }		

You are using the SUN LDAP code, which understands the providerURL property, rather than the masterurl property used in the WebSphere Context Factory example.

The helper class CICSNameSpaceHelper may also work with other context factories. Notice that the syntax of the name passed to LDAPSNSLookup is JNDI syntax a/b/c/d.