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