1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 20:12:07 +01:00

Make getMultipleRecipientServiceAddress more robust

to avoid

feature-not-implemented
	at org.jivesoftware.smack.PacketCollector.nextResultOrThrow(PacketCollector.java:182)
	at org.jivesoftware.smack.PacketCollector.nextResultOrThrow(PacketCollector.java:161)
	at org.jivesoftware.smackx.disco.ServiceDiscoveryManager.discoverItems(ServiceDiscoveryManager.java:573)
	at org.jivesoftware.smackx.address.MultipleRecipientManager.getMultipleRecipienServiceAddress(MultipleRecipientManager.java:310)
 	at org.jivesoftware.smackx.address.MultipleRecipientManager.send$7a184d34(MultipleRecipientManager.java:82)

for e.g. Google Apps XMPP services.

This is not to be merged in master/4.1 branch as it already contains a
similar fix.
This commit is contained in:
Florian Schmaus 2014-08-10 17:16:08 +02:00
parent c3f6c51d0e
commit 0d890623c7

View file

@ -300,29 +300,39 @@ public class MultipleRecipientManager {
if (serviceAddress == null) { if (serviceAddress == null) {
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection); ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
// Send the disco packet to the server itself // Send the disco packet to the server itself
DiscoverInfo info = sdm.discoverInfo(serviceName); DiscoverInfo info = null;
try {
info = sdm.discoverInfo(serviceName);
} catch (XMPPErrorException e) {
LOGGER.log(Level.WARNING, "Exception while discovering info of service", e);
}
// Check if the server supports XEP-33 // Check if the server supports XEP-33
if (info.containsFeature(MultipleAddresses.NAMESPACE)) { if (info != null && info.containsFeature(MultipleAddresses.NAMESPACE)) {
serviceAddress = serviceName; serviceAddress = serviceName;
} }
else { else {
// 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 = sdm.discoverItems(serviceName); DiscoverItems items;
for (DiscoverItems.Item item : items.getItems()) { try {
try { items = sdm.discoverItems(serviceName);
info = sdm.discoverInfo(item.getEntityID(), item.getNode()); for (DiscoverItems.Item item : items.getItems()) {
} try {
catch (XMPPErrorException|NoResponseException e) { info = sdm.discoverInfo(item.getEntityID(), item.getNode());
// Don't throw this exceptions if one of the server's items fail }
LOGGER.log(Level.WARNING, catch (XMPPErrorException|NoResponseException e) {
"Exception while discovering info of " + item.getEntityID() // Don't throw this exceptions if one of the server's items fail
+ " node: " + item.getNode(), e); LOGGER.log(Level.WARNING,
continue; "Exception while discovering info of " + item.getEntityID()
} + " node: " + item.getNode(), e);
if (info.containsFeature(MultipleAddresses.NAMESPACE)) { continue;
serviceAddress = serviceName; }
break; if (info.containsFeature(MultipleAddresses.NAMESPACE)) {
serviceAddress = serviceName;
break;
}
} }
} catch (XMPPErrorException e) {
LOGGER.log(Level.WARNING, "Exception while disvering items of service", e);
} }
} }
// Use the empty string to indicate that no service is known for this connection // Use the empty string to indicate that no service is known for this connection