没有达到超时时,java LDAP读取超时?

时间:2014-11-20 18:04:09

标签: java sockets ldap timeout

我有一个使用LDAPContext连接到LDAP的Java应用程序。以下是我的环境属性:

    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put("com.sun.jndi.ldap.read.timeout", READ_TIMEOUT);
    env.put("com.sun.jndi.ldap.connect.timeout", CONNECTION_TIMEOUT);
    env.put(Context.PROVIDER_URL, host);
    if (principal == null || principal.isEmpty()) {
      env.put(Context.SECURITY_AUTHENTICATION, "none");
    } else {
      env.put(Context.SECURITY_AUTHENTICATION, "simple");
      env.put(Context.SECURITY_PRINCIPAL, principal + "@" + domain);
      env.put(Context.SECURITY_CREDENTIALS, password);
    }
    if (useLDAPS) {
      env.put(Context.SECURITY_PROTOCOL, "ssl");
    }

我最近遇到的问题是在尝试连接时偶尔会出现问题,在达到超时时间之前我会收到读取超时错误。超时设置为10000毫秒(10秒)。我甚至尝试删除设置超时的属性,但仍然会发生。

还有其他可能发生的原因吗?如果连接由于达到最大连接而重置,是否会引发读取超时?我看到的例外是:

javax.naming.CommunicationException: XX.XX.XX.XX:636 [Root exception is java.net.SocketTimeoutException: Read timed out]
        at com.sun.jndi.ldap.Connection.<init>(Connection.java:226)

2015年9月15日更新 还有这个问题。这是堆栈跟踪。任何帮助都是适用的。

WARNING: CommunicationException
javax.naming.CommunicationException: XX.XX.XX.XX:636 [Root exception is java.net.SocketTimeoutException: Read timed out]
       at com.sun.jndi.ldap.Connection.<init>(Connection.java:226)
       at com.sun.jndi.ldap.LdapClient.<init>(LdapClient.java:136)
       at com.sun.jndi.ldap.LdapClient.getInstance(LdapClient.java:1608)
       at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2698)
       at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:316)
       at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:193)
       at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:211)
       at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:154)
       at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:84)
       at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
       at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
       at javax.naming.InitialContext.init(InitialContext.java:242)
       at javax.naming.ldap.InitialLdapContext.<init>(InitialLdapContext.java:153)
       at my.package.name.ToolClass.getLdapConnection(ToolClass.java:302)
Caused by: java.net.SocketTimeoutException: Read timed out
       at java.net.SocketInputStream.socketRead0(Native Method)
       at java.net.SocketInputStream.read(SocketInputStream.java:152)
       at java.net.SocketInputStream.read(SocketInputStream.java:122)
       at sun.security.ssl.InputRecord.readFully(InputRecord.java:442)
       at sun.security.ssl.InputRecord.read(InputRecord.java:480)
       at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:934)
       at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
       at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359)
       at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343)
       at com.sun.jndi.ldap.Connection.createSocket(Connection.java:381)
       at com.sun.jndi.ldap.Connection.<init>(Connection.java:203)
       ... 27 more

0 个答案:

没有答案