You are viewing a plain text version of this content. The canonical link for it is here.
Posted to api@directory.apache.org by Claudio <cl...@gmail.com> on 2015/03/21 15:29:38 UTC
Search problems
Hello friends,
I want to list all the mails that have an entry in my ldap server.
My code is:
LdapConnection connection =new LdapNetworkConnection(hostname));
connection().bind(adminLDAP, password);
ArrayList<String> mailList = new ArrayList<String>();
EntryCursor cursor = connection().search( dnUser, "(mail=*)",
SearchScope.SUBTREE );
Entry resultSearch= null;
while ( cursor.next() )
{
resultSearch = cursor.get();
Attribute attr = resultSearch.get("mail");
mailList.add(attr.getString());
}
This code lists only one mail for each of the entry not everyone who has.
I need help with this
thank you very much
Re: Search problems
Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 21/03/15 16:19, Kiran Ayyagari a écrit :
> On Sat, Mar 21, 2015 at 10:29 PM, Claudio <cl...@gmail.com> wrote:
>
>> Hello friends,
>>
>> I want to list all the mails that have an entry in my ldap server.
>>
> you mean you want to list all the mail addresses present in each entry?
>
>> My code is:
>>
>>
>>
>> LdapConnection connection =new LdapNetworkConnection(hostname));
>> connection().bind(adminLDAP, password);
>>
>> ArrayList<String> mailList = new ArrayList<String>();
>>
>> EntryCursor cursor = connection().search( dnUser, "(mail=*)",
>> SearchScope.SUBTREE );
>> Entry resultSearch= null;
>> while ( cursor.next() )
>> {
>>
>> resultSearch = cursor.get();
>> Attribute attr = resultSearch.get("mail");
>> mailList.add(attr.getString());
>>
>>
>> }
>>
>>
>>
>> This code lists only one mail for each of the entry not everyone who has.
>>
> mail is a multivalued attribute, so you need to iterate on the 'attr'
> reference and
> get all the values instead of calling attr.getString(), which returns only
> one of those present.
Which is done with such a code :
while ( cursor.next() )
{
resultSearch = cursor.get();
for ( Value<?> mail : resultSearch.getA("mail") )
{
mailList.add(mail.getSTring());
}
}
>
>> I need help with this
>>
>>
>> thank you very much
>>
>
>
Re: Search problems
Posted by Kiran Ayyagari <ka...@apache.org>.
On Sat, Mar 21, 2015 at 10:29 PM, Claudio <cl...@gmail.com> wrote:
> Hello friends,
>
> I want to list all the mails that have an entry in my ldap server.
>
you mean you want to list all the mail addresses present in each entry?
>
> My code is:
>
>
>
> LdapConnection connection =new LdapNetworkConnection(hostname));
> connection().bind(adminLDAP, password);
>
> ArrayList<String> mailList = new ArrayList<String>();
>
> EntryCursor cursor = connection().search( dnUser, "(mail=*)",
> SearchScope.SUBTREE );
> Entry resultSearch= null;
> while ( cursor.next() )
> {
>
> resultSearch = cursor.get();
> Attribute attr = resultSearch.get("mail");
> mailList.add(attr.getString());
>
>
> }
>
>
>
> This code lists only one mail for each of the entry not everyone who has.
>
mail is a multivalued attribute, so you need to iterate on the 'attr'
reference and
get all the values instead of calling attr.getString(), which returns only
one of those present.
>
> I need help with this
>
>
> thank you very much
>
--
Kiran Ayyagari
http://keydap.com