超出LDAPException大小限制

时间:2013-06-18 12:54:28

标签: ldap ldap-query ldapconnection unboundid-ldap-sdk

我正在使用unboundid ldap sdk来执行ldap查询。我在运行ldap搜索查询时遇到了一个奇怪的问题。当我对包含50k条目的组运行查询时,我收到异常。我的例外:

LDAPException(resultCode=4 (size limit exceeded), errorMessage='size limit exceeded')
at com.unboundid.ldap.sdk.migrate.ldapjdk.LDAPSearchResults.nextElement(LDAPSearchResults.java:254)
at com.unboundid.ldap.sdk.migrate.ldapjdk.LDAPSearchResults.next(LDAPSearchResults.java:279)

现在奇怪的是我已经在搜索约束中将maxResultSize设置为100k而不是我收到此错误的原因? 我的代码是

     ld = new LDAPConnection();
    ld.connect(ldapServer, 389);

    LDAPSearchConstraints ldsc = new LDAPSearchConstraints();
    ldsc.setMaxResults(100000);
    ld.setSearchConstraints(ldsc);

有人有任何想法吗?

2 个答案:

答案 0 :(得分:5)

对于necroposting很抱歉,但是没有回答的主题仍然是google中的第一个。

使用 unboundid ,您实际上可以在分页模式下获得无限数量的记录。

public static void main(String[] args) {

try {
    int count = 0;
    LDAPConnection connection = new LDAPConnection("hostname", 389, "user@domain", "password");

    final String path = "OU=Users,DC=org,DC=com";
    String[] attributes = {"SamAccountName","name"};

    SearchRequest searchRequest = new SearchRequest(path, SearchScope.SUB, Filter.createEqualityFilter("objectClass", "person"), attributes);

    ASN1OctetString resumeCookie = null;
    while (true)
    {
        searchRequest.setControls(
                new SimplePagedResultsControl(100, resumeCookie));
        SearchResult searchResult = connection.search(searchRequest);
        for (SearchResultEntry e : searchResult.getSearchEntries())
        {
            if (e.hasAttribute("SamAccountName"))
                System.out.print(count++ + ": " + e.getAttributeValue("SamAccountName"));

            if (e.hasAttribute("name"))
                System.out.println("->" + e.getAttributeValue("name"));
        }

        LDAPTestUtils.assertHasControl(searchResult,
                SimplePagedResultsControl.PAGED_RESULTS_OID);
        SimplePagedResultsControl responseControl =
                SimplePagedResultsControl.get(searchResult);
        if (responseControl.moreResultsToReturn())
        {
            resumeCookie = responseControl.getCookie();
        }
        else
        {
            break;
        }
    }


}
catch (Exception e)
{
    System.out.println(e.toString());
}

}

答案 1 :(得分:2)

检查服务器端大小限制设置。它优先于客户端设置,这是您在代码中所做的事情。