1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-26 05:52:06 +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) {
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
// 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
if (info.containsFeature(MultipleAddresses.NAMESPACE)) {
if (info != null && info.containsFeature(MultipleAddresses.NAMESPACE)) {
serviceAddress = serviceName;
}
else {
// Get the disco items and send the disco packet to each server item
DiscoverItems items = sdm.discoverItems(serviceName);
for (DiscoverItems.Item item : items.getItems()) {
try {
info = sdm.discoverInfo(item.getEntityID(), item.getNode());
}
catch (XMPPErrorException|NoResponseException e) {
// Don't throw this exceptions if one of the server's items fail
LOGGER.log(Level.WARNING,
"Exception while discovering info of " + item.getEntityID()
+ " node: " + item.getNode(), e);
continue;
}
if (info.containsFeature(MultipleAddresses.NAMESPACE)) {
serviceAddress = serviceName;
break;
DiscoverItems items;
try {
items = sdm.discoverItems(serviceName);
for (DiscoverItems.Item item : items.getItems()) {
try {
info = sdm.discoverInfo(item.getEntityID(), item.getNode());
}
catch (XMPPErrorException|NoResponseException e) {
// Don't throw this exceptions if one of the server's items fail
LOGGER.log(Level.WARNING,
"Exception while discovering info of " + item.getEntityID()
+ " node: " + item.getNode(), e);
continue;
}
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