javax.naming.NamingException: [LDAP: error code 1 - Invalid query reference];
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Nazmu_Nazarali
Posted On:   Thursday, August 5, 2004 10:44 AM

I get the above error in the second iteration of my search (the counter reads 252) at following line in the sample code (I'm fairly new at java, and brand new at doing anything with LDAP): Attributes ar = ctx.getAttributes(dn, MY_ATTRS); sample code: Int pageSize = 249 // the server limit is 250 // Activate paged results ctx.setRequestControls(new Control[]{ new PagedResultsControl(pageSize)}); SearchControls constraints = new SearchControls(); constraints.setSearchScope(SearchControls.SUBTREE_SCOPE); itemCounter = 0; do { NamingEnumeration results = ctx.search(MY_SEARCHBASE, MY_F   More>>

I get the above error in the second iteration of my search (the counter reads 252) at following line in the sample code (I'm fairly new at java, and brand new at doing anything with LDAP):


Attributes ar = ctx.getAttributes(dn, MY_ATTRS);


sample code:


Int pageSize = 249 // the server limit is 250


// Activate paged results


ctx.setRequestControls(new Control[]{
new PagedResultsControl(pageSize)});


SearchControls constraints = new SearchControls();


constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);


itemCounter = 0;


do {


NamingEnumeration results = ctx.search(MY_SEARCHBASE, MY_FILTER, constraints);


// Now step through the search results


while ( results != null && results.hasMore() ){


itemCounter += 1;


SearchResult sr = (SearchResult) results.next();


String dn = sr.getName();


System.out.print (itemCounter);


System.out.println (" Distinguished Name is " +dn);



// Code for displaying attribute list


Attributes ar = ctx.getAttributes(dn, MY_ATTRS);


if (ar == null){ // Has no attributes


System.out.println("Entry "+ dn );


System.out.println(" has none of the specified attributes
");


}


else // Has some attributes


{


// Determine the attributes in this record.


for (int i=0; i



Attribute attr = ar.get(MY_ATTRS[i]);


if (attr != null){



System.out.println(MY_ATTRS[i] + ":");


// Gather all values for the
specified attribute.



for ( Enumeration vals=attr.getAll();
vals.hasMoreElements(); )


{


System.out.println (" " + vals.nextElement() );


}


}


}


}


}



// PagedResultsResponseControl contains the server cookie.


Control[] responseControls = ctx.getResponseControls();


// examining responseControls for a PagedResultsResponseControl


if (responseControls != null) {


for (int i = 0; i < responseControls.length; i++) {


if (responseControls[i] instanceof PagedResultsResponseControl) {


// create a new request control with the cookie


// from the server's response.


PagedResultsResponseControl prrc =
(PagedResultsResponseControl)responseControls[i];


total = prrc.getResultSize();


cookie = prrc.getCookie();


}


} // for


}


ctx.setRequestControls(new Control[]{
new PagedResultsControl(pageSize, cookie, Control.NONCRITICAL) });


} while (cookie != null);

   <<Less

Re: javax.naming.NamingException: [LDAP: error code 1 - Invalid query reference];

Posted By:   Nazmu_Nazarali  
Posted On:   Friday, August 6, 2004 11:10 AM

solved it! here's what is wrong with the function:


once you do this:


ctx.setRequestControls(new Control[]{ new PagedResultsControl(pageSize)});


followed by this:



NamingEnumeration results = ctx.search(MY_SEARCHBASE, MY_FILTER, constraints);



you cannot do this this:



Attributes ar = ctx.getAttributes(dn, MY_ATTRS);



since the next context method that may return controls is invoked.



in this instance, I got around by doing this:



Attributes ar = sr.getAttributes();

About | Sitemap | Contact