Results 1 to 6 of 6

Thread: ldapTemplate is null in bean

  1. #1
    Join Date
    Jul 2006
    Posts
    4

    Default ldapTemplate is null in bean

    The ldapTemplate is null in the bean that is getting it. No errors, what can I do to troubleshoot?

    Thanks

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

    Default

    We'll need more information in order to track down this problem, i.e. code, configuration files and stack trace.
    Mattias Arthursson
    Jayway AB (www.jayway.se)
    Spring-LDAP project member

  3. #3
    Join Date
    Jul 2006
    Posts
    4

    Default More information...

    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.DirContextSourc e">
    <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.Lda pDao">
    <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();
    }
    });

    }
    }

  4. #4
    Join Date
    Jul 2006
    Posts
    4

    Default Log messages

    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

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

    Default

    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.
    Mattias Arthursson
    Jayway AB (www.jayway.se)
    Spring-LDAP project member

  6. #6
    Join Date
    Jul 2006
    Posts
    4

    Default Problem solved

    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!

Posting Permissions

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