I am using UnboundId SDK for searching LDAP and using SimplePagedResultsControl for paging my results. I am able to search properly and get the first set of desired results based on the page size, but I am not able to retrieve the subsequent set of results because the response control object coming from the SearchResult is NULL. I need to retrieve the cookie value and set it in the next search request for the search request to continue retrieving the remaining results.
I am using a similar code given in UnboundId SDK website and other sites. Any help to resolve this would be appreciated.
// Perform a search to retrieve all users in the server, but only retrieving
// ten at a time.
int numSearches = 0;
int totalEntriesReturned = 0;
SearchRequest searchRequest = new SearchRequest("dc=example,dc=com",
SearchScope.SUB, Filter.createEqualityFilter("objectClass", "person"));
ASN1OctetString resumeCookie = null;
while (true)
{
searchRequest.setControls(
new SimplePagedResultsControl(10, resumeCookie));
SearchResult searchResult = connection.search(searchRequest);
numSearches++;
totalEntriesReturned += searchResult.getEntryCount();
for (SearchResultEntry e : searchResult.getSearchEntries())
{
// Do something with each entry...
}
LDAPTestUtils.assertHasControl(searchResult,
SimplePagedResultsControl.PAGED_RESULTS_OID); -*Failing here as the SearchResult obj
is not having any Response Control*
SimplePagedResultsControl responseControl =
SimplePagedResultsControl.get(searchResult);
if (responseControl.moreResultsToReturn())
{
// The resume cookie can be included in the simple paged results
// control included in the next search to get the next page of results.
resumeCookie = responseControl.getCookie();
}
else
{
break;
}
}