powered by Jive Software

Error packet handling

Hi, Matt.

I have the problem with handling packets in the next code:

connection.sendPacket(packet);
PacketFilter filter = new AndFilter(
    new PacketIDFilter(packet.getPacketID()),
    new PacketTypeFilter(IQ.class)
);
PacketCollector collector = connection.createPacketCollector(filter);
IQ result = (IQ)collector.nextResult(waitTime);
collector.cancel();
// in this point I have (result == null)
// and connection is closed !!!!!

Debug window snapshort:

MY SEND:
<iq id="fzx77-5" to="jabber.ru" from="fatenext@jabber.ru/Smack" type="get">
  <item xmlns="jabber:iq:agents"/>
</iq> RECV:
<iq from=''jabber.ru'' to=''fatenext@jabber.ru/Smack'' type=''error'' id=''fzx77-5''>
  <item xmlns=''jabber:iq:agents''/>
  <error code=''501'' type=''cancel''>
    <feature-not-implemented xmlns=''urn:ietf:params:xml:ns:xmpp-stanzas''/>
  </error>
</iq> Smack SEND:
<presence id="fzx77-6" type="unavailable"></presence>
</stream:stream>

I look Smack sources but not found why Smack close connection

Thanks,

Oleg

Oleg,

If an exception occurs while parsing the received XML then the connection will be closed. When this happens all the ConnectionListeners of the connection are notified of the exception.

You can try to add a ConnectionListener to the connection in order to find out which is the exception. Please let us know if it’'s a parsing problem so that we can solve the issue.

Thanks,

– Gato

Gato,

I attached a ConnectionListener before

IQ result = (IQ)collector.nextResult(waitTime);

and print stack in

public void connectionClosedOnError (Exception exc)
    {
        exc.printStackTrace();
    }

result:

org.xmlpull.v1.XmlPullParserException: parser must be on START_TAG or TEXT to read text (position: START_TAG seen ...ture-not-implemented xmlns=\''urn:ietf:params:xml:ns:xmpp-stanzas\''/>... @1:1876)
at org.xmlpull.mxp1.MXParser.nextText(MXParser.java:1115)
at org.jivesoftware.smack.PacketReader.parseError(PacketReader.java:611)
at org.jivesoftware.smack.PacketReader.parseIQ(PacketReader.java:378)
at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:277)
at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:77)
at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:103)

Oleg

Oleg,

Thanks for the bug report. I made a fix and in the next couple of days it will be available in the daily updates section.

Thanks,

– Gato