[Date Prev][Date Next] [Chronological] [Thread] [Top]

JNDI, paging of results with OpenLDAP

Hello there,
After reading the archived list messages for OpenLDAP I get the general
impression that paging of results from a query to OpenLdap is not supported.
However, on your roadmap it says this:

OpenLDAP 2.2 (released December 2003)
Functional enhancements and improved scalability:
"LDAP Sync"-based lightweight replication
Proxy Cache Support
Hierarchical Backend
NS-SLAPI Support
Backend Layering
Access Control extensions including dynamic group support
LDAPv3 extensions:
ACID extensions
Cancel Operation
Content Synchronization Operation
DIT Content Rules
Duplicate Entry Extension
***Simple Paged Results Extension***
Proxy Authorization Extension

I am using version 2.2 and I have been able to obtain the first 'page' of 5
test results from a total set of 10- but there does not appear to be any way
to retreive the next page, or any subsequent pages after the first one. This


Gives some example JNDI code that you can use to retreive subsequent pages
after the first page. My code is similar to the example above and looks like

PagedResultsControl prc = new PagedResultsControl(resultsPerPage);
//gets the first Page of 'n' results
Control[] controls = {prc};

SearchControls search = new SearchControls();

/** My own helper method*/
InitialLdapContext ctx =


/** Another helper method*/
String searchBase = LdapDAOHelper.getCoreUserBase();

/** Get the search filter from the method argument */
String filter = searchBuilder.getLdapSearchFilter();

//Run the search
names = ctx.search(searchBase, filter, search);

//get the response controls
Control[] responseControls = ctx.getResponseControls();

//examining responseControls for a PagedResultsResponseControl
//to get cookie for next page
for (int i = 0; i < responseControls.length; i++)
	if (responseControls[i] instanceof PagedResultsResponseControl)
		totalResults =
		int temp = totalResults/resultsPerPage;
		totalPages = totalResults%resultsPerPage > 0 ? ++temp : temp;

		if(pageNumber <= totalPages)
			//get the cookie
			prc = new PagedResultsControl(resultsPerPage,
//get next page of results

The problem comes with this line:

Control[] responseControls = ctx.getResponseControls();

After calling it the array responseControls is null. So there is no way to
get the cookie which is used to get the next page of results. Here is the
link to the Javadoc for the method:


What I dont understand is how paging can only "half" work? Does anyone have
any example JNDI code that has been used with OpenLDAP to successfully get
several pages of results, one after the other?

Jon Poulton