PubSub implementation broken in 4.0.3

Hi,

I wanted to upgrade to the latest version of the smack library (4.0.3, currently using 3.2.1) but noticed that a bug was introduced in the new version that broke my regression tests. I use the pubsub mechanisms for machine-to-machine communication and exchange XML data using the PubSub mechanism. The XML naturally contains a lot of namespace declarations that are vital for parsing the content at the receiver (subscriber).

Previously, this worked fine, but the new version does something strange with the namespaces in the published item. Instead of passing the content of the item as it was published, the library seems to remove all but one namespace from my XML data. So the my ItemEventListener implementation gets items with invalid XML code which cannot further be processed.

Are there any workarounds to get the items as they were published out of the smack library?

Best Regards,

Ingo

Could you elaborate that a bit with examples? Or even better, present a code snippet that produces the bug. Which item class do you use?

OTOH I’m pretty sure that it’s caused by parseContentDepth, still a example producing the problem would be helpful for developing and testing the fix.

Allright, I’ve created a commit with a supposed solution/workaround. The problem is that if we use XmlPullParser.getNamespace() on elements that don’t define a namespace, then the parser will report the namespace of the outer element (which is not wrong, just sometime not required).

For example

some text

will become

some text

Smack’s PubSub ItemProvider does now use this approach. I’ve uploaded new 4.0.4-SNAPSHOTS to Sonatype. Since your problem description leaves room for interpretation, I’m not sure if I tried to fix the issue you are talking about. Please let me know if the 4.0.4-SNAPSHOTS solve the issue for you. Logged as SMACK-601.

Hi,

The initial issue was when publishing the following item on a PubSub node

<ns1:outer xmlns:ns1=“foo” xmlns:ns2=“bar”>ns2:inner/</ns1:outer>

I got the following when calling item.toXML() in my handlePublishedItems method…

…which is obviously wrong. I checked it with the 4.0.4-SNAPSHOT and it works now

Both XML fragments are semantically the same but I wonder why the library does not provide the content of the item as-it-is.

Thanks,

Ingo

I wonder why the library does not provide the content of the item as-it-is.
Basically because the xml-roundtrip feature of XmlPullParser is not available on Android and Smack tries to stay Android compatible. xml-roundtrip makes getText() return the full tag text when the parser in on START_TAG and END_TAG. Whithout this feature, we can only create the payload by parsing every tag and inspecting its attributes and namespace declarations. This introduces the mentioned effects when parsing XML of unkown structure, which is done very rarely when it comes to XMPP, but PubSub PayloadItem is a noteable exception.

BTW Smack is modular, you can always easily replace ItemProvider by your own implementation. To create a SimplePayload class which payload equals the input.

As with the current implementation, the prefix is lost, but it seems that it’s ok for you.

I’m getting something very similar with IQs currently…

When sending a custom IQ from my service:

<username>bot_plzxls@seattle1.adspore.com</username>

foo@foo.bar

-334015840129932217

true

When receiving via Smack 4:

<iq id=‘Avpxd-21’ to=‘bot_plzxls@seattle1.adspore.com/Smack’

from=‘lighthouse.seattle1.adspore.com

type=‘result’>true

Note that it’s chopping out everything except the text and closing tag on the IQ’s child element.

Please open a new thread for a different problem and provide more details. The IQ stanza does look like a custom one. It doesn’t look similar, more like a faulty parser implementation. How is it parsed? How does the class look like?