[
https://issues.apache.org/jira/browse/DIRAPI-399?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17823128#comment-17823128
]
Thomas Jodes commented on DIRAPI-399:
-------------------------------------
Edit: I switched paged search as seen above not to use the EntryCursorImpl, but
to use [SearchCursor like
here|[http://example.com|https://directory.apache.org/api/user-guide/2.3-searching.html]].
Just to work with the SearchCursor and to use the cast to SearchResultEntry.
Interestingly, not a single SearchResultReference comes up, so referals absent
here. When wrapping the searchResult in the EntryCursorImpl (EntryCursor cursor
= new EntryCursorImpl(searchCursor)), the references are in the first page
results.
> Cannot paginate SearchCursor via SearchRequest when SearchResultReference(s)
> picked up
> --------------------------------------------------------------------------------------
>
> Key: DIRAPI-399
> URL: https://issues.apache.org/jira/browse/DIRAPI-399
> Project: Directory Client API
> Issue Type: Bug
> Affects Versions: 2.1.6
> Reporter: Thomas Jodes
> Priority: Major
> Attachments: Screenshot from 2024-03-01 15-47-26.png, Screenshot from
> 2024-03-01 15-48-52.png
>
>
> As a ldap-api user, I want to search my DIT paginated from a base where also
> referrals /
> [SearchResultReference|https://github.com/apache/directory-ldap-api/blob/c4fcf46f72601c1729d6d5321e2cdc7126f94b14/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/SearchResultReferenceImpl.java#L28]s
> are.
> Following paged search code:
>
> {code:java}
> int pageSize = 100;
> LdapConnection connection = null;
> try {
> connection = ldapConnectionPool.getConnection();
> int page = 0; // the current page
> PagedResults pagedSearchControl = new PagedResultsImpl();
> pagedSearchControl.setSize(pageSize);
> // Loop using the paged search control extension
> while(true) {
> SearchRequest searchRequest = new SearchRequestImpl()
> .ignoreReferrals()
> .setDerefAliases(AliasDerefMode.NEVER_DEREF_ALIASES)
> .setBase(new Dn(searchBase))
> .setFilter(filter)
> .setScope(SearchScope.SUBTREE)
> .addAttributes(attributes)
> .setTimeLimit(120)
> .addControl(pagedSearchControl);
> SearchCursorImpl searchCursor = (SearchCursorImpl)
> connection.search(searchRequest);
> try (EntryCursor cursor = new EntryCursorImpl(searchCursor)) {
> while (cursor.next()) {
> Entry e = cursor.get();
> log.info("element: {}", e.get("sAMAccountName"));
> results.add(e);
> }
> SearchResultDone searchResult = cursor.getSearchResultDone();
> pagedSearchControl =
> (PagedResults)searchResult.getControl(PagedResults.OID);
> if (searchResult.getLdapResult().getResultCode() ==
> ResultCodeEnum.UNWILLING_TO_PERFORM) {
> throw new LdapException("Directory cannot handle
> pagination!");
> }
> } catch (CursorException e) {
> log.error("Unexpected cursor exception occurred!", e);
> }
> // Check if pagination is exhausted (all eligible entries have been
> read)
> if (Strings.isEmpty(pagedSearchControl.getCookie())) {
> log.info("Exiting paged search at page: " + ++page);
> break;
> }
> // Prepare the next iteration
> pagedSearchControl.setSize(pageSize);
> }
> // here we want to do s.th. with our 'results' reference;
> } catch (LdapException e) {
> log.error("Unexpected ldap exception occurred!", e);
> } catch (IOException e) {
> log.error("Unexpected I/O exception occurred!", e);
> } finally {
> if (connection != null) {
> ldapConnectionPool.releaseConnection(connection); // put the
> session/connection back to its pool
> }
> } {code}
>
> *Expected behaviour:*
> all elements in the base are picked up in the 'results' list, all paginated
> and added up by x times a bunch of 100 until everything has been read in the
> directory. In the searchFuture at LdapNetworkConnection.searchAsync should be
> 101 elements: 100 SearchResultEntryImpl's and one SearchResultDoneImpl.
>
> *Actual behaviour:*
> in the first page there are 100 entries, i.e. 100x SearchResultEntryImpl
> elements PLUS (in my case/active directory) 3x SearchResultReferenceImpl
> elements plus 1x SerachResultDoneImpl element as the last one in the array of
> the searchFuture here:[
> LdapNetworkConnection#searchAsync()|https://github.com/apache/directory-ldap-api/blob/c4fcf46f72601c1729d6d5321e2cdc7126f94b14/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java#L2391]
> .
> ldap-api code runs into exception at EntryCursorImpl.get() when the response
> instanceof [SearchResultReference is
> hit|https://github.com/apache/directory-ldap-api/blob/c4fcf46f72601c1729d6d5321e2cdc7126f94b14/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/EntryCursorImpl.java#L164]
> -> LdapReferralException.
> "ignoreReferrals()" has been set building the SearchRequestImpl
>
> The three additional SearchResultReferenceImpl elements in the entries read
> shouldn't be picked up.
>
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]