Announcement Announcement Module
No announcement yet.
Error while doing paged query on LDAP Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error while doing paged query on LDAP

    I tried to retrieve the result from LDAP using paged query. It returns 2-3 pages successfully, but then some times failes on any page with the following exception.

    Caused by: javax.naming.OperationNotSupportedException: [LDAP: error code 12 - 00000057: LdapErr: DSID-0C09068F, comment: Error processing control, data 0, vece

    Sometimes it returns all the pages successfully. I am not sure what causing this. Can anybody help me with this.

    The following is the code snippet I am using for paged search

    SearchControls searchControls = new SearchControls();

    List<LdapEntry> entries =, _filter,
    searchControls, _attributeMapper, _processor);

    for (LdapEntry entry : entries) {


    PagedResultsCookie cookie = _processor.getCookie();
    _processor = new PagedResultsDirContextProcessor(_pageSize, cookie);

  • #2
    Never really seen this error.
    I can share my code. Try comparing to yours, and see if it helps you solve the problem.

    protected NameClassPairCallbackHandler pagedSearch(String baseDN,
    String filter,
    String displayFilter,
    SearchControls searchControls,
    NameClassPairCallbackHandler handler) {

    * once a SingleContextSource is constructed, it must be destroyed (see below), otherwise only the garbage
    * collector will close its connection.
    final SingleContextSource singleContextSource =
    new SingleContextSource(contextSource.getContext(userN ame, password));
    try {
    ldapTemplate.setContextSource(singleContextSource) ;

    if (log.isDebugEnabled()) {
    log.debugFormat("LDAP query is {0}", displayFilter);
    int ldapPageSize = Config.<Integer> GetValue(ConfigValues.LdapQueryPageSize);
    PagedResultsDirContextProcessor requestControl = new PagedResultsDirContextProcessor(ldapPageSize);, filter, searchControls, handler, requestControl);
    PagedResultsCookie cookie = requestControl.getCookie();
    while (cookie != null) {
    byte[] cookieBytes = cookie.getCookie();
    if (cookieBytes == null) {
    requestControl = new PagedResultsDirContextProcessor(ldapPageSize, cookie);, filter, searchControls, handler, requestControl);
    cookie = requestControl.getCookie();

    } catch (Exception ex) {
    log.errorFormat("Error in running LDAP query. BaseDN is {0}, filter is {1}. Exception message is: {2}",
    } finally {
    return handler;

    It is part of the oVirt project , an open source project for enterprise virtualization management. see for more details

    Hope it will help you,


    • #3
      Thanks Oved. I have partially solved the problem using SingleContextSource around LdapContextSource. Now, I am running into another issue. If I use same template which has SingelContextSource for paged search, it works but then if I use the same template for "lookup" rather than search, the ldap throws an error :

      [LDAP: error code 12 - 00002040: SvcErr: DSID-03140290, problem 5010 (UNAVAIL_EXTENSION), data 0

      So, sharing a template with SingleLdapSource between search and lookup queries does not work. Do you have any idea why this may be happening.



      • #4
        Not sure about that, but as you see in the code above, we create a new singlecontextsource each time we perform a search.
        Did you try that with lookup as well?

        I mean:
        * create the singlecontextsource
        * run the paged query, get all results
        * destroy the single context source

        Repeat the above for each search/lookup.

        You must remember that it is not a good practice to keep the single context source open too much time, as the meaning of single context source is (taken from the javadoc):
        It is used as a decorator around a target ContextSource
        to make sure the target is never actually closed. Useful when working with e.g. paged results,
        as these require the same target to be used.

        So, not closing the target can leave un-freed resources.

        Hope it helps,