diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/IQ.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/IQ.java index 92ef0a964..09fa9178e 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/IQ.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/IQ.java @@ -137,7 +137,7 @@ public abstract class IQ extends Stanza { buf.attribute("type", type.toString()); } buf.rightAngleBracket(); - buf.append(getChildElementXML()); + buf.append(getChildElementXML(enclosingNamespace)); buf.closeElement(IQ_ELEMENT); return buf; } @@ -149,10 +149,22 @@ public abstract class IQ extends Stanza { * @return the child element section of the IQ XML. */ public final XmlStringBuilder getChildElementXML() { + return getChildElementXML(null); + } + + /** + * Returns the sub-element XML section of the IQ packet, or the empty String if there + * isn't one. + * + * @param enclosingNamespace the enclosing XML namespace. + * @return the child element section of the IQ XML. + * @since 4.3.0 + */ + public final XmlStringBuilder getChildElementXML(String enclosingNamespace) { XmlStringBuilder xml = new XmlStringBuilder(); if (type == Type.error) { // Add the error sub-packet, if there is one. - appendErrorIfExists(xml); + appendErrorIfExists(xml, enclosingNamespace); } else if (childElementName != null) { // Add the query section if there is one. diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java index cb87251c7..ee22034c5 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java @@ -501,7 +501,7 @@ public final class Message extends Stanza implements TypedCloneable { buf.optElement("thread", thread); // Append the error subpacket if the message type is an error. if (type == Type.error) { - appendErrorIfExists(buf); + appendErrorIfExists(buf, enclosingNamespace); } // Add extension elements, if any are defined. diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java index abf4e39c5..99a0b8ae1 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java @@ -292,7 +292,7 @@ public final class Presence extends Stanza implements TypedCloneable { buf.append(getExtensions(), enclosingNamespace); // Add the error sub-packet, if there is one. - appendErrorIfExists(buf); + appendErrorIfExists(buf, enclosingNamespace); buf.closeElement(ELEMENT); diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/Stanza.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/Stanza.java index 2dff229ab..e9c9072fa 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/Stanza.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/Stanza.java @@ -541,10 +541,10 @@ public abstract class Stanza implements TopLevelStreamElement { * * @param xml the XmlStringBuilder to append the error to. */ - protected void appendErrorIfExists(XmlStringBuilder xml) { + protected void appendErrorIfExists(XmlStringBuilder xml, String enclosingNamespace) { StanzaError error = getError(); if (error != null) { - xml.append(error.toXML()); + xml.append(error.toXML(enclosingNamespace)); } } }