0
votes

I am working on android chat application using ejabberd 2.1.11. For searching whether a particular user exists or not i'm using UserSearchManager

public boolean isUserExists(IrishContact ic) {
        try {
            UserSearchManager search = new UserSearchManager(connection);
            Collection<String> services = search.getSearchServices();
            if (services.isEmpty()) {
                Log.v("IrishuserSearch ", "no service found");
            }

            Log.v("service name: ", connection.getServiceName());

            Form searchForm = search.getSearchForm("vjud."
                    + connection.getServiceName());

            Form answerForm = searchForm.createAnswerForm();
            answerForm.setAnswer("Username", true);
            answerForm.setAnswer("search", ic.getPhoneNumber());
            org.jivesoftware.smackx.ReportedData data = search
                    .getSearchResults(answerForm,
                            "search." + connection.getServiceName());

            if (data.getRows() != null) {
                Iterator<Row> it = data.getRows();
                if (it.hasNext()) {
                    return true;
                } else
                    return false;
            } else
                return false;

        } catch (XMPPException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return false;

    }

On the basis on this answer

i'm using

Form searchForm = search.getSearchForm("vjud." + connection.getServiceName());

instead of

Form searchForm = search.getSearchForm("search."+connection.getServiceName());

the later part was giving 503 service not found exception so i changed my code and it got solved, but now the problem is I am getting IllegalArgumentException at

answerForm.setAnswer("Username", true);

I am using asmack-android-8-0.8.10.

STACK_TRACE=java.lang.IllegalArgumentException: Field not found for the specified variable name.
at org.jivesoftware.smackx.Form.setAnswer(Form.java:258)
at com.irishtalk.utilities.IrishUserSearch.isUserExists(IrishUserSearch.java:42)

at com.irishtalk.utilities.IrishContactsHelper.addContactToDefaultRoster(IrishContactsHelper.java:51)
at com.irishtalk.utilities.IrishContactsHelper.getRoster(IrishContactsHelper.java:32)
at com.irishtalk.service.IXmppAidlStub$1.run(IXmppAidlStub.java:221)

can anyone help me out why this is happening? Thanks

1
Show us the stacktrace of the exception and tell us the version of aSmack you are using.Flow
@Flow I have posted stack trace and library version number please look at edited questionprateek

1 Answers

0
votes

Ejabberd does not support the field value "Username". It is used in openfire. Please use the field vale "user" and pass arguments as string in ejabberd. Thanks. Please Vote up if your error is solved.