sendToRemoteServer(domain, multicastService);
}
else {
if (isRoot && IQ.Type.error != packet.getType()) {
// Discover node items with the hope that a sub-item supports JEP-33
IQ iq = new IQ(IQ.Type.get);
iq.setFrom(server.getServerInfo().getXMPPDomain());
iq.setTo(packet.getFrom());
iq.setChildElement("query", "http://jabber.org/protocol/disco#items");
// Send the disco#items request to the remote server or component. The reply will be
// processed by the IQResultListener (interface that this class implements)
iqRouter.addIQResultListener(iq.getID(), this);
iqRouter.route(iq);
}
else if (!isRoot) {
// Process the disco#info response of an item that does not support JEP-33
roots.remove(packet.getFrom().toString());
Collection<String> items = nodes.get(domain);
if (items != null) {
items.remove(packet.getFrom().toString());
if (items.isEmpty()) {
nodes.remove(domain);
cache.put(domain, "");
sendToRemoteServer(domain, "");
}
}
}
else {
// Root domain does not support disco#info
nodes.remove(domain);
cache.put(domain, "");
sendToRemoteServer(domain, "");
}
}
}
else {
// This is a disco#items response
Collection<Element> items = packet.getChildElement().elements("item");
if (IQ.Type.error == packet.getType() || items.isEmpty()) {
// Root domain does not support disco#items
nodes.remove(domain);
cache.put(domain, "");
sendToRemoteServer(domain, "");
}
else {
// Keep the list of items found in the requested domain
List<String> jids = new ArrayList<String>();
for (Element item : items) {
String jid = item.attributeValue("jid");
jids.add(jid);
// Add that this item was found for the following domain
roots.put(jid, domain);
}
nodes.put(domain, new CopyOnWriteArrayList<String>(jids));
// Send disco#info to each discovered item
for (Element item : items) {
// Discover if remote server supports JEP-33 (Extended Stanza Addressing)
IQ iq = new IQ(IQ.Type.get);
iq.setFrom(server.getServerInfo().getXMPPDomain());
iq.setTo(item.attributeValue("jid"));
Element child = iq.setChildElement("query", "http://jabber.org/protocol/disco#info");
if (item.attributeValue("node") != null) {
child.addAttribute("node", item.attributeValue("node"));
}
// Send the disco#info request to the discovered item. The reply will be
// processed by the IQResultListener (interface that this class implements)
iqRouter.addIQResultListener(iq.getID(), this);
iqRouter.route(iq);
}
}
}
}