Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(a)Smack's IQ.toXml() returns XML without custom child elements

I'm using asmack the latest version (asmack-android-8-source-0.8.3) in a android project and I have the following code:

connection.addPacketListener(new PacketListener()
{
    @Override
    public void processPacket(Packet p)
    {
        if(p.getPacketID().equals("v3"))
        {
            Log.e("TAG", p.toXML());
        }
    }
}, new IQTypeFilter(IQ.Type.RESULT));


Packet iq = new Packet() 
{
    @Override
    public String toXML() 
    {
        String str = "<iq type='get' id='v3'><getservertime xmlns='urn:xmpp:mrpresence'/></iq>";
        Log.e("TAG", str);
        return str;
    }
};

//sends <iq type='get' id='v3'><getservertime xmlns='urn:xmpp:mrpresence'/></iq>
connection.sendPacket(iq);

in the debugger the response it's ok and this is expected:

<iq type="result" id="v3" to="minimaal@mrserver/Smack">
    <servertime xmlns="urn:xmpp:mrpresence" utc="2013-06-28T11:45:32.380Z" local="2013-06-28T07:45:32.380Z"/>
</iq>

but p.toXML() in the package listner, the tag "servertime" it's missing:

<iq id="v3" to="minimaal@mrserver/Smack" type="result"></iq>

Any suggestions on what I'm doing wrong?

like image 791
Goran Horia Mihail Avatar asked Jun 28 '13 12:06

Goran Horia Mihail


1 Answers

<servertime/> is a custom child element, which is not known to Smack. It is simply ignored when parsing the stanza. You need to make Smack aware of the element, by creating a new PacketExtension which needs to get registered with the ProviderManager.

You can read more about it in Smack's documentation about the Provider Architecture.

like image 90
Flow Avatar answered Sep 28 '22 04:09

Flow