Browse DevX
Sign up for e-mail newsletters from DevX


Build the Netscape Directory Server SDK from Source : Page 2

Get a comprehensive guide through the process of obtaining LDAP client software (Netscape Directory SDK), building it from source, and testing the interface with Netscape Directory Server.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Building the SDK from Source
Building the SDK from source would seem to be a straightforward process, but my personal experiences have proved otherwise. While it can be a very easy process that you practically sleepwalk through, it also can be quite involved, requiring several detailed steps. The aim of this section is to streamline the process for you as much as possible.

You can build the source in two ways: using make files or using Ant. The source code ships with both. For those of you who are familiar and comfortable with make files, you are welcome to use them to build the source. I personally find this approach to be very frustrating. If you select this approach, follow the build instructions for your platform as detailed here. I recommend the Ant approach, which is both Java-centric and cross-platform. Follow these steps to build with Ant:

  1. Extract the files.
  2. Navigate to mozilla\directory\java-sdk.
  3. Type ant.
  4. Study the list of targets and run the target(s) that you need.

For a basic build, I recommend the following targets:

ant dist-docs ant dist-jdk

This will build the JavaDocs for the SDK (mozilla\directory\java-sdk\dist\doc), as well as a JAR file containing the basic LDAP access classes (mozilla\directory\java-sdk\dist\packages).

Building the LDAP Filters (Reg Exp with Jakarta-ORO)
The filter classes enhance the basic SDK by supporting regular expression filtering of LDAP entries in a lookup/search procedure. The filter classes written for the SDK rely upon an external regular expression engine developed by Daniel Savarese and distributed by ORO, Inc. Savarese founded ORO and donated the source code to the Apache Jakarta project in June 2000. At the time that the SDK classes were written, ORO still owned the software, thus the package namespaces begin with “com.oroinc”. Once Apache received the software, it changed the packaging to match its naming conventions (org.apache.oro).

In order to successfully compile the filter classes, you must change all references to the old ORO packaging to reference the new names. Fortunately, the API has remained untouched in every other way (class names, method signatures, etc.), so the necessary changes are relatively minor.

The compilation steps are as follows:

  1. Navigate to mozilla\directory\java-sdk\ldapfilter\netscape\ldap\util.
  2. Change the import statements in: LDAPFilterDescriptor.java, LDAPIntFilterList.java, LDAPIntFilterSet.java from com.oroinc.text.regex.* to org.apache.oro.text.regex.*.
  3. Save and close the source files.
  4. Navigate to mozilla\directory\java-sdk.
  5. Open the build.properties file.
  6. Uncomment the last line (remove the # sign).
  7. Change the path so that it points to the Jakarta-ORO jar file (jakarta-oro-x.x.x.jar).
  8. Save and close the file.
  9. Run ant build to build the entire SDK, or ant dist-filter to build just the filter JAR.

Now that you have built the SDK (either in part or in whole), you are ready to try it out.

Testing the Interface
The first step is to include the JAR file(s) in your system classpath. This could be as simple as including ldapjdk.jar, ldapjdk.jar and jakarta-oro-2.0.8.jar, or all of the Netscape Directory SDK jars in your classpath. The simple test in this article requires you to place only the ldapjdk.jar file in your classpath.

With your classpath set up, you are prepared to write a test program. The following are the five essential steps for performing an LDAP operation on a server:

  1. Create a new LDAPConnection object.
    Use a variable of type LDAPv2 or LDAPv3 to ensure that the API you are using is appropriate for your server's LDAP version support.
  2. Use the connect() method to connect to the LDAP server.
    LDAPv2 declares two connect() methods: one that accepts a host and port, another that also accepts a name and password for authentication. LDAPv3 adds a connect() method that allows you to specify the LDAP version number.
  3. Use the authenticate() method to authenticate to the server.
    If you didn’t authenticate in the connect() method, then you will need to invoke authenticate() separately. For LDAPv2, supply a name and password. LDAPv3 adds an authenticate() method that accepts an LDAP version number.
  4. Perform the LDAP operation.
    You have a variety of LDAP operations (add an entry, compare entries, delete an entry, modify an entry, read an entry, rename an entry, search entries, etc.) and corresponding methods.
  5. Use the disconnect() method to disconnect from the server when done.
    As with any external resource, closing the server connection when you are through is important. You typically can best handle this in a finally{} block.

To see a complete example, download the accompanying source code for this article.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date