Hi,

On 27/08/2019 16:19, Jeremy Sweetman wrote:
Hi,

I've successfully used the Apache Directory API to load in paged user data from 
Active Directory. It's similar to the example code by 'oers' found in this 
stackoverflow question: 
https://stackoverflow.com/questions/17963975/apache-directory-ldap-paged-searches

Some differences I have are:
*   I'm coding it with Nashorn (Javascript running in Java)
*   I'm using the PagedResultsImpl class instead of PagedResultsDecorator
*   I'm saving the cookie as a string between calls by using a Base64 encoding 
of the byte[] cookie.
*   I'm using Apache Directory API with the following maven import (The links 
to the version 2 javadoc on the website were broken so I stuck with version 1):
     <dependency>
         <groupId>org.apache.directory.api</groupId>
         <artifactId>api-all</artifactId>
         <version>1.0.3</version>
     </dependency>

Here's some of the important bits:

        var pageCursor = "";  /** or some Base64 encoded byte[] cookie if I'm 
trying to start from where i left off last time. */
        ...
        pagedSearchControl = new PagedResultsImpl();
        pagedSearchControl.setSize(pageSize);
        
pagedSearchControl.setCookie(Base64.getEncoder().encodeToString(pageCursor.getBytes()));

Any reason you encode the empty byte[] ? Just pass Strings.EMPTY_BYTES.


        ...
        var searchRequest = new SearchRequestImpl();
        ...
        searchRequest.addControl(pagedSearchControl);
        ...
        var cursor = new EntryCursorImpl(connection.search(searchRequest));
        ...
        pagingResults = 
cursor.getSearchResultDone().getControl(PagedResults.OID);
        if (pagingResults != null){
            nextPageCursor = 
Base64.getEncoder().encodeToString(pagingResults.getCookie());


Same thing. Don't encode using Base64.



---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscr...@directory.apache.org
For additional commands, e-mail: api-h...@directory.apache.org

Reply via email to