Re: Can't paginate with OpenLDAP

2019-08-27 Thread Emmanuel Lécharny

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):
 
 org.apache.directory.api
 api-all
 1.0.3
 

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



Can't paginate with OpenLDAP

2019-08-27 Thread Jeremy Sweetman
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):

org.apache.directory.api
api-all
1.0.3


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()));
...
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());
}

When run against Active Directory I can page all the users just fine. When I 
change my connection to point to an OpenLDAP directory I am able to search for 
users just fine, EXCEPT for when I set the page control cookie using a non-null 
value for pageCursor (one I got from base 64 encoding a previous call's 
cookie). Basically, I can't get the paged results from OpenLDAP. I get no 
results and there are no exceptions.

*   What is needed in order to get OpenLDAP to page properly?
*   Am I missing something with setting up page control in Apache Directory?
*   Is paging a setting in OpenLDAP I need to turn on?

This question has also been posted on stackoverflow: 
https://stackoverflow.com/questions/57632585/paginating-openldap-with-apache-directory-ldap-api

Thank you,
Jeremy

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