栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

运行我的应用程序中嵌入的Apache DS

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

运行我的应用程序中嵌入的Apache DS

我无法同时使用cringe,Kevin和JörgPfünder的版本。在我的JUnit测试中不断收到NPE。我已经调试了所有代码并将它们编译为一个有效的解决方案:

public class DirContextSourceAnonAuthTest {  private static DirectoryService directoryService;  private static LdapServer ldapServer;  @BeforeClass  public static void startApacheDs() throws Exception {    String buildDirectory = System.getProperty("buildDirectory");    File workingDirectory = new File(buildDirectory, "apacheds-work");    workingDirectory.mkdir();    directoryService = new DefaultDirectoryService();    directoryService.setWorkingDirectory(workingDirectory);    SchemaPartition schemaPartition = directoryService.getSchemaService()        .getSchemaPartition();    LdifPartition ldifPartition = new LdifPartition();    String workingDirectoryPath = directoryService.getWorkingDirectory()        .getPath();    ldifPartition.setWorkingDirectory(workingDirectoryPath + "/schema");    File schemaRepository = new File(workingDirectory, "schema");    SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor(        workingDirectory);    extractor.extractOrCopy(true);    schemaPartition.setWrappedPartition(ldifPartition);    SchemaLoader loader = new LdifSchemaLoader(schemaRepository);    SchemaManager schemaManager = new DefaultSchemaManager(loader);    directoryService.setSchemaManager(schemaManager);    schemaManager.loadAllEnabled();    schemaPartition.setSchemaManager(schemaManager);    List<Throwable> errors = schemaManager.getErrors();    if (!errors.isEmpty())      throw new Exception("Schema load failed : " + errors);    JdbmPartition systemPartition = new JdbmPartition();    systemPartition.setId("system");    systemPartition.setPartitionDir(new File(directoryService        .getWorkingDirectory(), "system"));    systemPartition.setSuffix(ServerDNConstants.SYSTEM_DN);    systemPartition.setSchemaManager(schemaManager);    directoryService.setSystemPartition(systemPartition);    directoryService.setShutdownHookEnabled(false);    directoryService.getChangeLog().setEnabled(false);    ldapServer = new LdapServer();    ldapServer.setTransports(new TcpTransport(11389));    ldapServer.setDirectoryService(directoryService);    directoryService.startup();    ldapServer.start();  }  @AfterClass  public static void stopApacheDs() throws Exception {    ldapServer.stop();    directoryService.shutdown();    directoryService.getWorkingDirectory().delete();  }  @Test  public void anonAuth() throws NamingException {    DirContextSource.Builder builder = new DirContextSource.Builder(        "ldap://localhost:11389");    DirContextSource contextSource = builder.build();    DirContext context = contextSource.getDirContext();    assertNotNull(context.getNameInNamespace());    context.close();  }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/438493.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号