views:

345

answers:

2

Hi guys!

I'm trying to run an embedded ApacheDS in my application. After reading http://directory.apache.org/apacheds/1.5/41-embedding-apacheds-into-an-application.html I build this:

public void startDirectoryService() throws Exception {
    service = new DefaultDirectoryService();
    service.getChangeLog().setEnabled( false );

    Partition apachePartition = addPartition("apache", "dc=apache,dc=org");
    addIndex(apachePartition, "objectClass", "ou", "uid");

    service.startup();

    // Inject the apache root entry if it does not already exist
    try
    {
        service.getAdminSession().lookup( apachePartition.getSuffixDn() );
    }
    catch ( LdapNameNotFoundException lnnfe )
    {
        LdapDN dnApache = new LdapDN( "dc=Apache,dc=Org" );
        ServerEntry entryApache = service.newEntry( dnApache );
        entryApache.add( "objectClass", "top", "domain", "extensibleObject" );
        entryApache.add( "dc", "Apache" );
        service.getAdminSession().add( entryApache );
    }
}

But I can't connect to the server after running it. What is the default port? Or am I missing something?

Here is the solution:

    service = new DefaultDirectoryService();
    service.getChangeLog().setEnabled( false );

    Partition apachePartition = addPartition("apache", "dc=apache,dc=org");

    LdapServer ldapService = new LdapServer();
    ldapService.setTransports(new TcpTransport(389));
    ldapService.setDirectoryService(service);

    service.startup();
    ldapService.start();
A: 

The default port for LDAP is 389.

JuanZe
But is it the default port for ApacheDS too? And is ApacheDS creating an LDAP access with the above code...?
cringe
I use Apache Directory Studio to browse LDAP, but I'm not familiar with running an embedded ApacheDS. Just answered your question about the default port for LDAP.
JuanZe
I dowloaded the sample code and the libraries and run it from Eclipse. The output shows:log4j:WARN No appenders could be found for logger (org.apache.directory.server.schema.registries.DefaultNormalizerRegistry).log4j:WARN Please initialize the log4j system properly.Found entry : ServerEntry dn[n]: dc=Apache,dc=Org objectClass: extensibleObject objectClass: domain objectClass: top dc: Apache
JuanZe
+1  A: 

Here is an abbreviated version of how we use it:

File workingDirectory = ...;

Partition partition = new JdbmPartition();
partition.setId(...);
partition.setSuffix(...);

DirectoryService directoryService = new DefaultDirectoryService();
directoryService.setWorkingDirectory(workingDirectory);
directoryService.addPartition(partition);

LdapService ldapService = new LdapService();
ldapService.setSocketAcceptor(new SocketAcceptor(null));
ldapService.setIpPort(...);
ldapService.setDirectoryService(directoryService);

directoryService.startup();
ldapService.start();
Kevin
Thanks, that's it. I had to change some lines to match my version of ApacheDS. You can see the result in the question.
cringe