powered by Jive Software

Raw packet data vs. Packet.toXML()

Hoping someone can help me with this.

I have created a client which is using PacketListener to receive messages. When I print out what I am receiving using Packet.toXML(), I can see that I am missing data. I have run the debugger, and when I look at the raw packets that I am receiving, all of the data is there.

Anyone know why data would be missing or how I can get at it?

Thanks.

Some additional info…

The packet is being sent via a third party, so I don’t have control over what is being sent. I am connecting to gtalk to receive messages. I can see from the Smack debugger that the raw packet is coming in with this format:

<message from="aaa@abc.com" to="bbb@gmail.com" type=“chat” id=“tag:abc.com:5234247”>

<body> some text here </body>

 &lt;entry xmlns="http://www.w3.org/2005/Atom"&gt;

<source>

<title> some text here </title>

      &lt;link href="http://lalala.com/abc"/&gt;

      &lt;link href="http://lalala.com/abc.atom" rel="self" type="application/atom+xml"/&gt;

<author>

<name> some text here </name>

</author>

      &lt;icon&gt;http://lalala/com/avatar_normal.jpg</icon>

</source>

<title> some text here </title>

<summary> some text here </summary>

  &lt;link href="http://lalala.com" rel="alternate" type="text/html"/&gt;

<id>tag:abc.com,2008-01-11T16:19:19+00:00:/lalala/588086852</id>

<published>2008-01-11T16:19:19+00:00</published>

<updated>2008-01-11T16:19:19+00:00</updated>

</entry>

&lt;event xmlns="http://jabber.org/protocol/pubsub#event"&gt;

&lt;items node="http://abc.com/statuses/timeline" xmlns="http://jabber.org/protocol/pubsub"&gt;

<item id=“tag:abc.com,2008-01-11T16:19:19+00:00:/statuses/588086852”/></items&g t;

</event>

</message>

When I print out the packet.toXml(), I get this:

<message id=“tag:abc.com:5111369” to="bbb@gmail.com" from="aaa@abc.com" type=“chat”>

<body> some text here </body>

<entry xmlns=“http://www.w3.org/2005/Atom”>

<summary> some text here </summary>

<title> some text here </title>

  &lt;icon&gt;http://lalala/com/avatar_normal.gif</icon>

<published>2008-01-14T17:22:13+00:00</published>

<link></link>

<source></source>

<name> some text here </name>

<updated>2008-01-14T17:22:13+00:00</updated>

<author></author>

<id>tag:abc.com,2008-01-14T17:22:13+00:00:/statuses/598312662</id>

</entry>

<event xmlns=“http://jabber.org/protocol/pubsub#event”>

</event>

</message>

In the received packet, it seems that the order of the elements has been rearranged, and some of the fields (link, source, author) do not contain values.

Is this a case that requires a PacketExtension implementation? How do I handle this when I am not the one sending the data? Or is there some other reason that I am not receiving the packet as it is sent out?

If anyone can help, I’d really appreciate it!

You need to process all the data that is in the packet and output it back with packet.toXML() if you want all the data to be there.

Thank you, I appreciate the answer but perhaps I didn’t explain my problem well enough.

How do I get all of the data? That is my issue. I’m not seeing any way to get it from the packet.

Thanks.

Did you manage to find a solution for this? I’ve just hit the exact same problem, thinking it was initially a problem with gtalk sending corrupt messages I tried via OpenFire and see the same thing.

Following my nose through the source code I think I’m seeing the problem being rooted in PacketParserUtils#parsePacketExtension() when using the default packet extension.

So far I’m just reading through the code via FishEye but about to download the source and see whats going on.

No, I have not yet found an answer. I got side-tracked by some other work, and I’m just now getting back to this. If you find a solution please let me know. I’d really appreciate some help with this.

It looks like the default package extension handler only works with simple XML, i.e. I found that if my extension was only one node deep everything worked fine:

<message>

<mystuff>

<foo>bar</foo>

<bar>foo</bar>

</mystuff>

</message>

With anything more complex the parser gets confused and returns odd data (understandable). This is only a problem when theres no custom PacketExtensionProvider registered for your particular element/namespace. I’ve not tried it yet (thats Monday mornings first exercise) but it looks like you just need to add your own provider via:

http://www.igniterealtime.org/builds/smack/docs/latest/javadoc/org/jivesoftware/ smack/provider/ProviderManager.html#addExtensionProvider(java.lang.String,%20jav a.lang.String,%20java.lang.Object)

Which looks simple enough to implement.

Mark