Announcement Announcement Module
Collapse
No announcement yet.
ldapTemplate is null in bean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    We'll need more information in order to track down this problem, i.e. code, configuration files and stack trace.

    Comment


    • #3
      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();
      }
      });

      }
      }

      Comment


      • #4
        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

        Comment


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

          Comment


          • #6
            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!

            Comment

            Working...
            X