I am trying to search an user in open fire.
public void searchUser(String username) {
UserSearchManager userSearchManager = new UserSearchManager(
xmppConnection);
Form searchForm;
try {
searchForm = userSearchManager.getSearchForm("search."
+ xmppConnection.getServiceName());
Form answerForm = searchForm.createAnswerForm();
answerForm.setAnswer("Username", true);
answerForm.setAnswer("search", username);
org.jivesoftware.smackx.ReportedData data = userSearchManager
.getSearchResults(answerForm,
"search." + xmppConnection.getServiceName());
if (data.getRows() != null) {
Iterator<Row> it = data.getRows();
while (it.hasNext()) {
Row row = it.next();
Iterator<?> iterator = row.getValues("jid");
if (iterator.hasNext()) {
String value = iterator.next().toString();
System.out.println(value);
}
}
}
} catch (XMPPException e) {
e.printStackTrace();
}
}
There are some similar thread so i followed them and added this provider manager before connection.
public void getProviderManager(ProviderManager providerManager) {
// Private Data Storage
providerManager.addIQProvider("query", "jabber:iq:private",
new PrivateDataManager.PrivateDataIQProvider());
// Time
try {
providerManager.addIQProvider("query", "jabber:iq:time",
Class.forName("org.jivesoftware.smackx.packet.Time"));
} catch (ClassNotFoundException e) {
Log.w("TestClient",
"Can't load class for org.jivesoftware.smackx.packet.Time");
}
// Roster Exchange
providerManager.addExtensionProvider("x", "jabber:x:roster",
new RosterExchangeProvider());
// Message Events
providerManager.addExtensionProvider("x", "jabber:x:event",
new MessageEventProvider());
// Chat State
providerManager.addExtensionProvider("active",
"http://jabber.org/protocol/chatstates",
new ChatStateExtension.Provider());
providerManager.addExtensionProvider("composing",
"http://jabber.org/protocol/chatstates",
new ChatStateExtension.Provider());
providerManager.addExtensionProvider("paused",
"http://jabber.org/protocol/chatstates",
new ChatStateExtension.Provider());
providerManager.addExtensionProvider("inactive",
"http://jabber.org/protocol/chatstates",
new ChatStateExtension.Provider());
providerManager.addExtensionProvider("gone",
"http://jabber.org/protocol/chatstates",
new ChatStateExtension.Provider());
// XHTML
providerManager.addExtensionProvider("html",
"http://jabber.org/protocol/xhtml-im",
new XHTMLExtensionProvider());
// Group Chat Invitations
providerManager.addExtensionProvider("x", "jabber:x:conference",
new GroupChatInvitation.Provider());
// Service Discovery # Items
providerManager.addIQProvider("query",
"http://jabber.org/protocol/disco#items",
new DiscoverItemsProvider());
// Service Discovery # Info
providerManager.addIQProvider("query",
"http://jabber.org/protocol/disco#info",
new DiscoverInfoProvider());
// Data Forms
providerManager.addExtensionProvider("x", "jabber:x:data",
new DataFormProvider());
// MUC User
providerManager.addExtensionProvider("x",
"http://jabber.org/protocol/muc#user", new MUCUserProvider());
// MUC Admin
providerManager.addIQProvider("query",
"http://jabber.org/protocol/muc#admin", new MUCAdminProvider());
// MUC Owner
providerManager.addIQProvider("query",
"http://jabber.org/protocol/muc#owner", new MUCOwnerProvider());
// Delayed Delivery
providerManager.addExtensionProvider("x", "jabber:x:delay",
new DelayInformationProvider());
// Version
try {
providerManager.addIQProvider("query", "jabber:iq:version",
Class.forName("org.jivesoftware.smackx.packet.Version"));
} catch (ClassNotFoundException e) {
// Not sure what's happening here.
}
// VCard
providerManager.addIQProvider("vCard", "vcard-temp",
new VCardProvider());
// Offline Message Requests
providerManager.addIQProvider("offline",
"http://jabber.org/protocol/offline",
new OfflineMessageRequest.Provider());
// Offline Message Indicator
providerManager.addExtensionProvider("offline",
"http://jabber.org/protocol/offline",
new OfflineMessageInfo.Provider());
// Last Activity
providerManager.addIQProvider("query", "jabber:iq:last",
new LastActivity.Provider());
// User Search
providerManager.addIQProvider("query", "jabber:iq:search",
new UserSearch.Provider());
// SharedGroupsInfo
providerManager.addIQProvider("sharedgroup",
"http://www.jivesoftware.org/protocol/sharedgroup",
new SharedGroupsInfo.Provider());
// JEP-33: Extended Stanza Addressing
providerManager.addExtensionProvider("addresses",
"http://jabber.org/protocol/address",
new MultipleAddressesProvider());
// FileTransfer
providerManager.addIQProvider("si", "http://jabber.org/protocol/si",
new StreamInitiationProvider());
providerManager.addIQProvider("query",
"http://jabber.org/protocol/bytestreams",
new BytestreamsProvider());
// Privacy
providerManager.addIQProvider("query", "jabber:iq:privacy",
new PrivacyProvider());
providerManager.addIQProvider("command",
"http://jabber.org/protocol/commands",
new AdHocCommandDataProvider());
providerManager.addExtensionProvider("malformed-action",
"http://jabber.org/protocol/commands",
new AdHocCommandDataProvider.MalformedActionError());
providerManager.addExtensionProvider("bad-locale",
"http://jabber.org/protocol/commands",
new AdHocCommandDataProvider.BadLocaleError());
providerManager.addExtensionProvider("bad-payload",
"http://jabber.org/protocol/commands",
new AdHocCommandDataProvider.BadPayloadError());
providerManager.addExtensionProvider("bad-sessionid",
"http://jabber.org/protocol/commands",
new AdHocCommandDataProvider.BadSessionIDError());
providerManager.addExtensionProvider("session-expired",
"http://jabber.org/protocol/commands",
new AdHocCommandDataProvider.SessionExpiredError());
}
Still i am getting
12-07 01:14:58.027: W/System.err(1591): bad-request(400)
12-07 01:14:58.037: W/System.err(1591): at org.jivesoftware.smackx.search.UserSearch.getSearchForm(UserSearch.java:84)
12-07 01:14:58.037: W/System.err(1591): at org.jivesoftware.smackx.search.UserSearchManager.getSearchForm(UserSearchManager.java:73)
12-07 01:14:58.037: W/System.err(1591): at com.afinity.core.chat.ChatManager.searchUser(ChatManager.java:107)
12-07 01:14:58.037: W/System.err(1591): at com.afinity.chat.ui.Activity.<init>(Activity.java:19)
12-07 01:14:58.037: W/System.err(1591): at java.lang.Class.newInstanceImpl(Native Method)
12-07 01:14:58.047: W/System.err(1591): at java.lang.Class.newInstance(Class.java:1208)
12-07 01:14:58.047: W/System.err(1591): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
12-07 01:14:58.047: W/System.err(1591): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2093)
12-07 01:14:58.047: W/System.err(1591): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
12-07 01:14:58.047: W/System.err(1591): at android.app.ActivityThread.access$700(ActivityThread.java:135)
12-07 01:14:58.047: W/System.err(1591): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
12-07 01:14:58.047: W/System.err(1591): at android.os.Handler.dispatchMessage(Handler.java:102)
12-07 01:14:58.047: W/System.err(1591): at android.os.Looper.loop(Looper.java:137)
12-07 01:14:58.047: W/System.err(1591): at android.app.ActivityThread.main(ActivityThread.java:4998)
12-07 01:14:58.047: W/System.err(1591): at java.lang.reflect.Method.invokeNative(Native Method)
12-07 01:14:58.047: W/System.err(1591): at java.lang.reflect.Method.invoke(Method.java:515)
12-07 01:14:58.047: W/System.err(1591): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
12-07 01:14:58.047: W/System.err(1591): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
12-07 01:14:58.047: W/System.err(1591): at dalvik.system.NativeStart.main(Native Method)