我正在使用unboundid-ldapsdk-3.1.1并尝试使用SimplePagedResultsControl
迭代条目。
以下是我正在使用的代码段:
...
searchRequest = new SearchRequest(dn, scope.getLdapSearchScope(), filter);
ASN1OctetString resumeCookie = null;
while (true)
{
searchRequest.setControls(new Control[] { new SimplePagedResultsControl(searchLimit, resumeCookie) });
setControls(searchRequest, controls);
searchResult = getConnectionPool().search(searchRequest);
numSearches++;
totalEntriesReturned += searchResult.getEntryCount();
for (SearchResultEntry e : searchResult.getSearchEntries()) {
// Do something with each entry...
}
LDAPTestUtils.assertHasControl(searchResult, SimplePagedResultsControl.PAGED_RESULTS_OID);
try {
SimplePagedResultsControl responseControl = SimplePagedResultsControl.get(searchResult);
if (responseControl.moreResultsToReturn())
resumeCookie = responseControl.getCookie();
else
break;
} catch (LDAPException ex) {
log.error("Error while accessing cookies" + ex.getMessage());
}
}
当总条目数为100且searchLimit为100时,我一直收到错误:
首次迭代responseControl.moreResultsToReturn()
返回true
,第二次迭代getConnectionPool().search(searchRequest);
抛出LDAPSearchException(resultCode=2 (protocol error), numEntries=0, numReferences=0, errorMessage='paged results cookie is invalid')
我的代码有什么问题?
答案 0 :(得分:1)
连接池通常具有多个连接,并且可能不会返回发出初始分页搜索结果请求的同一连接。解决方案是