Export to GitHub

asmack - issue #4

Problem with IQ providers


Posted on Mar 15, 2010 by Swift Rabbit

I've found out a potential issue with IQ providers.

I'm developing an Android application that makes use of the Smack API for its XMPP functionality. It uses some custom IQs for its features.

I've created a class for a custom IQ, following the usual guidelines. The class extends IQ and implements IQProvider, and for all its variables it has public setters and getters.

In the code, the provider is correctly registered by calling addIQProvider at the ProviderManager instance.

That said, I could send an empty message associated with the IQ; but got an exception when receiving a reply:

W/System.err( 211): java.lang.NoSuchMethodException: getFocus W/System.err( 211): at java.lang.ClassCache.findMethodByName(ClassCache.java:308) W/System.err( 211): at java.lang.Class.getMethod(Class.java:1007) W/System.err( 211): at org.jivesoftware.smack.util.PacketParserUtils.parseWithIntrospection(PacketParserUtils.java:787) W/System.err( 211): at org.jivesoftware.smack.util.PacketParserUtils.parseIQ(PacketParserUtils.java:270) W/System.err( 211): at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:229) W/System.err( 211): at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:43) W/System.err( 211): at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:70)

where focus is one of the variables of the IQ (the first variable to appear in the class). This exception usually appears when an IQ implementation is missing an element found in a received packet, but this is not the case, since the setter and getter for that variable are there.

The same code works fine in a standard Java application, using the normal Smack library. Is this a known issue with the Android port? May this be related to something that has been fixed in subsequent versions of Smack, or to any difference in the base Java classes the Android APIs may have introduced?

Thanks in advance!

Comment #1

Posted on Mar 15, 2010 by Grumpy Rhino

Yes, I can confirm that org.jivesoftware.smack.util.PacketParserUtils.parseWithIntrospection needed to be rewritten.

http://github.com/rtreffer/smack/blob/master/source/org/jivesoftware/smack/util/PacketParserUtils.java#L778

Please enable debugging (as usual), provide an XML dump (remove the SASL / base64 text) and show off the code :-) I've not yet used parseWithIntrospection (and it's just a basic fix, android doesn't support java bean introspection).

I've already an idea, is the method inherited? I might have to check the full chain for a getFocus method....

Regards, René

Comment #2

Posted on Mar 15, 2010 by Swift Rabbit

I didn't know about the missing Java bean support! That explains it, then... How can I enable debug?

Comment #3

Posted on Mar 15, 2010 by Grumpy Rhino

Well, I've create a drop in replacement, but I'm not sure if it works for object hierarchies :-)

Anyway, you need set DEBUG=true on (XMPP|BOSH|)Connection. Or use the config. It's the first thing to enable ;-) Be aware that this will dump your credentials, so remove the SASL packages (or at least the base64 content).

Comment #4

Posted on May 3, 2010 by Grumpy Rhino

someone else spotted the problem: http://github.com/rtreffer/asmack/commit/f564bde06dbabe2ad76afe9c6f9886bf02fefd3c

object.getClass().getClass().getMethod(...) is nonsense, stripped one getClass, could you please retry?

TIA, Rene

Comment #5

Posted on May 4, 2010 by Swift Rabbit

Hi René,

I just tried and it works great, well done!

In the meanwhile I had solved using the alternative way of implementing IQs, that is passing a new instance to addIQProvider, and then implementing the actual parsing and building in the IQ class itself (which is what is needed whenever non-flat XML in IQs is used anyway).

Of course this makes life much easier, thanks :)

Comment #6

Posted on May 4, 2010 by Grumpy Rhino

you're should thank koterpiller, reporter of issue 10, who spotted the root of the problem :-)

Problem solved, issue closed :-)

Status: Verified

Labels:
Type-Defect Priority-Medium