Ash*_*ery 1 ldap ldapconnection ldap-query 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)
Run Code Online (Sandbox Code Playgroud)
现在奇怪的是我已经在搜索约束中将maxResultSize设置为100k,而不是我收到此错误的原因?我的代码是
ld = new LDAPConnection();
ld.connect(ldapServer, 389);
LDAPSearchConstraints ldsc = new LDAPSearchConstraints();
ldsc.setMaxResults(100000);
ld.setSearchConstraints(ldsc);
Run Code Online (Sandbox Code Playgroud)
有人有什么想法吗?
抱歉,对于necroposting,但你的主题没有答案仍然是谷歌的第一个.
使用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());
}
Run Code Online (Sandbox Code Playgroud)
}
| 归档时间: |
|
| 查看次数: |
5621 次 |
| 最近记录: |