Results 1 to 3 of 3

Thread: LDAP: error code 2 - paged results cookie is invalid

  1. #1
    Join Date
    Sep 2010
    Posts
    1

    Unhappy LDAP: error code 2 - paged results cookie is invalid

    I am trying to get paged results from OpenLdap
    first page runs without difficulties but with second I got invalid cookie error

    to get the list I use this:

    def PagedResult listEm(PagedResultsCookie cookie) {

    final int PAGE_SIZE = 1;
    PagedResultsDirContextProcessor pageProcessor = new PagedResultsDirContextProcessor(PAGE_SIZE, cookie);

    SearchControls searchControls = new SearchControls();
    searchControls.setSearchScope(SearchControls.SUBTR EE_SCOPE);
    searchControls.setReturningObjFlag(true);

    List people = ldapTemplate.search("", "(objectclass=person)", searchControls, new PersonAttributesMapper(), pageProcessor);

    return new PagedResult(people, pageProcessor.getCookie());
    //return ldapTemplate.search( "", "(objectclass=person)",new PersonAttributesMapper())

    }

    def result = listEm(null);
    PagedResultsCookie prCookie = result.getCookie();
    def peopleList = result.getResultList();

    result = listEm(prCookie); //errror

  2. #2
    Join Date
    Jul 2005
    Location
    Helsingborg, Sweden
    Posts
    504

    Default

    It's probably getting a new connection on the second run, thus loosing the cookie. When I test PagedResults, I configure the context source like this:

    Code:
    <bean id="contextSource" class="org.springframework.ldap.core.support.SingleContextSource">
       <constructor-arg ref="context" />
    </bean>
    	 
    <bean id="context" factory-bean="contextSourceTarget" factory-method="getReadOnlyContext" />
    	 
    <bean id="contextSourceTarget" class="org.springframework.ldap.core.support.LdapContextSource">
       <property name="urls" value="${urls}" />
       <property name="base" value="dc=jayway,dc=se" />
       <property name="userDn" value="${userDn}" />
       <property name="password" value="${password}" />
    </bean>
    
    <bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
       <constructor-arg ref="contextSource" />
    </bean>
    Be careful, though. Stepping away from the comfort of the automatic closing of resources in LdapTemplate can be risky.
    Ulrik Sandberg
    Jayway (www.jayway.com)
    Spring LDAP project member

  3. #3

    Default Paged + sorted results

    Hi

    I have two questions:
    The search method
    Code:
    	public PagedResult getAllPersons(PagedResultsCookie cookie) {
    		final int PAGE_SIZE = 10;
    		
    		PagedResultsDirContextProcessor pager = new PagedResultsDirContextProcessor(PAGE_SIZE, cookie);
    
    		//SortControlDirContextProcessor sorter = new SortControlDirContextProcessor("uid");
    
    		AggregateDirContextProcessor processor = new AggregateDirContextProcessor();
    		//processor.addDirContextProcessor(sorter);
    		processor.addDirContextProcessor(pager);
    
    		
    		SearchControls searchControls = new SearchControls();
    		searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    		searchControls.setReturningObjFlag(true);
    
    		AndFilter filter = new AndFilter();
    		filter.and(new EqualsFilter("objectClass", "Person"));
    		
    		List people = ldapTemplate.search(DistinguishedName.EMPTY_PATH, filter.encode(), searchControls, getContextMapper(), processor);
    
    		return new PagedResult(people, pager.getCookie());
    		 }
    It's ok.
    How can I get total of the ldap base?
    I have more than 3000 entry.

    And I can't sort by cn or uid for example.
    How can I do this?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •