XMPP IQ result parsing issue

 ̄綄美尐妖づ 提交于 2019-12-12 10:07:32

问题


I am building a XMPP chat client app with eclipse, java and asmack. Using tutorials and many many google searches I managed to get the buddy list working, actual chatting also works fine. My problem is with searching for more buddies to add to my contacts list. The XML to send is exemplified here : http://xmpp.org/extensions/xep-0055.html My request is :

<iq
id="search123"
from="name3@webserv.xxx.com/name3"
to="search.xxx.zzz.com"
type="set" >
<query xmlns="jabber:iq:search" >
    <nick>
android
    </nick>
</query>
</iq>

the response I thought I was getting was/is this:

<iq
id="search123"
from="search.xxx.zzz.com"
to="name3@webserv.telebroad.com/Smack"
type="result" >
</iq>

But using connConfig.setDebuggerEnabled(true); (and an online Telnet Client) I managed to find out that the server IS actually working correctly and it's sending the requested results, but I'm just getting what you see above. I have been at this for 4 days and my self esteem is quite low :P Here is my code concerning the IQ request and response:

Packet asdf = new Packet() {
                    @Override
                    public String toXML() {
                        return    "<iq type='set'"+
                                " from='name3@webserv.xxx.com/name3'"+
                                " to='search.xxx.zzz.com'"+
                                " id='search2'"+
                                " xml:lang='en'>"+
                              " <query xmlns='jabber:iq:search'>"+
                                " <nick>Android</nick>"+
                              " </query>"+
                            " </iq>";
                    }
                };


ChatList.connection.sendPacket(asdf);
                Log.e("packet", "request = "+ asdf.toXML());
                PacketFilter filter = new IQTypeFilter(IQ.Type.RESULT);
                ChatList.connection.addPacketListener(new PacketListener() {
                    public void processPacket(Packet packet) {
                        IQ iq = (IQ)packet;


                        Log.e("response","incoming packet : "+ packet.toXML());
                        Log.e("response","incoming packet2 : "+ packet.toString());

                    }
                }, filter);  

I've tried lots of TypeFilters to no avail. I'm stumped!!

Bottom line:

1.request is being accepted correctly by server;

2.server response is correct(so says the debugger);

3.any response.toString or toXML prints out the type result XML from above(without the actual items after type='result'>.

4.I am about a week overdue on my final build for this app...help! :)


回答1:


Try adding

ProviderManager pm = ProviderManager.getInstance(); 
pm.addIQProvider( "query","jabber:iq:search",new UserSearch.Provider());
pm.addExtensionProvider("x","jabber:x:data", new DataFormProvider());

before establishing connection.




回答2:


This spec is already implemented via the UserSearchManager. Try using that instead.

As for your own case, I would guess that you haven't registered an appropriate provider for this specific element and namespace (like org.jivesoftware.smackx.search.UserSearch$Provider). In a normal Java environment, this would already be registered, but you will have to code it yourself in Android.




回答3:


https://stackoverflow.com/a/14214622/1688731 This...just works!!!! I have no idea why. maybe Iterator iterator = row.getValues("jid"); does the trick. But everything else, I've tried a LOT of times!!



来源:https://stackoverflow.com/questions/13290445/xmpp-iq-result-parsing-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!