I am using the Spring LdapTemplate class to access ldap. I use the ldap connection pool (PoolingContextSource class) to avoid creating connections at runtime. However, sometimes I get this exception in my application:
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
<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 offer a solution?
I was thinking about using the testOnReturn parameter in the pool properties instead of the currently used evictor connection. When I do this, I get the following warning when I launch my web application in a browser:
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 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.
source share