YamingPeng100 / asmack

Automatically exported from code.google.com/p/asmack
Other
0 stars 0 forks source link

Problem with IQ providers #4

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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(PacketParse
rUtils.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!

Original issue reported on code.google.com by lmini...@gmail.com on 15 Mar 2010 at 12:43

GoogleCodeExporter commented 9 years ago
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é

Original comment by rtreffer@gmail.com on 15 Mar 2010 at 12:53

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

Original comment by lmini...@gmail.com on 15 Mar 2010 at 2:43

GoogleCodeExporter commented 9 years ago
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).

Original comment by rtreffer@gmail.com on 15 Mar 2010 at 3:08

GoogleCodeExporter commented 9 years ago
someone else spotted the problem:
http://github.com/rtreffer/asmack/commit/f564bde06dbabe2ad76afe9c6f9886bf02fefd3
c

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

TIA,
  Rene

Original comment by rtreffer@gmail.com on 3 May 2010 at 9:03

GoogleCodeExporter commented 9 years ago
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 :)

Original comment by lmini...@gmail.com on 4 May 2010 at 10:59

GoogleCodeExporter commented 9 years ago
you're should thank koterpiller, reporter of issue 10, who  spotted the root of 
the
problem :-)

Problem solved, issue closed :-)

Original comment by rtreffer@gmail.com on 4 May 2010 at 11:17