Announcement Announcement Module
Collapse
No announcement yet.
SimpleLdapTemplate.search failing - resetting values? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SimpleLdapTemplate.search failing - resetting values?

    I haven't changed my code since yesterday but it isn't working today. Suddenly the code that does the mapping from the found context into the person instance gets called 2x: the first time is fine but when it is called again the context is null! I have no idea what is triggering the 2nd call.

    Code:
    	public List<QcPerson> findByFilter(Filter filter) {
    		logger.debug("findByFilter called with filter: " + filter.encode());
    		List<QcPerson> ldapPersons = new ArrayList<QcPerson>();
    		
    		try {
    			ldapPersons = simpleLdapTemplate.search(
    					DistinguishedName.EMPTY_PATH, filter.encode(), new PersonContextMapper());
    		} catch (org.springframework.ldap.NameNotFoundException nnfe) {
    		logger.debug("No records were found using filter: " + filter.encode());
    		} catch (Exception e) {
    			logger.debug(StackTraceUtil.getCustomStackTrace(e));
    		}
    		return ldapPersons;
    	}
    When I execute the app, the search is able to get the context of the record and then it executes the new PersonContextMapper() as expected. Here is the PersonContextMapper nested class:
    Code:
    	private static final class PersonContextMapper extends
    			AbstractParameterizedContextMapper<QcPerson> {
    		@Override
    		protected QcPerson doMapFromContext(DirContextOperations context) {
    			QcPerson p = getQcPerson(context);
    			return p;
    		}
    	}
    NOTE: Whether or not I do the full mapping within this method or call the external method that maps each of the fields I have the same problem. Here is the beginning of the static getQcPerson(context) method:
    Code:
    		DirContextOperations context = (DirContextOperations) ctx;
    		QcPerson p = new QcPerson();
    
    		DistinguishedName dn = (DistinguishedName) context.getDn();
    		String uid = dn.getValue("uid");
    		logger.debug("dn from context is [" + dn + "]");
    		logger.debug("setting uid to [" + uid + "]");
    		if ( uid != null) p.setUid( uid );
                    ...
    Note the 2 logger.debug lines in the CODE above, and now look at the output below. The 2 lines are repeated because the getQcPerson() method is somehow called 2x. The 2nd call has a null dn so everything fails.

    2010-10-01 03:01:50,939 DEBUG com.qualcomm.ldap.model.dao.PersonDaoImpl, 87 - findByFilter called with filter: (employeeNumber=83030)
    2010-10-01 03:02:42,047 DEBUG com.qualcomm.ldap.model.dao.PersonDaoImpl, 254 - dn from context is [uid=c_jandru]
    2010-10-01 03:02:42,051 DEBUG com.qualcomm.ldap.model.dao.PersonDaoImpl, 255 - setting uid to [c_jandru]
    2010-10-01 03:04:19,733 DEBUG com.qualcomm.ldap.model.dao.PersonDaoImpl, 254 - dn from context is [uid=null]
    2010-10-01 03:04:19,743 DEBUG com.qualcomm.ldap.model.dao.PersonDaoImpl, 255 - setting uid to [null]
    I've spent hours on this and it worked perfectly fine yesterday. My app is using:
    <spring.version>3.0.3.RELEASE</spring.version>
    <spring.ldap.version>1.3.0.RELEASE</spring.ldap.version>

    Please help asap. External teams are supposed to be using my app in their integration tests today!

  • #2
    Problem resolved

    The problem was that the testing I did yesterday accidentally created a user with a null uid which is part of the dn. When I queried by the employeeNumber it found both records and kept crashing on the 2nd record.
    I knew the code worked yesterday.

    Comment

    Working...
    X