- Smack version : 4.3.4
Xml payload I send with “sendStanza” method :
<message to='foo@bar.foobar.com' id='2793eaf8-8b55-4e14-8b9c-e8fc4be2250c' type='groupchat'>
<body></body>
<event xmlns='http://foo.com/protocol/events#card_sent'>
<card xmlns='http://foo.com/protocol/card'>
<title>bar</title>
<text>bar</text>
<image xmlns='http://foo.com/protocol/card_image'>
<url>bar</url>
<description>bar</description>
</image>
<actions xmlns='http://foo.com/protocol/actions'>
<action xmlns='http://foo.com/protocol/action#link'>
<title>bar</title>
<url>bar</url>
</action>
<action xmlns='http://foo.com/protocol/action#link'>
<title>bar</title>
<url>bar</url>
</action>
<action xmlns='http://foo.com/protocol/action#link'>
<title>bar</title>
<url>bar</url>
</action>
<action xmlns='http://foo.com/protocol/action#link'>
<title>bar</title>
<url>bar</url>
</action>
<action xmlns='http://foo.com/protocol/action#link'>
<title>bar</title>
<url>bar</url>
</action>
<action xmlns='http://foo.com/protocol/action#link'>
<title>bar</title>
<url>bar</url>
</action>
</actions>
</card>
</event>
</message>
Xml payload really sent to Xmpp (from log.debug) :
<message to='foo@bar.foobar.com' id='2793eaf8-8b55-4e14-8b9c-e8fc4be2250c' type='groupchat'>
<body></body>
<event xmlns='http://foo.com/protocol/events#card_sent'>
<card xmlns='http://foo.com/protocol/card'>
<title>bar</title>
<text>bar</text>
<image xmlns='http://foo.com/protocol/card_image'>
<url>bar</url>
<description>bar</description>
</image>
<actions xmlns='http://foo.com/protocol/actions'>
<action xmlns='http://foo.com/protocol/action#link'>
<title>bar</title>
<url>bar</url>
</action>
<action>
<title>bar</title>
<url>bar</url>
</action>
<action>
<title>bar</title>
<url>bar</url>
</action>
<action>
<title>bar</title>
<url>bar</url>
</action>
<action>
<title>bar</title>
<url>bar</url>
</action>
<action>
<title>bar</title>
<url>bar</url>
</action>
</actions>
</card>
</event>
</message>
As you can see, the “xmlns” from “actions -> action” are missing (except for the first one that is still present).
- The relevant code parts :
XmlStringBuilder.java :
public void write(Writer writer, String enclosingNamespace) throws IOException {
for (CharSequence csq : sb.getAsList()) {
if (csq instanceof XmlStringBuilder) {
((XmlStringBuilder) csq).write(writer, enclosingNamespace);
}
else if (csq instanceof XmlNsAttribute) {
XmlNsAttribute xmlNsAttribute = (XmlNsAttribute) csq;
if (!xmlNsAttribute.value.equals(enclosingNamespace)) {
writer.write(xmlNsAttribute.toString());
enclosingNamespace = xmlNsAttribute.value;
}
}
else {
writer.write(csq.toString());
}
}
}
I ran the code on debug mode :
When I loop on my “actions -> action” => xmlNsAttribute.equals(enclosingNamespace)
and so, the code writer.write(xmlNsAttribute.toString());
is never executed after the first “action”.
To validate my guess, I went back to the smackVersion=4.2.4. And the payload really sent was equal to the payload I wanted to send (ie : with xmlns still present / Test OK).
Here is the code of the write
method in 4.2.4 :
public void write(Writer writer) throws IOException {
for (CharSequence csq : sb.getAsList()) {
if (csq instanceof XmlStringBuilder) {
((XmlStringBuilder) csq).write(writer);
}
else {
writer.write(csq.toString());
}
}
}