Hi,

are you sure you have entries below the point you are searching from ?
You are doing a search using a ONE_LEVEL scope, which will return oly
the children entries.


Le 06/03/2018 à 22:32, George S. a écrit :
> I'm trying to use the API library and i'm running into a problem. I'm
> trying to do a search (see method below). Using this bound connection, I
> can do a lookup. For example, I can do .lookup(base,"objectClass"),
> .lookup(base,"dc"), etc. However search isn't working.
> 
> Can anyone give me an idea of what I'm doing wrong. I've looked through
> the docs and I'm just not getting it.
> 
> public  Collection<Entry>search(String  base,String...
> attributeNames)throws  LdapException{
> 
> if  (attributeNames.length ==0){
>     attributeNames =new  String[]{ 
> "distinguishedName","objectClass","name",
> prop.getProperty("emailAddress","mail")};
> }
> Collection<Entry> entries =new  ArrayList<>();
> // LC is LdapNetworkConnection
>  EntryCursor cursor = lc.search(new  Dn(base),"(objectclass=*)",
> SearchScope.ONELEVEL,attributeNames);
> 
> if  (isDebugMode()){
>     System.err.print("search(\""+base+"\"");
>     for  (String  s : attributeNames){
>         System.err.print(",\""+s+"\"");
>     }
>     System.err.println(");");
>     System.err.println("cursor.available()="  + cursor.available());
> }
> 
> if  (cursor.available()){
>     for  (Entry entry: cursor){
>         entries.add(entry);
>     }
> }  else  {
>     if  (isDebugMode()){
>         System.err.println("SearchResults came back null!");
>     }
> }
> try  {
>     cursor.close();
> }  catch  (IOException ioeClose){
>     ioeClose.printStackTrace(System.err);
> }
> return  entries;
> }
> 
> The output is:
> 
> getAttribute() entry=[Entry
>     dn: DC=somedistrict,DC=k12,DC=local
> 
>     dc: somedistrict
> ]
>         dc
>                 somedistrict
> 
> search("DC=somedistrict,DC=k12,DC=local","objectClass");
> cursor.available()=false
> SearchResults came back null!
> 
>  
> 

-- 
Emmanuel Lecharny

Symas.com
directory.apache.org

Reply via email to