From 19ebcb814bba3f0d57259e480408f45712b8e98e Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 17 Jul 2015 09:07:29 +0200 Subject: [PATCH] Check that service is MUC service in getHostedRooms() and otherwhise throw a NotAMucServiceException. --- .../jivesoftware/smackx/muc/MultiUserChatException.java | 8 +++++++- .../org/jivesoftware/smackx/muc/MultiUserChatManager.java | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatException.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatException.java index 2e1502a3e..dbf9c277f 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatException.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatException.java @@ -17,6 +17,7 @@ package org.jivesoftware.smackx.muc; import org.jivesoftware.smack.SmackException; +import org.jxmpp.jid.DomainBareJid; public abstract class MultiUserChatException extends SmackException { @@ -96,7 +97,12 @@ public abstract class MultiUserChatException extends SmackException { */ private static final long serialVersionUID = 1L; - public NotAMucServiceException(MultiUserChat multiUserChat) { + NotAMucServiceException(DomainBareJid service) { + super("Can't perform operation because " + service + + " does not provide a MUC (XEP-45) service."); + } + + NotAMucServiceException(MultiUserChat multiUserChat) { super("Can not join '" + multiUserChat.getRoom() + "', because '" + multiUserChat.getRoom().asDomainBareJid() + "' does not provide a MUC (XEP-45) service."); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java index 0cdbc03b0..b09a13ba1 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java @@ -48,6 +48,7 @@ import org.jivesoftware.smackx.disco.AbstractNodeInformationProvider; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.disco.packet.DiscoverInfo; import org.jivesoftware.smackx.disco.packet.DiscoverItems; +import org.jivesoftware.smackx.muc.MultiUserChatException.NotAMucServiceException; import org.jivesoftware.smackx.muc.packet.MUCInitialPresence; import org.jivesoftware.smackx.muc.packet.MUCUser; import org.jxmpp.jid.EntityBareJid; @@ -290,9 +291,13 @@ public final class MultiUserChatManager extends Manager { * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException + * @throws NotAMucServiceException */ public List getHostedRooms(DomainBareJid serviceName) throws NoResponseException, XMPPErrorException, - NotConnectedException, InterruptedException { + NotConnectedException, InterruptedException, NotAMucServiceException { + if (!providesMucService(serviceName)) { + throw new NotAMucServiceException(serviceName); + } ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection()); DiscoverItems discoverItems = discoManager.discoverItems(serviceName); List items = discoverItems.getItems();