Announcement Announcement Module
Collapse
No announcement yet.
LDAP-64: NPE at LdapContextSource.getAnonymousEnv Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • LDAP-64: NPE at LdapContextSource.getAnonymousEnv

    Hi,

    i am trying to beginning to work with spring-ldap in following context:
    EJB
    JBoss 4.2.1
    spring-ldap 1.2

    And setting up and doing first search with:
    Code:
    		DefaultDirObjectFactory factory = new DefaultDirObjectFactory();
    		contextSource.setBase("basedn");
    		contextSource.setUrl("ldap://localhost:8389");
    		contextSource.setUserDn("mangerdn);
    		contextSource.setPassword("secret");
    		contextSource.setDirObjectFactory(factory.getClass());
    		contextSource.setResponseControlFactory(ResponseControlFactory.class);
    		ldapTemplate.setContextSource(contextSource);
    		List l = ldapTemplate.search( "", "(objectclass=person)",
    				new AttributesMapper() {
    					public Object mapFromAttributes(Attributes attrs) throws NamingException {
    						return attrs.get("cn").get();
    					}
    				});
    ...but getting:

    Code:
    Caused by: java.lang.NullPointerException
    	at org.springframework.ldap.core.support.LdapContextSource.getAnonymousEnv(LdapContextSource.java:49)
    	at org.springframework.ldap.core.support.AbstractContextSource.getAuthenticatedEnv(AbstractContextSource.java:449)
    	at org.springframework.ldap.core.support.AbstractContextSource.getReadOnlyContext(AbstractContextSource.java:107)
    	at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:266)
    ...
    In JIRA at LDAP-64 it should be fixed, so I think the fault is on my side.

    I am new to spring, so it might be possible
    Any suggestions?

    Regards!

    EDIT:
    I have added the setResponseControlFactory and setDirObjectFactory for testing, to check if it works with, but its the same...the same without setting ResponseControlFactory
    Last edited by miwo; Dec 3rd, 2007, 07:41 AM.

  • #2
    The line
    DefaultDirObjectFactory factory = new DefaultDirObjectFactory();
    is a little confusing. However, the rest of the code seems to be in order. You don't need to set DirObjectFactory or ResponseControlFactory. What you do need to do when configuring ContextSource manually (as opposed to when configuring it in a Spring Application Context) is call afterPropertiesSet() to finish up initialization (this is done automatically in a Spring Application Context).

    Comment


    • #3
      Hi rasky,

      thx for that advice. Now, it works
      I wonder, that this method-call was not used in the source-examples I had found for direct-configuration...otherwise I had found the useless confusing factory-calls.

      Regards.

      Comment


      • #4
        Well, admittedly it's not completely explicit, but it is mentioned in the javadocs.

        Comment


        • #5
          Thanks it hepled me too

          Comment

          Working...
          X