1

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;
 }
}
Muthu
  • 211
  • 1
  • 6

1 Answers1

1

I don't see anything obviously wrong with the code, so my first guess is that either the server you're using doesn't support the control (if it does then "1.2.840.113556.1.4.319" should appear in the root DSE's supportedControl attribute), or that the connection is authenticated as a user that doesn't have permission to use it (in which case authenticating as a more powerful user should allow the control to be processed as expected). Since the control isn't marked critical, then the server should ignore the control if it doesn't support it, and some servers may choose to ignore the control instead of rejecting the request if the requester doesn't have permission to use it.

The best way to determine if the control is being processed is probably to check to see if the search returned only the number of entries specified in the page size or the entire set of results that match the search. If the search returned only a single page of results, then the server should have definitely returned a response control. If the server ignored the control and processed the request as if the control hadn't been provided, then the result set should include all entries in the server that match the search criteria.

Neil Wilson
  • 1,706
  • 8
  • 4
  • Thanks. The server does support the control. The search returns only single page results and when i get the ReferralURL value from SearchResult, I am able to see that control and the remaining number of search result entries. From exception:SearchResult(resultCode=0 (success), messageID=2, referralURLs={'1.2.840.113556.1.4.319?9450'} – Muthu Jun 20 '14 at 17:26