Announcement Announcement Module
Collapse
No announcement yet.
LDAP: error code 2 - paged results cookie is invalid Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment


    • #3
      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?

      Comment

      Working...
      X