コード例 #1
0
  public void start() {
    if (isRunning()) {
      return;
    }

    if (service.isStarted()) {
      throw new IllegalStateException("DirectoryService is already running.");
    }

    logger.info("Starting directory server...");
    try {
      service.startup();
      server.start();
    } catch (Exception e) {
      logger.error("Server startup failed ", e);
      return;
    }

    try {
      service.getAdminSession().lookup(partition.getSuffixDn());
    } catch (LdapNameNotFoundException e) {
      try {
        LdapDN dn = new LdapDN(root);
        Assert.isTrue(root.startsWith("dc="));
        String dc = root.substring(3, root.indexOf(','));
        ServerEntry entry = service.newEntry(dn);
        entry.add("objectClass", "top", "domain", "extensibleObject");
        entry.add("dc", dc);
        service.getAdminSession().add(entry);
      } catch (Exception e1) {
        logger.error("Failed to create dc entry", e1);
      }
    } catch (Exception e) {
      logger.error("Lookup failed", e);
    }

    running = true;

    try {
      importLdifs();
    } catch (Exception e) {
      logger.error("Failed to import LDIF file(s)", e);
    }
  }
コード例 #2
0
 private void startServer() throws Exception {
   service.startup();
   server = new LdapServer();
   server.setTransports(new TcpTransport(10389));
   server.setDirectoryService(service);
 }