View Full Version : ldapTemplate is null in bean
mpiscatello
Jul 31st, 2006, 03:58 PM
The ldapTemplate is null in the bean that is getting it. No errors, what can I do to troubleshoot?
Thanks
rasky
Aug 1st, 2006, 12:55 AM
We'll need more information in order to track down this problem, i.e. code, configuration files and stack trace.
mpiscatello
Aug 1st, 2006, 07:24 AM
Here is the bean configuration and the code. I am using other beans in my configuration that are working so I know spring is reading the file.
<bean id="contextSource"
class="net.sf.ldaptemplate.support.DirContextSource">
<property name="url" value="ldap://192.168.250.201:389" />
<property name="base" value="dc=AAC,dc=USAREC,dc=ARMY,dc=MIL" />
<property name="userName" value="cn=DSAMEUSER,ou=DSAME Users;dc=aac,dc=usarec,dc=army,dc=mil" />
<property name="password" value="n0password" />
</bean>
<bean id="ldapTemplate"
class="net.sf.ldaptemplate.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
<bean id="ldapDao"
class="mil.army.usaac.ariss.mpa.missionsupport.LdapDao">
<property name="ldapTemplate" ref="ldapTemplate" />
</bean>
package mil.army.usaac.ariss.mpa.missionsupport;
import java.util.Iterator;
import java.util.List;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import org.apache.log4j.Logger;
import net.sf.ldaptemplate.AttributesMapper;
import net.sf.ldaptemplate.LdapTemplate;
public class LdapDao {
private LdapTemplate ldapTemplate;
private static final Logger log = Logger.getLogger(LdapDao.class);
public void setLdapTemplate(LdapTemplate ldapTemplate) {
this.ldapTemplate = ldapTemplate;
}
public String getRoleCodeForRctrId(String RctrId) {
List roleCodes = getAllRolesForId(RctrId);
Iterator it = roleCodes.iterator();
String roleCd = "";
while (it.hasNext()){
roleCd = (String)it.next();
}
return roleCd;
}
private List getAllRolesForId(String RctrId) {
log.debug("RctrId value " + RctrId);
log.debug("Template object " + ldapTemplate);
return ldapTemplate.search("", "(RctrId=" + RctrId + ")",
new AttributesMapper() {
public Object mapFromAttributes(Attributes attrs)
throws NamingException {
return attrs.get("LEADSRoles").get();
}
});
}
}
mpiscatello
Aug 1st, 2006, 07:43 AM
Here is what I am getting in the log:
2006-08-01 08:38:31,881 DEBUG [main] support.AbstractContextSource - AuthenticationSource not set - using default implementation
2006-08-01 08:38:31,972 DEBUG [main] support.AbstractContextSource - Using LDAP pooling.
2006-08-01 08:38:31,974 DEBUG [main] support.AbstractContextSource - Trying provider Urls: ldap://192.168.250.201:389/dc=AAC,dc=USAREC,dc=ARMY,dc=MIL
rasky
Aug 1st, 2006, 08:02 AM
Well, on a quick glance I can't see anything wrong with the configuration files or the code (I'm assuming the spaces in the configuration file are typos in the forum post).
I suggest debugging to see whether setLdapTemplate() gets called, and if so, that the LdapDao instance being used is the one configured in the Application Context.
mpiscatello
Aug 1st, 2006, 08:30 AM
Thanks for the advise. I checked the setLdapTemplate method and the value is being set properly. I was NOT injecting the LdapDao into the bean that uses it, so it was creating a new reference that did not have the ldapTemplate object set.
Thanks!
Powered by vBulletin® Version 4.2.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.