1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 14:22:05 +01:00

Make ServiceDiscoveryManager.findServices() more robust

the method should not throw an exception if the discovery of the service
fails.
This commit is contained in:
Florian Schmaus 2014-08-08 15:12:23 +02:00
parent 0ed68cc18f
commit a5eebf3840

View file

@ -716,7 +716,14 @@ public class ServiceDiscoveryManager extends Manager {
} }
serviceAddresses = new LinkedList<String>(); serviceAddresses = new LinkedList<String>();
// Send the disco packet to the server itself // Send the disco packet to the server itself
DiscoverInfo info = discoverInfo(serviceName); DiscoverInfo info;
try {
info = discoverInfo(serviceName);
} catch (XMPPErrorException e) {
// Be extra robust here: Return the empty linked list and log this situation
LOGGER.log(Level.WARNING, "Could not discover information about service", e);
return serviceAddresses;
}
// Check if the server supports XEP-33 // Check if the server supports XEP-33
if (info.containsFeature(feature)) { if (info.containsFeature(feature)) {
serviceAddresses.add(serviceName); serviceAddresses.add(serviceName);
@ -728,8 +735,14 @@ public class ServiceDiscoveryManager extends Manager {
return serviceAddresses; return serviceAddresses;
} }
} }
DiscoverItems items;
try {
// Get the disco items and send the disco packet to each server item // Get the disco items and send the disco packet to each server item
DiscoverItems items = discoverItems(serviceName); items = discoverItems(serviceName);
} catch(XMPPErrorException e) {
LOGGER.log(Level.WARNING, "Could not discover items about service", e);
return serviceAddresses;
}
for (DiscoverItems.Item item : items.getItems()) { for (DiscoverItems.Item item : items.getItems()) {
try { try {
// TODO is it OK here in all cases to query without the node attribute? // TODO is it OK here in all cases to query without the node attribute?