Commit f60e9152 authored by Guus der Kinderen's avatar Guus der Kinderen Committed by Christian Schudt

OF-1087: Do not add empty-string prefixed namespaces

In dom4j, the default namespace of an element cannot be set by adding
a namespace that has an empty-string prefix. Although the string
representation of the element will be correct, that namespace is not
being recognized as the default namespace of the element (instead, it
is a namespace like any other prefixed namespace, to be used in child
elements).
parent e863a946
......@@ -35,6 +35,7 @@ import org.apache.commons.lang.StringEscapeUtils;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.QName;
import org.dom4j.io.XMPPPacketReader;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.net.MXParser;
......@@ -348,8 +349,7 @@ public class HttpBindServlet extends HttpServlet {
}
protected static String createErrorBody(String type, String condition) {
final Element body = DocumentHelper.createElement("body");
body.addNamespace("", "http://jabber.org/protocol/httpbind");
final Element body = DocumentHelper.createElement( QName.get( "body", "http://jabber.org/protocol/httpbind" ) );
body.addAttribute("type", type);
body.addAttribute("condition", condition);
return body.asXML();
......
......@@ -1074,17 +1074,15 @@ public class HttpSession extends LocalClientSession {
protected String createEmptyBody(boolean terminate)
{
final Element body = DocumentHelper.createElement("body");
final Element body = DocumentHelper.createElement( QName.get( "body", "http://jabber.org/protocol/httpbind" ) );
if (terminate) { body.addAttribute("type", "terminate"); }
body.addNamespace("", "http://jabber.org/protocol/httpbind");
body.addAttribute("ack", String.valueOf(getLastAcknowledged()));
return body.asXML();
}
private String createSessionRestartResponse()
{
final Element response = DocumentHelper.createElement("body");
response.addNamespace("", "http://jabber.org/protocol/httpbind");
final Element response = DocumentHelper.createElement( QName.get( "body", "http://jabber.org/protocol/httpbind" ) );
response.addNamespace("stream", "http://etherx.jabber.org/streams");
final Element features = response.addElement("stream:features");
......
......@@ -317,8 +317,7 @@ public class HttpSessionManager {
}
private static String createSessionCreationResponse(HttpSession session) throws DocumentException {
Element response = DocumentHelper.createElement("body");
response.addNamespace("", "http://jabber.org/protocol/httpbind");
Element response = DocumentHelper.createElement( QName.get( "body", "http://jabber.org/protocol/httpbind" ) );
response.addNamespace("stream", "http://etherx.jabber.org/streams");
response.addAttribute("from", session.getServerName());
response.addAttribute("authid", session.getStreamID().getID());
......
......@@ -5,6 +5,7 @@ import java.util.TimerTask;
import org.dom4j.Attribute;
import org.dom4j.Element;
import org.dom4j.QName;
import org.dom4j.tree.DefaultAttribute;
import org.dom4j.tree.DefaultElement;
import org.jivesoftware.openfire.interceptor.InterceptorManager;
......@@ -86,8 +87,7 @@ public class DiscoIQRegisteredProcessor extends AbstractRemoteRosterProcessor {
askComponent.setTo(to);
askComponent.setFrom(from);
askComponent.setType(IQ.Type.get);
Element query = new DefaultElement("query");
query.addNamespace("", "jabber:iq:register");
Element query = new DefaultElement( QName.get( "query", "jabber:iq:register" ) );
askComponent.setChildElement(query);
// Remove the package intercepter in 1sec
......
......@@ -8,6 +8,7 @@ import java.util.TimerTask;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.QName;
import org.dom4j.tree.DefaultAttribute;
import org.dom4j.tree.DefaultElement;
import org.jivesoftware.openfire.SharedGroupException;
......@@ -76,7 +77,7 @@ public class IQRosterPayloadProcessor extends AbstractRemoteRosterProcessor {
IQ response = IQ.createResultIQ(requestPacket);
response.setTo(subdomain);
Element query = new DefaultElement("query");
Element query = new DefaultElement( QName.get("query","jabber:iq:roster"));
for (RosterItem i : items) {
String jid = i.getJid().toString();
if (!jid.equals(subdomain) && jid.contains(subdomain)) {
......@@ -93,8 +94,6 @@ public class IQRosterPayloadProcessor extends AbstractRemoteRosterProcessor {
query.add(item);
}
}
query.addNamespace("", "jabber:iq:roster");
response.setChildElement(query);
dispatchPacket(response);
}
......@@ -103,8 +102,7 @@ public class IQRosterPayloadProcessor extends AbstractRemoteRosterProcessor {
IQ iq = (IQ) requestPacket;
IQ response = IQ.createResultIQ(iq);
response.setTo(subdomain);
Element query = new DefaultElement("query");
query.addNamespace("", "jabber:iq:roster");
Element query = new DefaultElement( QName.get("query","jabber:iq:roster") );
response.setChildElement(query);
dispatchPacket(response);
}
......
......@@ -268,8 +268,7 @@ public class RegistrationHandler implements ChannelHandler<IQ> {
}
// Add special indicator for rosterless gateway handling.
response.addElement("x")
.addNamespace("", NameSpace.IQ_GATEWAY_REGISTER);
response.addElement( QName.get( "x", NameSpace.IQ_GATEWAY_REGISTER) );
result.setChildElement(response);
......
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