I suggest you take a look at the sample present here[1] [1] http://svn.apache.org/repos/asf/directory/sandbox/kayyagari/embedded-sample-trunk/
On Fri, Oct 31, 2014 at 6:48 PM, brock samson <[email protected]> wrote: > my application is osgi-based, which contains an embedded ADS instance in a > form of an osgi bundle. i am in the process of upgrading from 1.5.7 to > 2.0.0m17. i have a security dir that contains a schema subdirectory > extracted from 1.5.7 shared-ldap-schema-0.9.19.jar before the ldap starts > up. so i performed the same for 2.0.0m17 by extracting the same > subdirectory from apacheds-service-2.0.0-M17.jar. as my application starts > up, i am using java to start up the embedded ADS instance. it worked > flawlessly using ADS 1.5.7, but i am having problems with 2.0.0m17. below > is the bundle's java code that i have adjusted from 1.5.7 to accommodate > 2.0.0m17: > > package com.myembeddedldap; > > import org.apache.directory.server.constants.ServerDNConstants; > import org.apache.directory.server.core.DefaultDirectoryService; > import > org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition; > import org.apache.directory.server.core.partition.ldif.LdifPartition; > import org.apache.directory.server.core.api.schema.SchemaPartition; > import org.apache.directory.server.ldap.LdapServer; > import org.apache.directory.server.protocol.shared.transport.TcpTransport; > import org.apache.directory.api.ldap.model.name.Dn; > import org.apache.directory.api.ldap.model.schema.SchemaManager; > import org.apache.directory.api.ldap.schemaloader.LdifSchemaLoader; > import > org.apache.directory.api.ldap.schemamanager.impl.DefaultSchemaManager; > import org.apache.directory.api.ldap.model.schema.registries.SchemaLoader; > import org.apache.directory.server.core.api.InstanceLayout; > import org.apache.directory.server.core.shared.DefaultDnFactory; > > import java.io.*; > import java.util.List; > > > public class MyEmbeddedLDAP { > > private DefaultDirectoryService directoryService_; > private LdapServer ldapServer_; > > private static final File SECURITY_DIR = new File("security"); > > > public void start() > throws Exception { > > directoryService_ = new DefaultDirectoryService(); > directoryService_.setInstanceLayout(new > InstanceLayout(SECURITY_DIR)); > > directoryService_.setAllowAnonymousAccess(true); > directoryService_.setAccessControlEnabled(false); > // directoryService.setExitVmOnShutdown(false); > directoryService_.setShutdownHookEnabled(false); > directoryService_.getChangeLog().setEnabled(false); > > SchemaLoader loader = new LdifSchemaLoader(new File(SECURITY_DIR, > "schema")); > SchemaManager schemaManager = new DefaultSchemaManager(loader); > schemaManager.loadAllEnabled(); > > directoryService_.setSchemaManager(schemaManager); > directoryService_.setDnFactory(new DefaultDnFactory(schemaManager, > null)); > > LdifPartition ldifPartition = new LdifPartition(schemaManager, > directoryService_.getDnFactory()); > > SchemaPartition schemaPartition = new SchemaPartition(schemaManager); > schemaPartition.setWrappedPartition(ldifPartition); > > directoryService_.setSchemaPartition(schemaPartition); > > List<Throwable> errors = schemaManager.getErrors(); > > if (!errors.isEmpty()) { > for (Throwable thr : errors) { > System.out.println(thr.getMessage()); > } > } > > JdbmPartition systemPartition = new JdbmPartition(schemaManager, > directoryService_.getDnFactory()); > systemPartition.setId("system"); > systemPartition.setPartitionPath(new File(SECURITY_DIR, > "system").toURI()); > systemPartition.setSuffixDn(new Dn(ServerDNConstants.SYSTEM_DN)); > systemPartition.setSchemaManager(schemaManager); > directoryService_.setSystemPartition(systemPartition); > > ldapServer_ = new LdapServer(); > ldapServer_.setTransports(new TcpTransport(10389)); > ldapServer_.setDirectoryService(directoryService_); > > directoryService_.startup(); > ldapServer_.start(); > > } > > > public void stop() > throws Throwable { > directoryService_.shutdown(); > ldapServer_.stop(); > } > } > > yet unlike my bundle with the ADS 1.5.7, i am getting the following error > when my ADS 2.0.0m17 bundle attempts to start: > > org.apache.directory.api.ldap.model.exception.LdapOtherException: > org.apache.directory.api.ldap.model.exception.LdapOtherException > at > org.apache.directory.server.core.api.partition.AbstractPartition.initialize(AbstractPartition.java:94) > at > org.apache.directory.server.core.DefaultDirectoryService.initialize(DefaultDirectoryService.java:1795) > at > org.apache.directory.server.core.DefaultDirectoryService.startup(DefaultDirectoryService.java:1244) > at > com.teamcenter.esb.internal.ldap.EmbeddedLDAPServer.start(EmbeddedLDAPServer.java:75) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native > Method)[:1.7.0_01] > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)[:1.7.0_01] > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.7.0_01] > at java.lang.reflect.Method.invoke(Method.java:601)[:1.7.0_01] > at > org.apache.aries.blueprint.utils.ReflectionUtils.invoke(ReflectionUtils.java:297)[7:org.apache.aries.blueprint.core:1.1.0] > at > org.apache.aries.blueprint.container.BeanRecipe.invoke(BeanRecipe.java:958)[7:org.apache.aries.blueprint.core:1.1.0] > at > org.apache.aries.blueprint.container.BeanRecipe.runBeanProcInit(BeanRecipe.java:712)[7:org.apache.aries.blueprint.core:1.1.0] > ... 34 more > Caused by: java.lang.RuntimeException: > org.apache.directory.api.ldap.model.exception.LdapOtherException > at > org.apache.directory.server.core.api.schema.SchemaPartition.doInit(SchemaPartition.java:226) > at > org.apache.directory.server.core.api.partition.AbstractPartition.initialize(AbstractPartition.java:89) > ... 44 more > Caused by: org.apache.directory.api.ldap.model.exception.LdapOtherException > at > org.apache.directory.server.core.api.partition.AbstractPartition.initialize(AbstractPartition.java:94) > at > org.apache.directory.server.core.api.schema.SchemaPartition.doInit(SchemaPartition.java:219) > ... 45 more > Caused by: java.lang.NullPointerException > at java.io.File.<init>(File.java:389)[:1.7.0_01] > at > org.apache.directory.server.core.partition.ldif.LdifPartition.doInit(LdifPartition.java:143) > at > org.apache.directory.server.core.api.partition.AbstractPartition.initialize(AbstractPartition.java:89) > > what am i doing wrong? > > thank you! > -- Kiran Ayyagari http://keydap.com
