Search code examples
javasizelimitunboundid-ldap-sdk

java ldapsearchexception size limit exceeded setMaxResults


I get this error: "LDAPSearchException: size limit exceeded" error and the server is only returning 500 results. I am assured by our highly experienced LDAP administrator that this limit is not set on the server. Indeed I can get much more than 500 results by using 'ldapsearch' on the CLI.

The suggestion in this article LDAPException Size Limit exceeded is exactly what I need. However when I try to set the LDAPSearchConstraints object on my LDAPConnection object (ld.setSearchConstraints(ldsc);) I get a compile error saying the method doesn't exist:

cannot find symbol
symbol  : method setSearchConstraints(com.unboundid.ldap.sdk.migrate.ldapjdk.LDAPSearchConstraints)
location: class com.unboundid.ldap.sdk.LDAPConnection. 

Does someone know why this method is not available? I have tried different versions of unboundid-ldapsdk and even tried different repositories in my pom file. Alternatively, if someone knows how to retrieve more than the default search results using a different approach please let me know.

I am using 64 bit linux (version: "3.2.0-4-amd64") and Apache Maven 2.2.1 (rdebian-8) Java version: 1.6.0_31


Solution

  • After taking a look at the API, the correct way to limit the search results is

    com.unboundid.ldap.sdk.LDAPConnection connection = <some connection>
    
    com.unboundid.ldap.sdk.SearchRequest request = new SearchRequest(<your parameters>);
    request.setSizeLimit(<your limit>);
    
    SearchResult result = connection.search(request);
    

    The compilation error occurs because you are importing the wrong LDAPConnection.

    com.unboundid.ldap.sdk.migrate.ldapjdk.LDAPConnection <-- supports setSearchConstraints

    com.unboundid.ldap.sdk.LDAPConnection <-- you are using this class, which doesn't support setSearchConstraints