1

我正在使用 UnboundId SDK 搜索 LDAP 并使用 SimplePagedResultsControl 对我的结果进行分页。我能够正确搜索并根据页面大小获得第一组所需的结果,但我无法检索后续结果集,因为来自 SearchResult 的响应控制对象为 NULL。我需要检索 cookie 值并将其设置在下一个搜索请求中,以便搜索请求继续检索剩余的结果。

我正在使用 UnboundId SDK 网站和其他网站中给出的类似代码。任何解决此问题的帮助将不胜感激。

// 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;
 }
}
4

1 回答 1

1

我看不出代码有任何明显错误,所以我的第一个猜测是您使用的服务器不支持控件(如果支持,则“1.2.840.113556.1.4.319”应该出现在根目录中DSE 的 supportedControl 属性),或者连接被验证为无权使用它的用户(在这种情况下,作为更强大的用户进行验证应该允许按预期处理控件)。由于控件未标记为关键,因此如果它不支持该控件,则服务器应忽略该控件,并且如果请求者无权使用该控件,则某些服务器可能会选择忽略该控件而不是拒绝该请求。

确定是否正在处理控件的最佳方法可能是检查搜索是否仅返回页面大小中指定的条目数或与搜索匹配的整个结果集。如果搜索只返回一页结果,那么服务器肯定应该返回一个响应控件。如果服务器忽略控件并处理请求,就好像没有提供控件一样,那么结果集应该包括服务器中与搜索条件匹配的所有条目。

于 2014-06-20T05:32:08.560 回答