Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: sizelimit

  1. #1

    Default sizelimit

    Can I somehow define sizelimit for my ldap searches?

  2. #2
    Join Date
    Mar 2005
    Location
    Landskrona, Sweden
    Posts
    505

    Default

    You can use one of the search methods that take SearchControls as an argument and set that parameter manually.

    However if the sizelimit is actually exceeded you will get a SearchLimitExceededException thrown from LdapTemplate, which will cause the collected objects thus far to be lost, which may or may not be what you want.

    If you want to keep the results you'll need to call the search(Name, String, SearchControls, SearchResultCallbackHandler) method and create the SearchResultCallbackHandler (e.g. a LdapTemplate.ContextMapperCallbackHandler) manually.
    Mattias Arthursson
    Jayway AB (www.jayway.se)
    Spring-LDAP project member

  3. #3
    Join Date
    Oct 2006
    Posts
    4

    Default I try this...

    Hello...

    Here is my test code:

    Code:
    private static Logger log = Logger.getLogger(TestSpringLDAP.class);
    
    	@Test
    	public void getAllUsers()
    	{
    		LdapContextSource source = new LdapContextSource();
    		source.setUrl(TestConfig.LDAP_CONNECTION_URL);
    		source.setBase(TestConfig.LDAP_BASE);
    		source.setUserName(TestConfig.LDAP_USER_NAME);
    		source.setPassword(TestConfig.LDAP_PASSWORD);
    		source.setDirObjectFactory(DefaultDirObjectFactory.class);
    		source.setAnonymousReadOnly(true);
    	        source.setContextFactory(com.sun.jndi.ldap.LdapCtxFactory.class);
    		source.setCacheEnvironmentProperties(false);
    		source.setPooled(false);
    		LdapTemplate template = new LdapTemplate(source);
    		template.setIgnorePartialResultException(true);
    		SearchControls searchControls = new SearchControls();
    		searchControls.setCountLimit(5);
    		searchControls.setReturningObjFlag(true);
    		searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    		List result = null;
    		result = template.search("", "(objectClass=person)", searchControls, new PersonContextMapper());
    	}
    
    	private static class PersonContextMapper implements ContextMapper
    	{
    		public Object mapFromContext(Object ctx)
    		{
    			DirContextAdapter context = (DirContextAdapter) ctx;
    			String result = context.getStringAttribute("uid");
    			Person person = new Person();
    			System.out.println("ctx " + ctx);
    			return result;
    		}
    	}
    and I've got a:
    LDAP: error code 4 - Sizelimit Exceeded]; remaining name ''

    What's wrong?

  4. #4
    Join Date
    Mar 2005
    Location
    Landskrona, Sweden
    Posts
    505

    Default

    That is the expected behaviour:
    Quote Originally Posted by rasky View Post
    However if the sizelimit is actually exceeded you will get a SearchLimitExceededException thrown from LdapTemplate, which will cause the collected objects thus far to be lost, which may or may not be what you want.

    If you want to keep the results you'll need to call the search(Name, String, SearchControls, SearchResultCallbackHandler) method and create the SearchResultCallbackHandler (e.g. a LdapTemplate.ContextMapperCallbackHandler) manually.
    Mattias Arthursson
    Jayway AB (www.jayway.se)
    Spring-LDAP project member

  5. #5
    Join Date
    Oct 2006
    Posts
    4

    Default Thanx

    Thanx for reply.

    But method search(Name, String, SearchControls, SearchResultCallbackHandler) is in the LdapTemplate package from http://sourceforge.net/projects/ldaptemplate/ and there is not defined LdapTemplate(LdapContextSource) constructor.

  6. #6
    Join Date
    Mar 2005
    Location
    Landskrona, Sweden
    Posts
    505

    Default

    Quote Originally Posted by Nullpointer View Post
    Thanx for reply.

    But method search(Name, String, SearchControls, SearchResultCallbackHandler) is in the LdapTemplate package from http://sourceforge.net/projects/ldaptemplate/ and there is not defined LdapTemplate(LdapContextSource) constructor.
    Ah, quite right. SearchResultCallbackHandler was replaced by NameClassPairCallbackHandler in Spring LDAP. Sorry for the confusion.
    Mattias Arthursson
    Jayway AB (www.jayway.se)
    Spring-LDAP project member

  7. #7
    Join Date
    Aug 2006
    Posts
    2

    Default SearchLimitExceededException

    Hello,

    As stated in this thread I now pass an AttributesMapperCallbackHandler to the search method and still get SearchLimitExceededException. I even tried setting count limit in SearchControls to 0.

    Here's the code:

    CollectingNameClassPairCallbackHandler handler = ldapTemplate.new AttributesMapperCallbackHandler(new PersonAttributesMapper());

    ldapTemplate.search("", orFilter.encode(), searchControls, handler);

    <bean id="searchControls" class="javax.naming.directory.SearchControls">
    <property name="countLimit" value="0" />
    <property name="searchScope" value="2" />
    </bean>

    <bean id="ldapSearchBean" class="de.mun.services.cd.LdapSearchServiceImpl">
    <property name="ldapTemplate"><ref bean="ldapTemplate"/></property>
    <property name="searchControls"><ref bean="searchControls"/></property>
    </bean>

    Please help :-(

  8. #8
    Join Date
    Mar 2005
    Location
    Landskrona, Sweden
    Posts
    505

    Default

    It's possible to specify search limit in server configuration as well, so there's always the possibility of getting that exception even though you haven't specified any count limit yourself.

    Also, using an AttributesMapperCallbackHandler will not prevent any exceptions from being thrown. It does however give you access to the results that have been processed up to when the exception is thrown, using the getList() method of CollectingNameClassPairCallbackHandler.
    Mattias Arthursson
    Jayway AB (www.jayway.se)
    Spring-LDAP project member

  9. #9
    Join Date
    Aug 2006
    Posts
    2

    Default sizelimit

    Hello,
    Thanks for the reply.

    If I implement the same search functionality in the traditional way using InitialDirContext, I get all the results returned without any exception being thrown.

    ctx = new InitialDirContext(env);
    SearchControls ctls = new SearchControls();
    ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    ctls.setReturningAttributes (ldapattrs );

    NamingEnumeration answer = ctx.search(CONTEXT, filter, ctls);

    This implies there's no search limit specified on the server. So what are the other possibilities of getting the exception? Is there no way of getting all the results?

  10. #10
    Join Date
    Mar 2005
    Location
    Landskrona, Sweden
    Posts
    505

    Default

    Did you actually try to loop through the NamingEnumeration you get back in the plain JNDI code? The LimitExceededException may be thrown when calling NamingEnumeration.hasMore().

    Once again, if the search limit is actually exceeded there's really no simple way of avoiding the Exception being thrown. But you can get hold of the entries collected up to when the exception was thrown using e.g. an AttributesMapperCallbackHandler instantiated by you before you call LdapTemplate. That instance holds a list that will be filled with all entries found so far.
    Mattias Arthursson
    Jayway AB (www.jayway.se)
    Spring-LDAP project member

Posting Permissions

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