7

LDAPにアクセスするためにSpring LdapTemplateクラスを使用しています。実行時に常に接続を作成しないように、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'

(...)

私の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>

誰かがこの問題を経験し、解決策を提案できますか?

現在使用されている接続 evictor の代わりに、プールのプロパティで 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: ''

そしてすぐに、次の例外が発生します。

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)

前もって感謝します。

4

1 に答える 1

2

タイムアウトの定義は低くする方法のようです。Oracleの公式サイトがあり、問題の原因を突き止めることができます。おそらく、SunLdapコネクタやLdapサーバーの「春」ではありません。多くの人がリンクの提供に反対していますが、私はこのページをコピーできません。おそらく、サイトで「生の」ステートメントを試して、それが発生するかどうかを確認してください。それはあなたにあなたの解決策に一歩近づくでしょう。(おそらくLDAPタイムアウト設定)

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();
}
于 2012-09-18T04:54:36.093 に答える