Announcement Announcement Module
Collapse
No announcement yet.
Error while doing paged query on LDAP Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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();
    searchControls.setSearchScope(_scope);
    searchControls.setReturningAttributes(null);

    List<LdapEntry> entries = _ldapTemplate.search(_base, _filter,
    searchControls, _attributeMapper, _processor);

    for (LdapEntry entry : entries) {

    _entriesQueue.addLast(entry);
    }

    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);
    ldapTemplate.search(baseDN, filter, searchControls, handler, requestControl);
    PagedResultsCookie cookie = requestControl.getCookie();
    while (cookie != null) {
    byte[] cookieBytes = cookie.getCookie();
    if (cookieBytes == null) {
    break;
    }
    requestControl = new PagedResultsDirContextProcessor(ldapPageSize, cookie);
    ldapTemplate.search(baseDN, 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}",
    baseDN,
    displayFilter,
    ex.getMessage());
    handleException(ex);
    } finally {
    singleContextSource.destroy();
    }
    return handler;
    }

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

    Hope it will help you,
    Oved

    Comment


    • #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.

      Thanks

      Comment


      • #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,
        Oved

        Comment

        Working...
        X