Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LDAP-316: support for apache commons-pool2 #351

Closed
spring-projects-issues opened this issue Sep 29, 2014 · 9 comments
Closed

LDAP-316: support for apache commons-pool2 #351

spring-projects-issues opened this issue Sep 29, 2014 · 9 comments
Assignees
Milestone

Comments

@spring-projects-issues
Copy link

Cristi Vulpe (Migrated from LDAP-316) said:

I have tried to upgrade from commons-pool version 1.6 to commons-pool2 version 2.2 and I get this exception:

java.lang.NoClassDefFoundError: org/apache/commons/pool/KeyedPoolableObjectFactory
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2688)
    at java.lang.Class.getDeclaredMethods(Class.java:1962)
    at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:570)
    at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:489)
    at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:473)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:241)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1059)
    at 
....

I have a bean that looks like this:

  <bean id="ldapContextSource"
    class="org.springframework.ldap.pool.factory.PoolingContextSource">
    ...
  </bean>

When I looked at the source code for PoolingContextSource.java I found that it is using the naming convention from commons-pool 1.x:

import org.apache.commons.pool.impl.GenericKeyedObjectPool;

.
Is it possible to:

  1. Upgrade to the latest version (will very likely break backwards compatibility)?
  2. Provide an implementation that is sensitive to the classpath entries (i.e. detect which implementation to use)?
@spring-projects-issues
Copy link
Author

Michael Osipov said:

I am highly interested in this. Pool 1.x and 2.x are not compatible and different package names.

@spring-projects-issues
Copy link
Author

Anindya Chatterjee said:

Any update on this issue? Any road map for the implementation?

If not yet, I'll work on it and create PR.

@spring-projects-issues
Copy link
Author

Rob Winch said:

anidotnet Thanks for the offer for making a PR! We would greatly appreciate it. Please ensure any PR that is submitted is passive so as not to break existing users.

@spring-projects-issues
Copy link
Author

Anindya Chatterjee said:

I have submitted the PR as promised.

[https://github.com//pull/33]

@spring-projects-issues
Copy link
Author

Anindya Chatterjee said:

Any update please about merging the PR?

@spring-projects-issues
Copy link
Author

Rob Winch said:

This is resolved in master

@salmanVD
Copy link

salmanVD commented Aug 4, 2019

@spring-issuemaster This issue still exists with latest Ldap core 2.3.2 release. When this will be fixed?

@snytkine
Copy link

I too have this issue right now with spring boot 2.2.3
The whole reason for using spring-ldap was the idea of support for ldap pool, but unfortunately there is this bug.
Is anyone working on fixing this issue?

@nulliver
Copy link

nulliver commented Feb 15, 2020

I too have this issue right now with spring boot 2.2.3
The whole reason for using spring-ldap was the idea of support for ldap pool, but unfortunately there is this bug.
Is anyone working on fixing this issue?

@snytkine @salmanVD commons-pool2 is working fine for me with Spring LDAP Core version 2.3.2. One thing you have to consider is that there are two classes, one is for commons-pool and the other is for commons-pool2.

For commons-pool 1.x use the class:
org.springframework.ldap.pool.factory.PoolingContextSource

For commons-pool 2.x use class:
org.springframework.ldap.pool2.factory.PooledContextSource

Note that the first one is in the pool subpackage while the second one on the pool2 subpackage. Also, the name of the commons-pool2 class starts with Pooled while the commons-pool 1 starts with Pooling

The Spring LDAP documentation does not mention this difference in the Pooling Support section, I found out about this by looking at the code of spring-ldap-core.

Sample code:

...
import org.springframework.ldap.pool2.factory.PoolConfig;
import org.springframework.ldap.pool2.factory.PooledContextSource;
import org.springframework.ldap.pool2.validation.DefaultDirContextValidator;
...
@Bean
public ContextSource contextSource() {
    
    LdapContextSource contextSource = new LdapContextSource();
    contextSource.setUrl("ldap://my.ldap.server.com:389");
    contextSource.setBase("o=myorg.com");
    contextSource.setUserDn("uid=someUserId,cn=mycn,o=myorg.com");
    contextSource.setPassword("super-secret-password");
    contextSource.afterPropertiesSet();

    // Configures Spring LDAP pooling for LDAP connections
    PoolConfig poolConfig = new PoolConfig();
    
    /* Objects will be validated before being borrowed from the pool. If the object fails to validate,
    it will be dropped from the pool, and an attempt to borrow another will be made. */
    poolConfig.setTestOnBorrow(true);

    /*The limit on the number of object instances allocated by the pool (checked out or idle), per key.
    When the limit is reached, the sub-pool is said to be exhausted. A negative value indicates no limit.*/
    poolConfig.setMaxTotalPerKey(-1);

    /*The maximum number of active connections of each type (read-only|read-write) that can remain idle
    in the pool, without extra ones being released, or non-positive for no limit.*/
    poolConfig.setMaxIdlePerKey(-1);

    PooledContextSource pcs = new PooledContextSource(poolConfig);
    pcs.setContextSource(contextSource);
    pcs.setDirContextValidator(new DefaultDirContextValidator());

    TransactionAwareContextSourceProxy contextSourceProxy = new TransactionAwareContextSourceProxy(pcs);

    return contextSourceProxy;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants