java Spring LDAP:对等方重置连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12465138/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 08:59:27  来源:igfitidea点击:

Spring LDAP: Connection reset by peer

javaspringldap

提问by Alan Evangelista

I'm using Spring LdapTemplate class to access ldap. I'm using a pool of ldap connections (PoolingContextSource class) to avoid creating connections all the time at runtime. However, I get this exception sometimes at my application:

我正在使用 Spring LdapTemplate 类来访问 ldap。我正在使用一个 ldap 连接池(PoolingContextSource 类)来避免在运行时一直创建连接。但是,有时在我的应用程序中会遇到此异常:

javax.servlet.ServletException: org.springframework.ldap.CommunicationException: Connection reset; 
nested exception is javax.naming.CommunicationException: Connection reset [Root exception is java.net.SocketException: Connection reset]; 
Remaining name: 'ou=memberlist,ou=mygroups,o=mycompany.com'

(...)

(...)

My ldap classes are defined in the following xml

我的 ldap 类在以下 xml 中定义

<bean id="contextSource" class="com.ibm.tp4.spring.ldap.CustomPoolingContextSource">
  <property name="contextSource" ref="contextSourceTarget" />
  <property name="testWhileIdle" value="true" />
  <property name="minEvictableIdleTimeMillis" value="300000" />
  <property name="timeBetweenEvictionRunsMillis" value="10000"/>
  <property name="dirContextValidator">
    <bean class="org.springframework.ldap.pool.validation.DefaultDirContextValidator" />
  </property>
</bean>

<bean id="contextSourceTarget" class="org.springframework.ldap.core.support.LdapContextSource">
  <property name="url" value="${ldap.url}" />
  <property name="pooled" value="false" />
  <property name="anonymousReadOnly" value="true" />
</bean>

<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
  <constructor-arg ref="contextSource" />
</bean>

<bean id="myLdapResolver" class="com.ibm.tp4.model.service.user.MyLdapResolver">
  <constructor-arg ref="ldapTemplate" />
  <property name="ldapUserSearchBase" value="${ldap.user.search_base}" />
  <property name="ldapUserEmailAddressField" value="${ldap.user.email_address}" />
  <property name="ldapAttributes" value="${ldap.user.attributes}" />
</bean>

Has anyone experienced this problem and can suggest a solution?

有没有人遇到过这个问题并且可以提出解决方案?

I thought about using testOnReturn parameter in the pool properties instead of connection evictor used right now. When I do, I get the following warning when I run my web application in the browser:

我想过在池属性中使用 testOnReturn 参数而不是现在使用的连接驱逐器。当我这样做时,当我在浏览器中运行我的 Web 应用程序时,我收到以下警告:

WARN [org.springframework.ldap.pool.validation.DefaultDirContextValidator] - 
DirContext 'javax.naming.ldap.InitialLdapContext@d150d15' failed validation with an 
exception.javax.naming.OperationNotSupportedException: [LDAP: error code 53 - Unwilling To Perform]; 
Remaining name: ''

and soon after, I get this exception:

不久之后,我得到了这个例外:

org.springframework.dao.DataAccessResourceFailureException: Failed to borrow DirContext from pool.; nested exception is java.util.NoSuchElementException: Could not create a validated object, cause: ValidateObject failed  
org.springframework.ldap.pool.factory.PoolingContextSource.getContext(PoolingContextSource.java:425)

Thanks in advance.

提前致谢。

回答by Oliver

It looks like the time out definition is way to low. There is a official Site from Oracle that will give you the possibility to figure out the source of the problem, very likely its not "Spring" its the Sun Ldap connector or your Ldap Server. Lots of people are against providing Links but i simply can't copy this page, maybe you try the "raw" statement on their site to see if it occurs too. It will bring you a step closer to your solution. (probably the ldap timeout config)

看起来超时定义太低了。Oracle 有一个官方站点,可以让您找出问题的根源,很可能不是“Spring”,而是 Sun Ldap 连接器或您的 Ldap 服务器。很多人反对提供链接,但我根本无法复制此页面,也许您可​​以尝试在他们的网站上使用“原始”声明,看看它是否也会发生。它将使您更接近您的解决方案。(可能是 ldap 超时配置)

http://docs.oracle.com/javase/tutorial/jndi/newstuff/readtimeout.html

http://docs.oracle.com/javase/tutorial/jndi/newstuff/readtimeout.html

env.put(Context.INITIAL_CONTEXT_FACTORY,
    "com.sun.jndi.ldap.LdapCtxFactory");
env.put("com.sun.jndi.ldap.read.timeout", "1000");
env.put(Context.PROVIDER_URL, "ldap://localhost:2001");

Server s = new Server();

try {

    // start the server
    s.start();

   // Create initial context
   DirContext ctx = new InitialDirContext(env);
   System.out.println("LDAP Client: Connected to the Server");
        :
        :
} catch (NamingException e) {
   e.printStackTrace();
}