2

How to search registered user by user id on ejabberd server using asmack in Android?

Following is my code:

                //Host & serviceName both are IP_ADDRESS of the ejabberd server.
                UserSearchManager usm = new UserSearchManager(connection);
                /*Collection<String> services = usm.getSearchServices();
                if(services.isEmpty())
                    throw new Exception("No search services avilable");
                String service = services.iterator().next();*/
                Form searchForm = usm.getSearchForm(/*service*/"vjud." + connection.getServiceName());
                Form answerForm = searchForm.createAnswerForm();
                //answerForm.setAnswer("Username", true);
                    // Tried with only osama also
                answerForm.setAnswer("user", "osama@IP_ADDRESS");
                ReportedData rd = usm.getSearchResults(answerForm, /*service*/"vjud." + connection.getServiceName());
                Iterator<Column> iCols = rd.getColumns();
                Iterator<Row> iRows = rd.getRows();
                while(iCols.hasNext()) {
                    Log.i("COLS", iCols.next().getLabel());
                }
                while(iRows.hasNext()) {
                    Log.i("ROWS", iRows.next().toString());
                }

Following is the output where I am getting columns but not any rows which means it is not getting any user though the user is registered:

10-17 14:09:38.212: I/COLS(30588): Jabber ID
10-17 14:09:38.212: I/COLS(30588): Full Name
10-17 14:09:38.212: I/COLS(30588): Name
10-17 14:09:38.212: I/COLS(30588): Middle Name
10-17 14:09:38.212: I/COLS(30588): Family Name
10-17 14:09:38.212: I/COLS(30588): Nickname
10-17 14:09:38.212: I/COLS(30588): Birthday
10-17 14:09:38.212: I/COLS(30588): Country
10-17 14:09:38.212: I/COLS(30588): City
10-17 14:09:38.212: I/COLS(30588): Email
10-17 14:09:38.212: I/COLS(30588): Organization Name
10-17 14:09:38.212: I/COLS(30588): Organization Unit

I checked this on local ejabberd server on my development machine but still same output.

I tried this answer of stackoverflow getSearchForm returns null when using UserSearch in XMPP with aSmack before which I was getting NullPointerException on following line:

Form answerForm = searchForm.createAnswerForm();

I just wanted to check whether the user has registered. Now, if he has not registered I will send a link to register or else directly send message if registered.

Community
  • 1
  • 1
Osama Mohammed Shaikh
  • 1,219
  • 1
  • 16
  • 40

0 Answers0