Commit 60141ddf authored by Christian Schudt's avatar Christian Schudt

OF-803 Message Carbons may throw org.dom4j.IllegalAddException, resulting in disconnection

parent 6e102ccf
......@@ -12,15 +12,16 @@ public class Forwarded extends PacketExtension {
public Forwarded(Message message) {
super("forwarded", "urn:xmpp:forward:0");
message.getElement().setQName(QName.get("message", "jabber:client"));
Message copy = message.createCopy();
for (Object element : message.getElement().elements()) {
copy.getElement().setQName(QName.get("message", "jabber:client"));
for (Object element : copy.getElement().elements()) {
if (element instanceof Element) {
Element el = (Element) element;
el.setQName(QName.get(el.getName(), "jabber:client"));
}
}
element.add(message.getElement());
element.add(copy.getElement());
}
}
......@@ -17,7 +17,10 @@ public class ForwardTest {
message.setBody("Tests");
Forwarded forwarded = new Forwarded(message);
String xml = forwarded.getElement().asXML();
assertEquals("<forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body></message></forwarded>", xml);
Forwarded forwarded2 = new Forwarded(message);
String xml1 = forwarded.getElement().asXML();
String xml2 = forwarded2.getElement().asXML();
assertEquals("<forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body></message></forwarded>", xml1);
assertEquals("<forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body></message></forwarded>", xml2);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment