Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Step 1: The web component which starts and stops the server

The ApacheDS core is a JNDI provider that manages a local hierarchical store of Attributes objects, based on the LDAP namespace. JNDI is the access API used to hide internals, and it is also used to configure the core.

A helper class for configuration

In order to keep the source code of this example simple, the following class is used to provide the environment to the other classes. Standard JNDI keys are used to tell JNDI what the provider is etc.

...


package org.apache.directory.samples.embed.webapp;

import java.util.Hashtable;
import java.util.Properties;

import javax.naming.Context;

public class EnvHelper {

    public static Hashtable createEnv() {
        Hashtable env = new Properties();

        env.put(Context.PROVIDER_URL, "");
        env.put(Context.INITIAL_CONTEXT_FACTORY,
                "org.apache.directory.server.jndi.ServerContextFactory");

        env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system");
        env.put(Context.SECURITY_CREDENTIALS, "secret");
        env.put(Context.SECURITY_AUTHENTICATION, "simple");

        return env;
    }
}

...

comprised of JavaBeans components, and can easily be instantiated started and stopped with simple Java code. This is done by the following listener.

The class StartStopListener implements ServletContextListener and therefore contains the following two life cycle methods:

...