powered by Jive Software

Searching directory for user - how

I’'m trying to use the SMACK jar to search for a user in a directory (search by first/last/ name or email or combination).

I tried to use the UserSearchManager but failed.

Is that the right way to do a user search? Can you provide me with a code sample? I tried the code in the UserSearchManager API but failed.

Sample from UserSearchManager API:

XMPPConnection con = new XMPPConnection(“jabber.org”);

con.login(“john”, “doe”);

UserSearchManager search = new UserSearchManager(con, “users.jabber.org”);

Form searchForm = search.getSearchForm();

Form answerForm = searchForm.createAnswerForm();

answerForm.setAnswer(“last”, “DeMoro”);

ReportedData data = search.getSearchResults(answerForm);

Is there another way to do that search?


What part of it failed?

No matter how I’‘m using the Form and its parameters, data always return as null. Probably I’'m using it the wrong way, or using wrong parameters

data: ReportedData data = search.getSearchResults(answerForm);

It looks like you’‘ve followed the example code correctly. The docs don’'t say anything about it, but maybe it returns null when there are no matches. Have you tried searching for someone that exists on your server?

In my user directory I have a user called:


I tried the followings:

answerFor.setAnswer(“first”, “a2”);

After failing I tried:

answerFor.setAnswer(“first”, "a2@aaa.bbb.com");

After failing I tried:

answerFor.setAnswer(“first”, “a2%”);

I failed with them all.

I tried the same test with the fillowing fields:

“first”, “last”, “nick” “email”.

Failed with all.

The difference between my code and the sample was due to difference in the API:

UserSearchManager search = new UserSearchManager(con); // instead of having another param, I think it is the service name

Form searchForm = um.getSearchForm(XMPP_SEARCH_SERVICE); // instead of having () like in the sample

Form answerForm = searchForm.createAnswerForm();

answerForm.setAnswer(“last”, “a2%”);

df = answerForm.getDataFormToSend();

ReportedData data = um.getSearchResults(answerForm, XMPP_SEARCH_SERVICE); // instead of having just answerForm

but I don’'t think this difference should impact the results

I just checked out the spark debugger, and Spark searches the username, name, and email fields when you use it’'s built-in search, so give username and name a try.

If that doesn’'t work, comparing the raw packets your program is sending with the ones Spark sends may shed some light on things.

Problem solved.

Turned out that on registering the user I did not use jud:

Registration request = new Registration();


request.setTo(“users.” + client.JABBER_XMPP_DOMAIN_NAME);

Map<String,String> attributes1 = new HashMap<String, String>();

attributes1.put(“nick”," a2 ");

attributes1.put(“first”," a2 ");

attributes1.put(“last”," a2 ");




I only saved to user profile in a VCard.

Adding these lines solved the problem

Thanks for the help