Announcement Announcement Module
Collapse
No announcement yet.
Empty String and PagedResults Control Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Empty String and PagedResults Control

    Hello,
    I was performing a search starting from a given dn. Now if I supply an empty string instead of an actual dn string I get a null pointer exception in the PageResultsRequestControl.

    Code:
    java.lang.NullPointerException
    	at org.springframework.ldap.control.PagedResultsRequestControl.postProcess(PagedResultsRequestControl.java:121)
    	at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:289)
    	at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:225)
    	at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:539)
    	at
    I thought with JNDI if you supply an empty string you obtain the entries which start from the root of the ldap server? Similar to the preProcess in the postProcess whether the controls are null or not should be checked.
    Last edited by zbhiwandiwala; Apr 30th, 2007, 12:31 PM. Reason: Misspelt JNDI.

  • #2
    The problem is very similar to the one in preProcess. The code in postProcess assumes that we get a non-null array of response controls from the context, just like AbstractRequestControlDirContextProcessor.preProce ss assumed a non-null array of request controls.

    Thanks for spotting this. I've created a JIRA issue for it.

    Comment


    • #3
      Thinking a little bit more on this, I'm wondering why there isn't at least a PagedResultsResponseControl in the context. Could you provide us with more details, like the complete stack trace, your search code, your configuration, and what server you're using?

      Comment


      • #4
        Search Details

        Server - Windows 2000 Server ( I am using the AD server with it.)

        I am using the Spring-LDAP build from the 4/29/07 as that had the bug fix for the preProcess.

        I am manually following referrals, so I have java.naming.referral = follows.

        Config File :
        Code:
         <bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
              <property name="url" value="${ldap.url}" />
              <property name="base" value="" />
              <property name="userName" value="${ldap.managerdn}" />
              <property name="password" value="${ldap.password}" />
              <property name="baseEnvironmentProperties">
              		 <map>
              		 	<entry key="java.naming.ldap.attributes.binary" value="objectGUID"/>
              		 	<entry key="java.naming.referral" value="follow"/>
              		 </map>	
              </property>
        
           </bean>
        
           <bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
              <constructor-arg ref="contextSource" />
              <!--<property name="ignorePartialResultException">
              <value>true</value>
              </property>  -->
           </bean>

        Sample Code :
        Code:
           private LdapResults getLdapOrganizationalUnits(final PagedResultsCookie cookie, final String startdn,
                    final int searchscope) {
        
                PagedResultsRequestControl requestControl = null;
                if(cookie != null && cookie.getCookie() != null && cookie.getCookie().length != 0) {
                    requestControl = new PagedResultsRequestControl(this.pagesize, cookie);
                } else {
                    requestControl = new PagedResultsRequestControl(this.pagesize);
                }
                SearchControls searchControls = new SearchControls(searchscope, 0, 0, null, false, false);
        
                try {
                    List results = this.ldapTemplate.search(startdn, this.ouAttributesMapper.getEntityFilter(), searchControls,
                            this.ouAttributesMapper, requestControl);
                    LdapResults ldapResults = new LdapResults();
                    ldapResults.setEntities(results);
                    ldapResults.setCookie(requestControl.getCookie());
                    return ldapResults;
                } catch(final org.springframework.ldap.PartialResultException e) {
                    logger.error("Partial result exception occured", e);
                    throw e;
                } catch(final org.springframework.ldap.NamingException e) {
                    throw e;
                } catch(final java.lang.NullPointerException e) {
                    // note zb : 04/30/07
                    // If an invalid dn is supplied a null pointer exception occurs during the post
                    // process of the DirContext. This is due to the fact that the PageResultsRequestControl
                    // post process method does not account for a null return array. We will ignore this for now,just log it
                    logger.error(e);
                    return null;
                }
            }
        I do have some of my custom classes used. But the basic process is that the cookie is sent back to the calling method if it has adddtional bytes it is sent back.

        When you do set the java.naming.referral = follow , the ManageReferral control is not sent as a part of the server request. I am not sure if that control gets returned even if we had a naming exception and then the array is not null.

        Full Stack trace :

        Code:
        java.lang.NullPointerException
        	at org.springframework.ldap.control.PagedResultsRequestControl.postProcess(PagedResultsRequestControl.java:121)
        	at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:289)
        	at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:225)
        	at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:539)
        	at com.docfinity.dao.ldap.activedirectory.ADLdapDAO.getLdapOrganizationalUnits(ADLdapDAO.java:334)
        	at com.docfinity.dao.ldap.activedirectory.ADLdapDAO.populateOrganizationalUnits(ADLdapDAO.java:122)
        	at com.docfinity.manager.ldap.activedirectory.ADLdapManagerImpl.populateOrganizationalUnits(ADLdapManagerImpl.java:51)
        	at com.docfinity.ldap.LdapManagerTests.testGetExternalOUSubtreeEmptyBaseDN(LdapManagerTests.java:63)
        	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        	at java.lang.reflect.Method.invoke(Unknown Source)
        	at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
        	at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
        	at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
        	at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
        	at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
        	at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:71)
        	at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
        	at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
        	at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
        	at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
        	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
        	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
        	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
        	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
        	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

        Comment


        • #5
          I have added a null check now. Please verify if this solves your problem.

          Comment


          • #6
            Paged Results Control

            Hey Ulsa,
            Thanks for quick turn around for the bug. I don't get any null pointer exception any more. It seems to work fine.

            Comment

            Working...
            X