• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java StartupException类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中com.google.enterprise.adaptor.StartupException的典型用法代码示例。如果您正苦于以下问题:Java StartupException类的具体用法?Java StartupException怎么用?Java StartupException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

StartupException类属于com.google.enterprise.adaptor包,在下文中一共展示了StartupException类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testEnsureConnectionWrapsStartupException

点赞 3

import com.google.enterprise.adaptor.StartupException; //导入依赖的package包/类
@Test
public void testEnsureConnectionWrapsStartupException() throws Exception {
  MockLdapContext ldapContext = new MockLdapContext() {
    @Override
    public Attributes getAttributes(String name) throws NamingException {
      throw new CommunicationException("testing");
    }
  };
  LdapServer ldapServer = new LdapServer("localhost", "nickname",
      "ou=basedn", "userFilter", "cn,dn" /* attributes */,
      1000 /* traversalRate */, "dn={dn}, cn={cn}", ldapContext) {
    @Override
    void recreateLdapContext() {
      throw new StartupException("persistent problem");
    }
  };
  try {
    ldapServer.initialize();
  } catch (RuntimeException re) {
    assertTrue(re.getCause() instanceof NamingException);
    NamingException ne = (NamingException) re.getCause();
    assertTrue(ne.getMessage().contains("recreateLdapContext"));
    assertTrue(ne.getRootCause() instanceof StartupException);
  }
}
 

开发者ID:googlegsa,
项目名称:ldap,
代码行数:26,
代码来源:LdapServerTest.java

示例2: newAdServer

点赞 2

import com.google.enterprise.adaptor.StartupException; //导入依赖的package包/类
/**
 * This method exists specifically to be overwritten in the test class, in
 * order to inject a version of AdServer that uses mocks.
 */
@VisibleForTesting
AdServer newAdServer(Method method, String host, int port,
    String principal, String passwd, String userSearchBaseDN,
    String groupSearchBaseDN, String userSearchFilter,
    String groupSearchFilter, String ldapTimeoutInMillis)
    throws StartupException {
  return new AdServer(method, host, port, principal, passwd, userSearchBaseDN,
      groupSearchBaseDN, userSearchFilter, groupSearchFilter,
      ldapTimeoutInMillis);
}
 

开发者ID:googlegsa,
项目名称:activedirectory,
代码行数:15,
代码来源:AdAdaptor.java

示例3: AdServer

点赞 2

import com.google.enterprise.adaptor.StartupException; //导入依赖的package包/类
public AdServer(Method connectMethod, String hostName,
    int port, String principal, String password,
    String userSearchBaseDN, String groupSearchBaseDN,
    String userSearchFilter, String groupSearchFilter,
    String ldapTimeoutInMillis)
    throws StartupException {
  this(hostName, userSearchBaseDN, groupSearchBaseDN, userSearchFilter,
      groupSearchFilter, createLdapContext(connectMethod, hostName, port,
          principal, password, ldapTimeoutInMillis));
  this.connectMethod = connectMethod;
  this.port = port;
  this.principal = principal;
  this.password = password;
  this.ldapTimeoutInMillis = ldapTimeoutInMillis;
}
 

开发者ID:googlegsa,
项目名称:activedirectory,
代码行数:16,
代码来源:AdServer.java

示例4: testInitFailedForMissingRootCollection

点赞 2

import com.google.enterprise.adaptor.StartupException; //导入依赖的package包/类
@Test
public void testInitFailedForMissingRootCollection() throws Exception {
  MockSoapFactory rootMissingSoapFactory = MockSoapFactory.blank()
      .endpoint(VS_ENDPOINT, MockSiteData.blank()
          .register(VS_CONTENT_EXCHANGE)
          .register(CD_CONTENT_EXCHANGE)
          .register(new SiteAndWebExchange(
              "http://localhost:1", 10L, null, null)));
  adaptor = new SharePointAdaptor(rootMissingSoapFactory,
      new UnsupportedHttpClient(), executorFactory,
      new MockAuthenticationClientFactoryForms(),
      new UnsupportedActiveDirectoryClientFactory());
  thrown.expect(StartupException.class);
  adaptor.init(new MockAdaptorContext(config, pusher));
}
 

开发者ID:googlegsa,
项目名称:sharepoint,
代码行数:16,
代码来源:SharePointAdaptorTest.java

示例5: recreateLdapContext

点赞 2

import com.google.enterprise.adaptor.StartupException; //导入依赖的package包/类
@VisibleForTesting
void recreateLdapContext() throws StartupException {
  ldapContext = createLdapContext(connectMethod, hostName, port, principal,
      password, ldapTimeoutInMillis);
}
 

开发者ID:googlegsa,
项目名称:activedirectory,
代码行数:6,
代码来源:AdServer.java

示例6: createLdapContext

点赞 2

import com.google.enterprise.adaptor.StartupException; //导入依赖的package包/类
/**
 * Normally called (only) by public constructor and recreateLdapContext().
 */
private static LdapContext createLdapContext(String hostName,
    Method connectMethod, int port, String principal, String password,
    long ldapTimeoutInMillis) {
  Hashtable<String, String> env = new Hashtable<String, String>();
  if (null == connectMethod || null == hostName
      || null == principal || null == password) {
    throw new NullPointerException();
  }
  if ("".equals(hostName)) {
    throw new IllegalArgumentException("host needs to be non-empty");
  }
  if ("".equals(principal)) {
    throw new IllegalArgumentException("principal needs to be non-empty");
  }
  if ("".equals(password)) {
    throw new IllegalArgumentException("password needs to be non-empty");
  }

  // Use the built-in LDAP support.
  // TODO(myk): See if we can specify a value in the configuration file to
  // allow us to override this, for unit tests.
  env.put(Context.INITIAL_CONTEXT_FACTORY,
      "com.sun.jndi.ldap.LdapCtxFactory");
  // Connecting to configuration naming context is very slow for crawl users
  // in large multidomain environment, which belong to thousands of groups
  env.put("com.sun.jndi.ldap.read.timeout", "" + ldapTimeoutInMillis);
  env.put(Context.SECURITY_AUTHENTICATION, "simple");
  // TODO(myk): allow anonymous authentication
  env.put(Context.SECURITY_PRINCIPAL, principal);
  env.put(Context.SECURITY_CREDENTIALS, password);

  String ldapUrl = connectMethod.protocol() + hostName + ":" + port;
  log.config("LDAP provider url: " + ldapUrl);
  env.put(Context.PROVIDER_URL, ldapUrl);
  try {
    return new InitialLdapContext(env, null);
  } catch (NamingException ne) {
    // display (throw) a "nicer" exception message when we cannot connect.
    // This can be an AuthenticationException (wrong user name or password) or
    // a ConnectException (wrong hostname).
    Throwable cause = ne.getCause();
    boolean replaceException = false;
    boolean abortStartup = false;
    if (cause instanceof ConnectException) {
      ConnectException ce = (ConnectException) cause;
      if (ce.getMessage() != null
          && (ce.getMessage().contains("Connection timed out")
              || ce.getMessage().contains("Connection refused"))) {
        replaceException = true;
      }
    } else if (ne instanceof AuthenticationException) {
      // this is the only exception we flag as a StartupException.
      replaceException = true;
      abortStartup = true;
    } else if (ne instanceof CommunicationException) {
      replaceException = true;
    }
    if (replaceException) {
      String warning = String.format("Cannot connect to server \"%s\" as "
          + "user \"%s\" with the specified password.  Please make sure "
          + "they are specified correctly.  If the LDAP server is currently "
          + "down, please try again later.", hostName, principal);
      if (abortStartup) {
        throw new StartupException(warning, ne);
      } else {
        throw new RuntimeException(warning, ne);
      }
    }
    // wasn't the specific error we're looking for -- rethrow it.
    // <code>RuntimeException</code> is caught by the library, and retried.
    throw new RuntimeException(ne);
  }
}
 

开发者ID:googlegsa,
项目名称:ldap,
代码行数:77,
代码来源:LdapServer.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)