Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

Embedding ApacheDS as a Web Application

...

...

This site was updated for ApacheDS 1.5.5.
Maven archetype depends on the current trunk.

...

My initial aim was to demonstrate embedding ApacheDS in a very simple, but nevertheless impressive way. I thought about embedding the server in Apache Tomcat first. But then I got a better plan: Creating a standard web application which wraps ApacheDS and can be deployed on any compliant application server. ApacheDS in a war-archive!

...

Although the concepts depicted below apply to all version of ApacheDS (even before 1.0), the configuration for starting and stopping the embedded server uses the style introduced with ApacheDS 1.5.5. Be sure that you use this version of the server, or a later one.

...

Although it works well, please note that this is just an example on how to embed ApacheDS in an application! If you plan to run the server as LDAP production system, this is not the first option to consider. Some more steps have to be done, especially in the area of configuration.

...

The method contextDestroyed simply stops the protocol and shuts down the service.

...

...

Deployment descriptor

In order to execute the listener code, the class has to be defined in the deployment descriptor of a web application, as depicted below:

...

Packaging and Deploying the WebApp

...

To use the archetype you'll need to check it out and install it to your local repository:

...

...

Then change to your preferred location to create the new project and execute following command:

...

Then change to the created directory and run the following command:

...

...

This creates an ApacheDS.war file below the target folder.

...

The fastest way to run the web application is to use the Maven Jetty plugin:

...

...

The sample servlet 'RootDseServlet' is available at the following URL:

...

...

excerpttrue

hiddentrue
A standard web archive (war-File) is needed in order to deploy the application to a servlet container. The Resources area at the end of this page provides a zip-File which contains the file structure. A build script for Apache Ant is included as well.

Directory layout for the sources, war file layout

The build script assumes that you have ApacheDS 1.5.5 and Tomcat 6.0.18 installed locally; it uses and (in the case of ApacheDS) copies the necessary files from their lib directories to the lib directory of the web application. You will likely want to adjust the installation directories defined in the build.xml file.

Note: Within the build script, Tomcat is only used for compilation. To be more concrete, only the servlet-api.jar is needed. Other options to provide this library at build time are imaginable, especially if you plan to deploy ApacheDS on a Web Application Server other than Tomcat.

Image Modified

After building the project, the classes folder will contain the compiled class files of the two Java classes above, and a properties file to configure the logging framework log4j. The lib folder will contain all jar-Files necessary, these are

  • antlr-2.7.7.jar
  • apacheds-bootstrap-extract-1.5.4.jar
  • apacheds-bootstrap-partition-1.5.4.jar
  • apacheds-core-1.5.4.jar
  • apacheds-core-avl-1.5.4.jar
  • apacheds-core-cursor-1.5.4.jar
  • apacheds-core-entry-1.5.4.jar
  • apacheds-core-jndi-1.5.4.jar
  • apacheds-core-shared-1.5.4.jar
  • apacheds-jdbm-1.5.4.jar
  • apacheds-jdbm-store-1.5.4.jar
  • apacheds-protocol-ldap-1.5.4.jar
  • apacheds-protocol-shared-1.5.4.jar
  • apacheds-schema-bootstrap-1.5.4.jar
  • apacheds-schema-registries-1.5.4.jar
  • apacheds-utils-1.5.4.jar
  • apacheds-xdbm-base-1.5.4.jar
  • apacheds-xdbm-search-1.5.4.jar
  • commons-collections-3.2.jar
  • commons-lang-2.3.jar
  • log4j-1.2.14.jar
  • mina-core-1.1.6.jar
  • mina-filter-ssl-1.1.6.jar
  • shared-asn1-0.9.12.jar
  • shared-asn1-codec-0.9.12.jar
  • shared-bouncycastle-reduced-0.9.12.jar
  • shared-ldap-0.9.12.jar
  • shared-ldap-constants-0.9.12.jar
  • slf4j-api-1.4.3.jar
  • slf4j-log4j12-1.4.3.jar

The webapp target in the build.xml file (which is the default target) packs the files for the web application together in a web archive called ApacheDS.war.

Deploying on Apache Tomcat

...

One option is a command line tool like ldapsearch (see ApacheDS Basic User's Guide for details on how to connect to ApacheDS with such tools in general). Here is an example how to connect as administrator (simple bind) and fetch the Root DSE of our embedded ApacheDS instance:

...

Another choice are graphical LDAP clients (see ApacheDS Basic User's Guide for details on how to connect to ApacheDS with such tools in general).

...

The following servlet, which will be deployed together with the other class in the web archive, connects to ApacheDS directly, i.e. via the internal JNDI provider. No network access is needed. In the doGet method it performs a search operation against the Root DSE of the server, as the examples above do.

...

In order to make the servlet available to clients, it has to be declared in the deployment descriptor web.xml, here are the additions (a servlet named RootDseServlet for the class above, and a URL mapping)

...

Redeploy the web application. If you point to your tomcat server with the appropriate URL (http://localhost:8080/ApacheDS/RootDse), you'll see the content of the Root DSE as depicted below:

Excerpthidden

true

Download the source code

Image Modified StartStopListener.java (Step 1)
Image Modified RootDseServlet.java (Step 2)
Image Modified web.xml
Image Modified ApacheDSWebApp.zip all sources including a build script for Apache Ant (build.xml)