AnsweredAssumed Answered

Trying to write a smack IQProvider that parses an IQ Error stanza with sender XML

Question asked by Greg Thomas on Nov 19, 2015
Latest reply on Nov 20, 2015 by Greg Thomas

I'm using smack 4.1.4, and I'm having trouble parsing an IQ Error stanza.


According to the spec @ Extensible Messaging and Presence Protocol (XMPP): Core an error stanza is of the form ...


<stanza-kind to='sender' type='error'>

  [RECOMMENDED to include sender XML here]

  <error type='error-type'>

    <defined-condition xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>

    <text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas' xml:lang='langcode'>

      OPTIONAL descriptive text


    [OPTIONAL application-specific condition element]




So, I've got two packets which may look something like ...


A standard result IQ stanza looks something like ...

<iq to="someone" from="sender" type="result">

  <command xmlns="" node="http://my-custom-node" status="completed">

  ... rest of result XML ...


<error ...





Whilst an error IQ stanza looks very similar (as it includes the sender XML)

<iq to="someone" from="sender" type="error">

   <command xmlns="" node="http://my-custom-node" status="completed">

   ... rest of sender XML ...


  <error ...




And I can't work out how to write a IQProvider for it. My problem is that there's no way in advance of knowing if it's an error or result IQ; the IQProvider class that I'm extending doesn't give me access to the parent <iq> element, so I can't check the IQ type attribute. If I read the next item after the end of the command tag to see if it's an <error>, then for the result IQ stanza I've just pulled the </iq> item and the Provider.parse() blows up when it calls ParserUtils.forwardToEndTagOfDepth(...) as we've gone too far already.

I'm sure it must be possible to properly parse an error IQ of this style, but I can't figure out - can someone point me in the right direction?