From aab48570c91a145bef60b25e6b3c70fd0dbdeedd Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Tue, 11 May 2021 22:03:24 +0200 Subject: [PATCH] Call XMPPConnection.sendIqRequestAndWaitForResponse(IQ) where possible Refactored using find . -type f -name "*.java" |\ xargs sed -i -E |\ 's/\.createStanzaCollectorAndSend\((\w+)\)\.nextResultOrThrow\(\);/.sendIqRequestAndWaitForResponse(\1);/' and some manual refactoring. --- .../smackx/carbons/CarbonManager.java | 2 +- .../httpfileupload/HttpFileUploadManager.java | 2 +- .../smackx/iot/control/IoTControlManager.java | 2 +- .../smackx/iot/data/IoTDataManager.java | 2 +- .../iot/discovery/IoTDiscoveryManager.java | 10 +++--- .../provisioning/IoTProvisioningManager.java | 2 +- .../jivesoftware/smackx/mam/MamManager.java | 4 +-- .../smackx/muclight/MultiUserChatLight.java | 20 +++++------ .../muclight/MultiUserChatLightManager.java | 8 ++--- .../PushNotificationsManager.java | 2 +- .../blocking/BlockingCommandManager.java | 8 ++--- .../jivesoftware/smackx/bob/BoBManager.java | 2 +- .../ibb/InBandBytestreamManager.java | 2 +- .../ibb/InBandBytestreamSession.java | 4 +-- .../socks5/Socks5BytestreamManager.java | 4 +-- .../socks5/Socks5ClientForInitiator.java | 2 +- .../smackx/commands/RemoteCommand.java | 2 +- .../smackx/disco/ServiceDiscoveryManager.java | 4 +-- .../smackx/iqlast/LastActivityManager.java | 2 +- .../smackx/iqprivate/PrivateDataManager.java | 6 ++-- .../smackx/iqversion/VersionManager.java | 2 +- .../smackx/jingle/JingleUtil.java | 32 ++++++++--------- .../jingle_s5b/JingleS5BTransportManager.java | 2 +- .../jingle_s5b/JingleS5BTransportSession.java | 8 ++--- .../smackx/muc/MultiUserChat.java | 22 ++++++------ .../smackx/offline/OfflineMessageManager.java | 6 ++-- .../smackx/privacy/PrivacyListManager.java | 4 +-- .../jivesoftware/smackx/pubsub/LeafNode.java | 12 +++---- .../org/jivesoftware/smackx/pubsub/Node.java | 4 +-- .../smackx/pubsub/PubSubManager.java | 6 ++-- .../smackx/search/UserSearch.java | 6 ++-- .../sharedgroups/SharedGroupManager.java | 2 +- .../smackx/time/EntityTimeManager.java | 2 +- .../smackx/vcardtemp/VCardManager.java | 4 +-- .../jivesoftware/util/ConnectionUtils.java | 11 ++++++ .../org/jivesoftware/smack/roster/Roster.java | 4 +-- .../smack/roster/RosterEntry.java | 2 +- .../smack/roster/RosterGroup.java | 6 ++-- .../smackx/jingleold/ContentNegotiator.java | 8 +++-- .../smackx/jingleold/JingleSession.java | 4 ++- .../listeners/JingleSessionListener.java | 7 ++-- .../listeners/JingleTransportListener.java | 7 ++-- .../smackx/jingleold/nat/BridgedResolver.java | 3 +- .../nat/BridgedTransportManager.java | 5 +-- .../jingleold/nat/ICETransportManager.java | 5 +-- .../smackx/jingleold/nat/RTPBridge.java | 34 +++++++----------- .../smackx/jingleold/nat/STUN.java | 14 ++++---- .../jingleold/nat/TransportNegotiator.java | 8 +++-- .../smackx/workgroup/agent/Agent.java | 6 ++-- .../smackx/workgroup/agent/AgentSession.java | 36 ++++++++++--------- .../workgroup/agent/TranscriptManager.java | 4 +-- .../agent/TranscriptSearchManager.java | 8 ++--- .../smackx/workgroup/user/Workgroup.java | 20 +++++------ 53 files changed, 206 insertions(+), 188 deletions(-) diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/carbons/CarbonManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/carbons/CarbonManager.java index 196484c97..c020df7cf 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/carbons/CarbonManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/carbons/CarbonManager.java @@ -339,7 +339,7 @@ public final class CarbonManager extends Manager { IQ setIQ = carbonsEnabledIQ(new_state); - connection().createStanzaCollectorAndSend(setIQ).nextResultOrThrow(); + connection().sendIqRequestAndWaitForResponse(setIQ); enabled_state = new_state; } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/httpfileupload/HttpFileUploadManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/httpfileupload/HttpFileUploadManager.java index 4b7cfa079..3f98a5056 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/httpfileupload/HttpFileUploadManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/httpfileupload/HttpFileUploadManager.java @@ -418,7 +418,7 @@ public final class HttpFileUploadManager extends Manager { throw new AssertionError(); } - return connection.createStanzaCollectorAndSend(slotRequest).nextResultOrThrow(); + return connection.sendIqRequestAndWaitForResponse(slotRequest); } public void setTlsContext(SSLContext tlsContext) { diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/control/IoTControlManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/control/IoTControlManager.java index 07e65cb85..241b20ea8 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/control/IoTControlManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/control/IoTControlManager.java @@ -128,7 +128,7 @@ public final class IoTControlManager extends IoTManager { public IoTSetResponse setUsingIq(FullJid jid, Collection data) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { IoTSetRequest request = new IoTSetRequest(data); request.setTo(jid); - IoTSetResponse response = connection().createStanzaCollectorAndSend(request).nextResultOrThrow(); + IoTSetResponse response = connection().sendIqRequestAndWaitForResponse(request); return response; } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/data/IoTDataManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/data/IoTDataManager.java index 8375d01cf..3c512d4ca 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/data/IoTDataManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/data/IoTDataManager.java @@ -191,7 +191,7 @@ public final class IoTDataManager extends IoTManager { StanzaCollector dataCollector = connection.createStanzaCollector(dataCollectorConfiguration); try { - connection.createStanzaCollectorAndSend(iotDataRequest).nextResultOrThrow(); + connection.sendIqRequestAndWaitForResponse(iotDataRequest); // Wait until a message with an IoTFieldsExtension and the done flag comes in. doneCollector.nextResult(); } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/discovery/IoTDiscoveryManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/discovery/IoTDiscoveryManager.java index 9d2d22ee9..a719fed8a 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/discovery/IoTDiscoveryManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/discovery/IoTDiscoveryManager.java @@ -246,7 +246,7 @@ public final class IoTDiscoveryManager extends Manager { final XMPPConnection connection = connection(); IoTRegister iotRegister = new IoTRegister(thing.getMetaTags(), thing.getNodeInfo(), thing.isSelfOwened()); iotRegister.setTo(registry); - IQ result = connection.createStanzaCollectorAndSend(iotRegister).nextResultOrThrow(); + IQ result = connection.sendIqRequestAndWaitForResponse(iotRegister); if (result instanceof IoTClaimed) { IoTClaimed iotClaimedResult = (IoTClaimed) result; throw new IoTClaimedException(iotClaimedResult); @@ -293,7 +293,7 @@ public final class IoTDiscoveryManager extends Manager { IoTMine iotMine = new IoTMine(metaTags, publicThing); iotMine.setTo(registry); - IoTClaimed iotClaimed = connection().createStanzaCollectorAndSend(iotMine).nextResultOrThrow(); + IoTClaimed iotClaimed = connection().sendIqRequestAndWaitForResponse(iotMine); // The 'jid' attribute of the response now represents the XMPP address of the thing we just successfully claimed. Jid thing = iotClaimed.getJid(); @@ -322,7 +322,7 @@ public final class IoTDiscoveryManager extends Manager { IoTRemove iotRemove = new IoTRemove(thing, nodeInfo); iotRemove.setTo(registry); - connection().createStanzaCollectorAndSend(iotRemove).nextResultOrThrow(); + connection().sendIqRequestAndWaitForResponse(iotRemove); // We no not update the ThingState here, as this is done in the IQ handler above.; } @@ -346,7 +346,7 @@ public final class IoTDiscoveryManager extends Manager { IoTUnregister iotUnregister = new IoTUnregister(nodeInfo); iotUnregister.setTo(registry); - connection().createStanzaCollectorAndSend(iotUnregister).nextResultOrThrow(); + connection().sendIqRequestAndWaitForResponse(iotUnregister); ThingState state = getStateFor(nodeInfo); state.setUnregistered(); @@ -375,7 +375,7 @@ public final class IoTDiscoveryManager extends Manager { IoTDisown iotDisown = new IoTDisown(thing, nodeInfo); iotDisown.setTo(registry); - connection().createStanzaCollectorAndSend(iotDisown).nextResultOrThrow(); + connection().sendIqRequestAndWaitForResponse(iotDisown); } // Registry utility methods diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/provisioning/IoTProvisioningManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/provisioning/IoTProvisioningManager.java index a1971400c..d11e46f42 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/provisioning/IoTProvisioningManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/provisioning/IoTProvisioningManager.java @@ -344,7 +344,7 @@ public final class IoTProvisioningManager extends Manager { IoTIsFriend iotIsFriend = new IoTIsFriend(friendInQuestion); iotIsFriend.setTo(provisioningServer); - IoTIsFriendResponse response = connection().createStanzaCollectorAndSend(iotIsFriend).nextResultOrThrow(); + IoTIsFriendResponse response = connection().sendIqRequestAndWaitForResponse(iotIsFriend); assert response.getJid().equals(friendInQuestion); boolean isFriend = response.getIsFriendResult(); if (!isFriend) { diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java index 382f1af3f..b0d43e117 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java @@ -533,7 +533,7 @@ public final class MamManager extends Manager { MamQueryIQ mamQueryIq = new MamQueryIQ(queryId, node, null); mamQueryIq.setTo(archiveAddress); - MamQueryIQ mamResponseQueryIq = connection().createStanzaCollectorAndSend(mamQueryIq).nextResultOrThrow(); + MamQueryIQ mamResponseQueryIq = connection().sendIqRequestAndWaitForResponse(mamQueryIq); return mamResponseQueryIq.getDataForm().getFields(); } @@ -864,7 +864,7 @@ public final class MamManager extends Manager { NotConnectedException, InterruptedException, NotLoggedInException { final XMPPConnection connection = getAuthenticatedConnectionOrThrow(); - MamPrefsIQ mamPrefsResultIQ = connection.createStanzaCollectorAndSend(mamPrefsIQ).nextResultOrThrow(); + MamPrefsIQ mamPrefsResultIQ = connection.sendIqRequestAndWaitForResponse(mamPrefsIQ); return new MamPrefsResult(mamPrefsResultIQ, DataForm.from(mamPrefsIQ)); } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/muclight/MultiUserChatLight.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/muclight/MultiUserChatLight.java index ba001f38c..8a5c51f2b 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/muclight/MultiUserChatLight.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/muclight/MultiUserChatLight.java @@ -301,7 +301,7 @@ public class MultiUserChatLight { messageCollector = connection.createStanzaCollector(fromRoomGroupChatFilter); try { - connection.createStanzaCollectorAndSend(createMUCLightIQ).nextResultOrThrow(); + connection.sendIqRequestAndWaitForResponse(createMUCLightIQ); } catch (NotConnectedException | InterruptedException | NoResponseException | XMPPErrorException e) { removeConnectionCallbacks(); throw e; @@ -332,7 +332,7 @@ public class MultiUserChatLight { affiliations.put(connection.getUser(), MUCLightAffiliation.none); MUCLightChangeAffiliationsIQ changeAffiliationsIQ = new MUCLightChangeAffiliationsIQ(room, affiliations); - IQ responseIq = connection.createStanzaCollectorAndSend(changeAffiliationsIQ).nextResultOrThrow(); + IQ responseIq = connection.sendIqRequestAndWaitForResponse(changeAffiliationsIQ); boolean roomLeft = responseIq.getType().equals(IQ.Type.result); if (roomLeft) { @@ -354,7 +354,7 @@ public class MultiUserChatLight { throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { MUCLightGetInfoIQ mucLightGetInfoIQ = new MUCLightGetInfoIQ(room, version); - IQ responseIq = connection.createStanzaCollectorAndSend(mucLightGetInfoIQ).nextResultOrThrow(); + IQ responseIq = connection.sendIqRequestAndWaitForResponse(mucLightGetInfoIQ); MUCLightInfoIQ mucLightInfoResponseIQ = (MUCLightInfoIQ) responseIq; return new MUCLightRoomInfo(mucLightInfoResponseIQ.getVersion(), room, @@ -388,7 +388,7 @@ public class MultiUserChatLight { public MUCLightRoomConfiguration getConfiguration(String version) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { MUCLightGetConfigsIQ mucLightGetConfigsIQ = new MUCLightGetConfigsIQ(room, version); - IQ responseIq = connection.createStanzaCollectorAndSend(mucLightGetConfigsIQ).nextResultOrThrow(); + IQ responseIq = connection.sendIqRequestAndWaitForResponse(mucLightGetConfigsIQ); MUCLightConfigurationIQ mucLightConfigurationIQ = (MUCLightConfigurationIQ) responseIq; return mucLightConfigurationIQ.getConfiguration(); } @@ -421,7 +421,7 @@ public class MultiUserChatLight { throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { MUCLightGetAffiliationsIQ mucLightGetAffiliationsIQ = new MUCLightGetAffiliationsIQ(room, version); - IQ responseIq = connection.createStanzaCollectorAndSend(mucLightGetAffiliationsIQ).nextResultOrThrow(); + IQ responseIq = connection.sendIqRequestAndWaitForResponse(mucLightGetAffiliationsIQ); MUCLightAffiliationsIQ mucLightAffiliationsIQ = (MUCLightAffiliationsIQ) responseIq; return mucLightAffiliationsIQ.getAffiliations(); @@ -453,7 +453,7 @@ public class MultiUserChatLight { public void changeAffiliations(HashMap affiliations) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { MUCLightChangeAffiliationsIQ changeAffiliationsIQ = new MUCLightChangeAffiliationsIQ(room, affiliations); - connection.createStanzaCollectorAndSend(changeAffiliationsIQ).nextResultOrThrow(); + connection.sendIqRequestAndWaitForResponse(changeAffiliationsIQ); } /** @@ -466,7 +466,7 @@ public class MultiUserChatLight { */ public void destroy() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { MUCLightDestroyIQ mucLightDestroyIQ = new MUCLightDestroyIQ(room); - IQ responseIq = connection.createStanzaCollectorAndSend(mucLightDestroyIQ).nextResultOrThrow(); + IQ responseIq = connection.sendIqRequestAndWaitForResponse(mucLightDestroyIQ); boolean roomDestroyed = responseIq.getType().equals(IQ.Type.result); if (roomDestroyed) { @@ -486,7 +486,7 @@ public class MultiUserChatLight { public void changeSubject(String subject) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { MUCLightSetConfigsIQ mucLightSetConfigIQ = new MUCLightSetConfigsIQ(room, null, subject, null); - connection.createStanzaCollectorAndSend(mucLightSetConfigIQ).nextResultOrThrow(); + connection.sendIqRequestAndWaitForResponse(mucLightSetConfigIQ); } /** @@ -501,7 +501,7 @@ public class MultiUserChatLight { public void changeRoomName(String roomName) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { MUCLightSetConfigsIQ mucLightSetConfigIQ = new MUCLightSetConfigsIQ(room, roomName, null); - connection.createStanzaCollectorAndSend(mucLightSetConfigIQ).nextResultOrThrow(); + connection.sendIqRequestAndWaitForResponse(mucLightSetConfigIQ); } /** @@ -531,7 +531,7 @@ public class MultiUserChatLight { public void setRoomConfigs(String roomName, HashMap customConfigs) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { MUCLightSetConfigsIQ mucLightSetConfigIQ = new MUCLightSetConfigsIQ(room, roomName, customConfigs); - connection.createStanzaCollectorAndSend(mucLightSetConfigIQ).nextResultOrThrow(); + connection.sendIqRequestAndWaitForResponse(mucLightSetConfigIQ); } } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/muclight/MultiUserChatLightManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/muclight/MultiUserChatLightManager.java index 848411f58..d153d499d 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/muclight/MultiUserChatLightManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/muclight/MultiUserChatLightManager.java @@ -279,7 +279,7 @@ public final class MultiUserChatLightManager extends Manager { MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(rooms, null); mucLightBlockingIQ.setType(IQ.Type.set); mucLightBlockingIQ.setTo(mucLightService); - connection().createStanzaCollectorAndSend(mucLightBlockingIQ).nextResultOrThrow(); + connection().sendIqRequestAndWaitForResponse(mucLightBlockingIQ); } /** @@ -323,7 +323,7 @@ public final class MultiUserChatLightManager extends Manager { MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(null, users); mucLightBlockingIQ.setType(IQ.Type.set); mucLightBlockingIQ.setTo(mucLightService); - connection().createStanzaCollectorAndSend(mucLightBlockingIQ).nextResultOrThrow(); + connection().sendIqRequestAndWaitForResponse(mucLightBlockingIQ); } /** @@ -367,7 +367,7 @@ public final class MultiUserChatLightManager extends Manager { MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(rooms, null); mucLightBlockingIQ.setType(IQ.Type.set); mucLightBlockingIQ.setTo(mucLightService); - connection().createStanzaCollectorAndSend(mucLightBlockingIQ).nextResultOrThrow(); + connection().sendIqRequestAndWaitForResponse(mucLightBlockingIQ); } /** @@ -411,7 +411,7 @@ public final class MultiUserChatLightManager extends Manager { MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(null, users); mucLightBlockingIQ.setType(IQ.Type.set); mucLightBlockingIQ.setTo(mucLightService); - connection().createStanzaCollectorAndSend(mucLightBlockingIQ).nextResultOrThrow(); + connection().sendIqRequestAndWaitForResponse(mucLightBlockingIQ); } } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/push_notifications/PushNotificationsManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/push_notifications/PushNotificationsManager.java index 5a4f0505b..ff62d96eb 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/push_notifications/PushNotificationsManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/push_notifications/PushNotificationsManager.java @@ -164,7 +164,7 @@ public final class PushNotificationsManager extends Manager { private boolean changePushNotificationsStatus(IQ iq) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException { final XMPPConnection connection = connection(); - IQ responseIQ = connection.createStanzaCollectorAndSend(iq).nextResultOrThrow(); + IQ responseIQ = connection.sendIqRequestAndWaitForResponse(iq); return responseIQ.getType() != IQ.Type.error; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/BlockingCommandManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/BlockingCommandManager.java index 28ae4fa24..6f1b30fe6 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/BlockingCommandManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/BlockingCommandManager.java @@ -184,7 +184,7 @@ public final class BlockingCommandManager extends Manager { if (blockListCached == null) { BlockListIQ blockListIQ = new BlockListIQ(); - BlockListIQ blockListIQResult = connection().createStanzaCollectorAndSend(blockListIQ).nextResultOrThrow(); + BlockListIQ blockListIQResult = connection().sendIqRequestAndWaitForResponse(blockListIQ); blockListCached = blockListIQResult.getBlockedJidsCopy(); } @@ -203,7 +203,7 @@ public final class BlockingCommandManager extends Manager { public void blockContacts(List jids) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { BlockContactsIQ blockContactIQ = new BlockContactsIQ(jids); - connection().createStanzaCollectorAndSend(blockContactIQ).nextResultOrThrow(); + connection().sendIqRequestAndWaitForResponse(blockContactIQ); } /** @@ -218,7 +218,7 @@ public final class BlockingCommandManager extends Manager { public void unblockContacts(List jids) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { UnblockContactsIQ unblockContactIQ = new UnblockContactsIQ(jids); - connection().createStanzaCollectorAndSend(unblockContactIQ).nextResultOrThrow(); + connection().sendIqRequestAndWaitForResponse(unblockContactIQ); } /** @@ -232,7 +232,7 @@ public final class BlockingCommandManager extends Manager { public void unblockAll() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { UnblockContactsIQ unblockContactIQ = new UnblockContactsIQ(); - connection().createStanzaCollectorAndSend(unblockContactIQ).nextResultOrThrow(); + connection().sendIqRequestAndWaitForResponse(unblockContactIQ); } public void addJidsBlockedListener(JidsBlockedListener jidsBlockedListener) { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bob/BoBManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bob/BoBManager.java index aff276e7c..cfc6404d8 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bob/BoBManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bob/BoBManager.java @@ -149,7 +149,7 @@ public final class BoBManager extends Manager { requestBoBIQ.setTo(to); XMPPConnection connection = getAuthenticatedConnectionOrThrow(); - BoBIQ responseBoBIQ = connection.createStanzaCollectorAndSend(requestBoBIQ).nextResultOrThrow(); + BoBIQ responseBoBIQ = connection.sendIqRequestAndWaitForResponse(requestBoBIQ); bobData = responseBoBIQ.getBoBData(); BOB_CACHE.put(bobHash, bobData); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManager.java index c97ad9634..9061a5606 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManager.java @@ -424,7 +424,7 @@ public final class InBandBytestreamManager extends Manager implements Bytestream final XMPPConnection connection = connection(); // sending packet will throw exception on timeout or error reply - connection.createStanzaCollectorAndSend(byteStreamRequest).nextResultOrThrow(); + connection.sendIqRequestAndWaitForResponse(byteStreamRequest); InBandBytestreamSession inBandBytestreamSession = new InBandBytestreamSession( connection, byteStreamRequest, targetJID); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java index df783618f..0e74aa813 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java @@ -228,7 +228,7 @@ public class InBandBytestreamSession implements BytestreamSession { Close close = new Close(this.byteStreamRequest.getSessionID()); close.setTo(this.remoteJID); try { - connection.createStanzaCollectorAndSend(close).nextResultOrThrow(); + connection.sendIqRequestAndWaitForResponse(close); } catch (Exception e) { // Sadly we are unable to use the IOException(Throwable) constructor because this @@ -823,7 +823,7 @@ public class InBandBytestreamSession implements BytestreamSession { iq.setTo(remoteJID); try { - connection.createStanzaCollectorAndSend(iq).nextResultOrThrow(); + connection.sendIqRequestAndWaitForResponse(iq); } catch (Exception e) { // close session unless it is already closed diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamManager.java index 4e67561e1..12be65fcb 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamManager.java @@ -624,8 +624,8 @@ public final class Socks5BytestreamManager extends Manager implements Bytestream for (Jid proxy : proxies) { Bytestream streamHostRequest = createStreamHostRequest(proxy); try { - Bytestream response = connection.createStanzaCollectorAndSend( - streamHostRequest).nextResultOrThrow(); + Bytestream response = connection.sendIqRequestAndWaitForResponse( + streamHostRequest); streamHosts.addAll(response.getStreamHosts()); } catch (Exception e) { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiator.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiator.java index 8fc609c3d..f92393abd 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiator.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiator.java @@ -115,7 +115,7 @@ public class Socks5ClientForInitiator extends Socks5Client { private void activate() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { Bytestream activate = createStreamHostActivation(); // if activation fails #nextResultOrThrow() throws an exception - connection.get().createStanzaCollectorAndSend(activate).nextResultOrThrow(); + connection.get().sendIqRequestAndWaitForResponse(activate); } /** diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/RemoteCommand.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/RemoteCommand.java index 58d8cc74e..e79919eb6 100755 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/RemoteCommand.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/RemoteCommand.java @@ -145,7 +145,7 @@ public class RemoteCommand extends AdHocCommand { AdHocCommandData responseData = null; try { - responseData = connection.createStanzaCollectorAndSend(data).nextResultOrThrow(); + responseData = connection.sendIqRequestAndWaitForResponse(data); } finally { // We set the response data in a 'finally' block, so that it also gets set even if an error IQ was returned. diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java index 312b559b5..b37209ad4 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java @@ -603,7 +603,7 @@ public final class ServiceDiscoveryManager extends Manager { .setNode(node) .build(); - Stanza result = connection.createStanzaCollectorAndSend(discoInfoRequest).nextResultOrThrow(); + Stanza result = connection.sendIqRequestAndWaitForResponse(discoInfoRequest); return (DiscoverInfo) result; } @@ -642,7 +642,7 @@ public final class ServiceDiscoveryManager extends Manager { disco.setTo(entityID); disco.setNode(node); - Stanza result = connection().createStanzaCollectorAndSend(disco).nextResultOrThrow(); + Stanza result = connection().sendIqRequestAndWaitForResponse(disco); return (DiscoverItems) result; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqlast/LastActivityManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqlast/LastActivityManager.java index fe23e4e18..2f4b6ba38 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqlast/LastActivityManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqlast/LastActivityManager.java @@ -236,7 +236,7 @@ public final class LastActivityManager extends Manager { public LastActivity getLastActivity(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { LastActivity activity = new LastActivity(jid); - return (LastActivity) connection().createStanzaCollectorAndSend(activity).nextResultOrThrow(); + return (LastActivity) connection().sendIqRequestAndWaitForResponse(activity); } /** diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqprivate/PrivateDataManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqprivate/PrivateDataManager.java index e93c560de..dfea387c2 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqprivate/PrivateDataManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqprivate/PrivateDataManager.java @@ -163,8 +163,8 @@ public final class PrivateDataManager extends Manager { // Create an IQ packet to get the private data. IQ privateDataGet = new PrivateDataIQ(elementName, namespace); - PrivateDataIQ response = connection().createStanzaCollectorAndSend( - privateDataGet).nextResultOrThrow(); + PrivateDataIQ response = connection().sendIqRequestAndWaitForResponse( + privateDataGet); return response.getPrivateData(); } @@ -183,7 +183,7 @@ public final class PrivateDataManager extends Manager { // Create an IQ packet to set the private data. IQ privateDataSet = new PrivateDataIQ(privateData); - connection().createStanzaCollectorAndSend(privateDataSet).nextResultOrThrow(); + connection().sendIqRequestAndWaitForResponse(privateDataSet); } private static final PrivateData DUMMY_PRIVATE_DATA = new PrivateData() { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqversion/VersionManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqversion/VersionManager.java index a170fc6d1..e02a4f999 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqversion/VersionManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqversion/VersionManager.java @@ -155,7 +155,7 @@ public final class VersionManager extends Manager { } XMPPConnection connection = connection(); Version version = Version.builder(connection).to(jid).build(); - return connection().createStanzaCollectorAndSend(version).nextResultOrThrow(); + return connection().sendIqRequestAndWaitForResponse(version); } private static VersionInformation generateVersionFrom(String name, String version, String os) { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleUtil.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleUtil.java index 1ac93c448..6eb5911fe 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleUtil.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleUtil.java @@ -90,7 +90,7 @@ public class JingleUtil { XMPPException.XMPPErrorException, SmackException.NoResponseException { Jingle jingle = createSessionInitiateFileOffer(recipient, sessionId, contentCreator, contentName, description, transport); - return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow(); + return connection.sendIqRequestAndWaitForResponse(jingle); } public IQ sendSessionInitiate(FullJid recipient, @@ -176,7 +176,7 @@ public class JingleUtil { XMPPException.XMPPErrorException, SmackException.NoResponseException { Jingle jingle = createSessionTerminateDecline(recipient, sessionId); - return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow(); + return connection.sendIqRequestAndWaitForResponse(jingle); } public Jingle createSessionTerminateSuccess(FullJid recipient, String sessionId) { @@ -188,7 +188,7 @@ public class JingleUtil { SmackException.NotConnectedException, SmackException.NoResponseException { Jingle jingle = createSessionTerminateSuccess(recipient, sessionId); - return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow(); + return connection.sendIqRequestAndWaitForResponse(jingle); } public Jingle createSessionTerminateBusy(FullJid recipient, String sessionId) { @@ -200,7 +200,7 @@ public class JingleUtil { SmackException.NotConnectedException, SmackException.NoResponseException { Jingle jingle = createSessionTerminateBusy(recipient, sessionId); - return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow(); + return connection.sendIqRequestAndWaitForResponse(jingle); } public Jingle createSessionTerminateAlternativeSession(FullJid recipient, String sessionId, String altSessionId) { @@ -212,7 +212,7 @@ public class JingleUtil { SmackException.NotConnectedException, SmackException.NoResponseException { Jingle jingle = createSessionTerminateAlternativeSession(recipient, sessionId, altSessionId); - return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow(); + return connection.sendIqRequestAndWaitForResponse(jingle); } public Jingle createSessionTerminateCancel(FullJid recipient, String sessionId) { @@ -225,7 +225,7 @@ public class JingleUtil { SmackException.NotConnectedException, SmackException.NoResponseException { Jingle jingle = createSessionTerminateCancel(recipient, sessionId); - return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow(); + return connection.sendIqRequestAndWaitForResponse(jingle); } public Jingle createSessionTerminateContentCancel(FullJid recipient, String sessionId, @@ -249,7 +249,7 @@ public class JingleUtil { throws SmackException.NotConnectedException, InterruptedException, XMPPException.XMPPErrorException, SmackException.NoResponseException { Jingle jingle = createSessionTerminateContentCancel(recipient, sessionId, contentCreator, contentName); - return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow(); + return connection.sendIqRequestAndWaitForResponse(jingle); } public Jingle createSessionTerminateUnsupportedTransports(FullJid recipient, String sessionId) { @@ -260,7 +260,7 @@ public class JingleUtil { throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException { Jingle jingle = createSessionTerminateUnsupportedTransports(recipient, sessionId); - return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow(); + return connection.sendIqRequestAndWaitForResponse(jingle); } public Jingle createSessionTerminateFailedTransport(FullJid recipient, String sessionId) { @@ -271,7 +271,7 @@ public class JingleUtil { throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException { Jingle jingle = createSessionTerminateFailedTransport(recipient, sessionId); - return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow(); + return connection.sendIqRequestAndWaitForResponse(jingle); } public Jingle createSessionTerminateUnsupportedApplications(FullJid recipient, String sessionId) { @@ -282,7 +282,7 @@ public class JingleUtil { throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException { Jingle jingle = createSessionTerminateUnsupportedApplications(recipient, sessionId); - return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow(); + return connection.sendIqRequestAndWaitForResponse(jingle); } public Jingle createSessionTerminateFailedApplication(FullJid recipient, String sessionId) { @@ -293,7 +293,7 @@ public class JingleUtil { throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException { Jingle jingle = createSessionTerminateFailedApplication(recipient, sessionId); - return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow(); + return connection.sendIqRequestAndWaitForResponse(jingle); } public Jingle createSessionTerminateIncompatibleParameters(FullJid recipient, String sessionId) { @@ -304,7 +304,7 @@ public class JingleUtil { throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException { Jingle jingle = createSessionTerminateIncompatibleParameters(recipient, sessionId); - return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow(); + return connection.sendIqRequestAndWaitForResponse(jingle); } public IQ sendContentRejectFileNotAvailable(FullJid recipient, String sessionId, JingleContentDescription description) { @@ -327,7 +327,7 @@ public class JingleUtil { throws SmackException.NotConnectedException, InterruptedException, XMPPException.XMPPErrorException, SmackException.NoResponseException { Jingle jingle = createSessionPing(recipient, sessionId); - return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow(); + return connection.sendIqRequestAndWaitForResponse(jingle); } public IQ createAck(Jingle jingle) { @@ -362,7 +362,7 @@ public class JingleUtil { throws SmackException.NotConnectedException, InterruptedException, XMPPException.XMPPErrorException, SmackException.NoResponseException { Jingle jingle = createTransportReplace(recipient, initiator, sessionId, contentCreator, contentName, transport); - return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow(); + return connection.sendIqRequestAndWaitForResponse(jingle); } public Jingle createTransportAccept(FullJid recipient, FullJid initiator, String sessionId, @@ -389,7 +389,7 @@ public class JingleUtil { throws SmackException.NotConnectedException, InterruptedException, XMPPException.XMPPErrorException, SmackException.NoResponseException { Jingle jingle = createTransportAccept(recipient, initiator, sessionId, contentCreator, contentName, transport); - return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow(); + return connection.sendIqRequestAndWaitForResponse(jingle); } public Jingle createTransportReject(FullJid recipient, FullJid initiator, String sessionId, @@ -416,7 +416,7 @@ public class JingleUtil { throws SmackException.NotConnectedException, InterruptedException, XMPPException.XMPPErrorException, SmackException.NoResponseException { Jingle jingle = createTransportReject(recipient, initiator, sessionId, contentCreator, contentName, transport); - return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow(); + return connection.sendIqRequestAndWaitForResponse(jingle); } /* diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/jingle_s5b/JingleS5BTransportManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/jingle_s5b/JingleS5BTransportManager.java index 60b1e9f88..06accc144 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/jingle_s5b/JingleS5BTransportManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/jingle_s5b/JingleS5BTransportManager.java @@ -119,7 +119,7 @@ public final class JingleS5BTransportManager extends JingleTransportManager jids, MUCAffiliation affiliation) @@ -1732,7 +1732,7 @@ public class MultiUserChat { iq.addItem(item); } - connection.createStanzaCollectorAndSend(iq).nextResultOrThrow(); + connection.sendIqRequestAndWaitForResponse(iq); } private void changeRole(Resourcepart nickname, MUCRole role, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { @@ -1743,7 +1743,7 @@ public class MultiUserChat { MUCItem item = new MUCItem(role, nickname, reason); iq.addItem(item); - connection.createStanzaCollectorAndSend(iq).nextResultOrThrow(); + connection.sendIqRequestAndWaitForResponse(iq); } private void changeRole(Collection nicknames, MUCRole role) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { @@ -1756,7 +1756,7 @@ public class MultiUserChat { iq.addItem(item); } - connection.createStanzaCollectorAndSend(iq).nextResultOrThrow(); + connection.sendIqRequestAndWaitForResponse(iq); } /** @@ -1914,7 +1914,7 @@ public class MultiUserChat { MUCItem item = new MUCItem(affiliation); iq.addItem(item); - MUCAdmin answer = (MUCAdmin) connection.createStanzaCollectorAndSend(iq).nextResultOrThrow(); + MUCAdmin answer = (MUCAdmin) connection.sendIqRequestAndWaitForResponse(iq); // Get the list of affiliates from the server's answer List affiliates = new ArrayList(); @@ -1969,7 +1969,7 @@ public class MultiUserChat { MUCItem item = new MUCItem(role); iq.addItem(item); - MUCAdmin answer = (MUCAdmin) connection.createStanzaCollectorAndSend(iq).nextResultOrThrow(); + MUCAdmin answer = (MUCAdmin) connection.sendIqRequestAndWaitForResponse(iq); // Get the list of participants from the server's answer List participants = new ArrayList(); for (MUCItem mucadminItem : answer.getItems()) { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageManager.java index e4973baa2..c5ac1d776 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageManager.java @@ -178,7 +178,7 @@ public final class OfflineMessageManager extends Manager { }); int pendingNodes = nodes.size(); try (StanzaCollector messageCollector = connection().createStanzaCollector(messageFilter)) { - connection().createStanzaCollectorAndSend(request).nextResultOrThrow(); + connection().sendIqRequestAndWaitForResponse(request); // Collect the received offline messages Message message; do { @@ -249,7 +249,7 @@ public final class OfflineMessageManager extends Manager { item.setAction("remove"); request.addItem(item); } - connection().createStanzaCollectorAndSend(request).nextResultOrThrow(); + connection().sendIqRequestAndWaitForResponse(request); } /** @@ -265,6 +265,6 @@ public final class OfflineMessageManager extends Manager { OfflineMessageRequest request = new OfflineMessageRequest(); request.setType(IQ.Type.set); request.setPurge(true); - connection().createStanzaCollectorAndSend(request).nextResultOrThrow(); + connection().sendIqRequestAndWaitForResponse(request); } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/PrivacyListManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/PrivacyListManager.java index 362ed8e71..847651f21 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/PrivacyListManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/PrivacyListManager.java @@ -233,7 +233,7 @@ public final class PrivacyListManager extends Manager { // The request is a get iq type requestPrivacy.setType(Privacy.Type.get); - return connection().createStanzaCollectorAndSend(requestPrivacy).nextResultOrThrow(); + return connection().sendIqRequestAndWaitForResponse(requestPrivacy); } /** @@ -252,7 +252,7 @@ public final class PrivacyListManager extends Manager { // The request is a get iq type requestPrivacy.setType(Privacy.Type.set); - return connection().createStanzaCollectorAndSend(requestPrivacy).nextResultOrThrow(); + return connection().sendIqRequestAndWaitForResponse(requestPrivacy); } /** diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/LeafNode.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/LeafNode.java index 35c807240..f056c3a62 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/LeafNode.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/LeafNode.java @@ -57,7 +57,7 @@ public class LeafNode extends Node { DiscoverItems items = new DiscoverItems(); items.setTo(pubSubManager.getServiceJid()); items.setNode(getId()); - return pubSubManager.getConnection().createStanzaCollectorAndSend(items).nextResultOrThrow(); + return pubSubManager.getConnection().sendIqRequestAndWaitForResponse(items); } /** @@ -194,7 +194,7 @@ public class LeafNode extends Node { private List getItems(PubSub request, List returnedExtensions) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { - PubSub result = pubSubManager.getConnection().createStanzaCollectorAndSend(request).nextResultOrThrow(); + PubSub result = pubSubManager.getConnection().sendIqRequestAndWaitForResponse(request); ItemsExtension itemsElem = result.getExtension(PubSubElementType.ITEMS); if (returnedExtensions != null) { returnedExtensions.addAll(result.getExtensions()); @@ -278,7 +278,7 @@ public class LeafNode extends Node { public void publish() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { PubSub packet = createPubsubPacket(IQ.Type.set, new NodeExtension(PubSubElementType.PUBLISH, getId())); - pubSubManager.getConnection().createStanzaCollectorAndSend(packet).nextResultOrThrow(); + pubSubManager.getConnection().sendIqRequestAndWaitForResponse(packet); } /** @@ -327,7 +327,7 @@ public class LeafNode extends Node { public void publish(Collection items) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { PubSub packet = createPubsubPacket(IQ.Type.set, new PublishItem<>(getId(), items)); - pubSubManager.getConnection().createStanzaCollectorAndSend(packet).nextResultOrThrow(); + pubSubManager.getConnection().sendIqRequestAndWaitForResponse(packet); } /** @@ -343,7 +343,7 @@ public class LeafNode extends Node { public void deleteAllItems() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { PubSub request = createPubsubPacket(IQ.Type.set, new NodeExtension(PubSubElementType.PURGE_OWNER, getId())); - pubSubManager.getConnection().createStanzaCollectorAndSend(request).nextResultOrThrow(); + pubSubManager.getConnection().sendIqRequestAndWaitForResponse(request); } /** @@ -377,6 +377,6 @@ public class LeafNode extends Node { items.add(new Item(id)); } PubSub request = createPubsubPacket(IQ.Type.set, new ItemsExtension(ItemsExtension.ItemsElementType.retract, getId(), items)); - pubSubManager.getConnection().createStanzaCollectorAndSend(request).nextResultOrThrow(); + pubSubManager.getConnection().sendIqRequestAndWaitForResponse(request); } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java index 26d4a060c..4db909dfa 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java @@ -112,7 +112,7 @@ public abstract class Node { public void sendConfigurationForm(FillableConfigureForm configureForm) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { PubSub packet = createPubsubPacket(IQ.Type.set, new FormNode(FormNodeType.CONFIGURE_OWNER, getId(), configureForm.getDataFormToSubmit())); - pubSubManager.getConnection().createStanzaCollectorAndSend(packet).nextResultOrThrow(); + pubSubManager.getConnection().sendIqRequestAndWaitForResponse(packet); } /** @@ -130,7 +130,7 @@ public abstract class Node { .to(pubSubManager.getServiceJid()) .setNode(getId()) .build(); - return connection.createStanzaCollectorAndSend(discoverInfoRequest).nextResultOrThrow(); + return connection.sendIqRequestAndWaitForResponse(discoverInfoRequest); } /** diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java index 861fcdb06..cbe9c10cb 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java @@ -302,7 +302,7 @@ public final class PubSubManager extends Manager { .setNode(id) .build(); - DiscoverInfo infoReply = connection.createStanzaCollectorAndSend(info).nextResultOrThrow(); + DiscoverInfo infoReply = connection.sendIqRequestAndWaitForResponse(info); if (infoReply.hasIdentity(PubSub.ELEMENT, "leaf")) { node = new LeafNode(this, id); @@ -492,7 +492,7 @@ public final class PubSubManager extends Manager { if (nodeId != null) items.setNode(nodeId); items.setTo(pubSubService); - DiscoverItems nodeItems = connection().createStanzaCollectorAndSend(items).nextResultOrThrow(); + DiscoverItems nodeItems = connection().sendIqRequestAndWaitForResponse(items); return nodeItems; } @@ -666,7 +666,7 @@ public final class PubSubManager extends Manager { PubSub sendPubsubPacket(PubSub packet) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { - IQ resultIQ = connection().createStanzaCollectorAndSend(packet).nextResultOrThrow(); + IQ resultIQ = connection().sendIqRequestAndWaitForResponse(packet); if (resultIQ instanceof EmptyResultIQ) { return null; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/search/UserSearch.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/search/UserSearch.java index bac591b78..7e1717738 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/search/UserSearch.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/search/UserSearch.java @@ -73,7 +73,7 @@ public class UserSearch extends SimpleIQ { search.setType(IQ.Type.get); search.setTo(searchService); - IQ response = con.createStanzaCollectorAndSend(search).nextResultOrThrow(); + IQ response = con.sendIqRequestAndWaitForResponse(search); return DataForm.from(response, NAMESPACE); } @@ -95,7 +95,7 @@ public class UserSearch extends SimpleIQ { search.setTo(searchService); search.addExtension(searchForm); - IQ response = con.createStanzaCollectorAndSend(search).nextResultOrThrow(); + IQ response = con.sendIqRequestAndWaitForResponse(search); return ReportedData.getReportedDataFrom(response); } @@ -117,7 +117,7 @@ public class UserSearch extends SimpleIQ { search.setType(IQ.Type.set); search.setTo(searchService); - SimpleUserSearch response = con.createStanzaCollectorAndSend(search).nextResultOrThrow(); + SimpleUserSearch response = con.sendIqRequestAndWaitForResponse(search); return response.getReportedData(); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/sharedgroups/SharedGroupManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/sharedgroups/SharedGroupManager.java index 3ed412f57..4f9f1935f 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/sharedgroups/SharedGroupManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/sharedgroups/SharedGroupManager.java @@ -52,7 +52,7 @@ public class SharedGroupManager { SharedGroupsInfo info = new SharedGroupsInfo(); info.setType(IQ.Type.get); - SharedGroupsInfo result = connection.createStanzaCollectorAndSend(info).nextResultOrThrow(); + SharedGroupsInfo result = connection.sendIqRequestAndWaitForResponse(info); return result.getGroups(); } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/time/EntityTimeManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/time/EntityTimeManager.java index 4262d8213..99a5e41bc 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/time/EntityTimeManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/time/EntityTimeManager.java @@ -118,6 +118,6 @@ public final class EntityTimeManager extends Manager { Time request = Time.builder(connection) .to(jid) .build(); - return connection.createStanzaCollectorAndSend(request).nextResultOrThrow(); + return connection.sendIqRequestAndWaitForResponse(request); } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/VCardManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/VCardManager.java index 87346d513..0bfbba9b2 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/VCardManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/VCardManager.java @@ -107,7 +107,7 @@ public final class VCardManager extends Manager { // Also make sure to generate a new stanza id (the given vcard could be a vcard result), in which case we don't // want to use the same stanza id again (although it wouldn't break if we did) vcard.setStanzaId(); - connection().createStanzaCollectorAndSend(vcard).nextResultOrThrow(); + connection().sendIqRequestAndWaitForResponse(vcard); } /** @@ -137,7 +137,7 @@ public final class VCardManager extends Manager { public VCard loadVCard(EntityBareJid bareJid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { VCard vcardRequest = new VCard(); vcardRequest.setTo(bareJid); - VCard result = connection().createStanzaCollectorAndSend(vcardRequest).nextResultOrThrow(); + VCard result = connection().sendIqRequestAndWaitForResponse(vcardRequest); return result; } diff --git a/smack-extensions/src/testFixtures/java/org/jivesoftware/util/ConnectionUtils.java b/smack-extensions/src/testFixtures/java/org/jivesoftware/util/ConnectionUtils.java index 910d73ee7..3beae26dc 100644 --- a/smack-extensions/src/testFixtures/java/org/jivesoftware/util/ConnectionUtils.java +++ b/smack-extensions/src/testFixtures/java/org/jivesoftware/util/ConnectionUtils.java @@ -129,6 +129,17 @@ public class ConnectionUtils { when(collector.nextResultOrThrow()).thenAnswer(answerOrThrow); when(collector.nextResultOrThrow(anyLong())).thenAnswer(answerOrThrow); + Answer responseIq = new Answer() { + @Override + public IQ answer(InvocationOnMock invocation) throws Throwable { + collectorAndSend.answer(invocation); + + IQ response = (IQ) answerOrThrow.answer(invocation); + return response; + } + }; + when(connection.sendIqRequestAndWaitForResponse(isA(IQ.class))).thenAnswer(responseIq); + // initialize service discovery manager for this connection ServiceDiscoveryManager.getInstanceFor(connection); diff --git a/smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java index c212eaeb7..3d3198315 100644 --- a/smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java @@ -699,7 +699,7 @@ public final class Roster extends Manager { } } rosterPacket.addRosterItem(item); - connection.createStanzaCollectorAndSend(rosterPacket).nextResultOrThrow(); + connection.sendIqRequestAndWaitForResponse(rosterPacket); } /** @@ -852,7 +852,7 @@ public final class Roster extends Manager { // Set the item type as REMOVE so that the server will delete the entry item.setItemType(RosterPacket.ItemType.remove); packet.addRosterItem(item); - connection.createStanzaCollectorAndSend(packet).nextResultOrThrow(); + connection.sendIqRequestAndWaitForResponse(packet); } /** diff --git a/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntry.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntry.java index 113058428..8a13fda90 100644 --- a/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntry.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntry.java @@ -110,7 +110,7 @@ public final class RosterEntry extends Manager { // Create a new roster item with the current RosterEntry and the *new* name. Note that we can't set the name of // RosterEntry right away, as otherwise the updated event wont get fired, because equalsDeep would return true. packet.addRosterItem(toRosterItem(this, name)); - connection().createStanzaCollectorAndSend(packet).nextResultOrThrow(); + connection().sendIqRequestAndWaitForResponse(packet); // We have received a result response to the IQ set, the name was successfully changed item.setName(name); diff --git a/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterGroup.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterGroup.java index 19e7cacab..f8718fcbb 100644 --- a/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterGroup.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterGroup.java @@ -85,7 +85,7 @@ public class RosterGroup extends Manager { item.removeGroupName(this.name); item.addGroupName(name); packet.addRosterItem(item); - connection().createStanzaCollectorAndSend(packet).nextResultOrThrow(); + connection().sendIqRequestAndWaitForResponse(packet); } } } @@ -180,7 +180,7 @@ public class RosterGroup extends Manager { item.addGroupName(getName()); packet.addRosterItem(item); // Wait up to a certain number of seconds for a reply from the server. - connection().createStanzaCollectorAndSend(packet).nextResultOrThrow(); + connection().sendIqRequestAndWaitForResponse(packet); } } } @@ -211,7 +211,7 @@ public class RosterGroup extends Manager { item.removeGroupName(this.getName()); packet.addRosterItem(item); // Wait up to a certain number of seconds for a reply from the server. - connection().createStanzaCollectorAndSend(packet).nextResultOrThrow(); + connection().sendIqRequestAndWaitForResponse(packet); } } } diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/ContentNegotiator.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/ContentNegotiator.java index 2d9d663b5..d876ff36f 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/ContentNegotiator.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/ContentNegotiator.java @@ -20,8 +20,10 @@ import java.util.ArrayList; import java.util.List; import org.jivesoftware.smack.SmackException; +import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smackx.jingleold.listeners.JingleListener; @@ -265,7 +267,7 @@ public class ContentNegotiator extends JingleNegotiator { return result; } - public void triggerContentEstablished() throws NotConnectedException, InterruptedException { + public void triggerContentEstablished() throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException { PayloadType bestCommonAudioPt = getMediaNegotiator().getBestCommonAudioPt(); TransportCandidate bestRemoteCandidate = getTransportNegotiator().getBestRemoteCandidate(); @@ -279,8 +281,10 @@ public class ContentNegotiator extends JingleNegotiator { * Trigger a session established event. * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. + * @throws XMPPErrorException if there was an XMPP error returned. + * @throws NoResponseException if there was no response from the remote entity. */ - private void triggerContentEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc) throws NotConnectedException, InterruptedException { + private void triggerContentEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException { // Let the session know that we've established a content/media segment. JingleSession session = getSession(); diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSession.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSession.java index 7358d11a2..c202ac9b5 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSession.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSession.java @@ -27,10 +27,12 @@ import java.util.logging.Logger; import org.jivesoftware.smack.AbstractConnectionClosedListener; import org.jivesoftware.smack.ConnectionListener; import org.jivesoftware.smack.SmackException; +import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.StanzaListener; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.filter.StanzaFilter; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.Stanza; @@ -847,7 +849,7 @@ public final class JingleSession extends JingleNegotiator implements MediaReceiv JingleTransportListener jingleTransportListener = new JingleTransportListener() { @Override - public void transportEstablished(TransportCandidate local, TransportCandidate remote) throws NotConnectedException, InterruptedException { + public void transportEstablished(TransportCandidate local, TransportCandidate remote) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException { if (isFullyEstablished()) { // CHECKSTYLE:OFF // Indicate that this session is active. diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/listeners/JingleSessionListener.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/listeners/JingleSessionListener.java index b51e6e9f6..fb754e489 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/listeners/JingleSessionListener.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/listeners/JingleSessionListener.java @@ -16,9 +16,10 @@ */ package org.jivesoftware.smackx.jingleold.listeners; +import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.XMPPException; - +import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smackx.jingleold.JingleSession; import org.jivesoftware.smackx.jingleold.media.PayloadType; import org.jivesoftware.smackx.jingleold.nat.TransportCandidate; @@ -39,9 +40,11 @@ public interface JingleSessionListener extends JingleListener { * @param jingleSession Session that called the method * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. + * @throws XMPPErrorException if there was an XMPP error returned. + * @throws NoResponseException if there was no response from the remote entity. */ void sessionEstablished(PayloadType pt, TransportCandidate remoteCandidate, - TransportCandidate localCandidate, JingleSession jingleSession) throws NotConnectedException, InterruptedException; + TransportCandidate localCandidate, JingleSession jingleSession) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException; /** * Notification that the session was declined. diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/listeners/JingleTransportListener.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/listeners/JingleTransportListener.java index e4ca3ca67..55478c276 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/listeners/JingleTransportListener.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/listeners/JingleTransportListener.java @@ -16,9 +16,10 @@ */ package org.jivesoftware.smackx.jingleold.listeners; +import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.XMPPException; - +import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smackx.jingleold.nat.TransportCandidate; /** @@ -37,9 +38,11 @@ public interface JingleTransportListener extends JingleListener { * transmitting to the remote machine * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. + * @throws XMPPErrorException if there was an XMPP error returned. + * @throws NoResponseException if there was no response from the remote entity. */ void transportEstablished(TransportCandidate local, - TransportCandidate remote) throws NotConnectedException, InterruptedException; + TransportCandidate remote) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException; /** * Notification that a transport must be cancelled. diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/BridgedResolver.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/BridgedResolver.java index 05482014f..542f2e9f8 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/BridgedResolver.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/BridgedResolver.java @@ -68,9 +68,10 @@ public class BridgedResolver extends TransportResolver { * The BridgedResolver takes the IP address and ports of a jmf proxy service. * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. + * @throws NoResponseException if there was no response from the remote entity. */ @Override - public synchronized void resolve(JingleSession session) throws XMPPException, NotConnectedException, InterruptedException { + public synchronized void resolve(JingleSession session) throws XMPPException, NotConnectedException, InterruptedException, NoResponseException { setResolveInit(); diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/BridgedTransportManager.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/BridgedTransportManager.java index faa18e8e0..151f6dff1 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/BridgedTransportManager.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/BridgedTransportManager.java @@ -16,10 +16,11 @@ */ package org.jivesoftware.smackx.jingleold.nat; +import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; - +import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smackx.jingleold.JingleSession; import org.jivesoftware.smackx.jingleold.listeners.CreatedJingleSessionListener; import org.jivesoftware.smackx.jingleold.listeners.JingleSessionListener; @@ -57,7 +58,7 @@ public class BridgedTransportManager extends JingleTransportManager implements J // Implement a Session Listener to relay candidates after establishment @Override - public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc, JingleSession jingleSession) throws NotConnectedException, InterruptedException { + public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc, JingleSession jingleSession) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException { RTPBridge rtpBridge = RTPBridge.relaySession(lc.getConnection(), lc.getSessionId(), lc.getPassword(), rc, lc); } diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/ICETransportManager.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/ICETransportManager.java index 1435d9e29..b8cb0f850 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/ICETransportManager.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/ICETransportManager.java @@ -20,10 +20,11 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.jivesoftware.smack.SmackException; +import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; - +import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smackx.jingleold.JingleSession; import org.jivesoftware.smackx.jingleold.listeners.CreatedJingleSessionListener; import org.jivesoftware.smackx.jingleold.listeners.JingleSessionListener; @@ -59,7 +60,7 @@ public class ICETransportManager extends JingleTransportManager implements Jingl // Implement a Session Listener to relay candidates after establishment @Override - public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc, JingleSession jingleSession) throws NotConnectedException, InterruptedException { + public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc, JingleSession jingleSession) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException { if (lc instanceof ICECandidate) { if (((ICECandidate) lc).getType().equals(ICECandidate.Type.relay)) { RTPBridge rtpBridge = RTPBridge.relaySession(lc.getConnection(), lc.getSessionId(), lc.getPassword(), rc, lc); diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/RTPBridge.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/RTPBridge.java index bee715507..0d3131231 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/RTPBridge.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/RTPBridge.java @@ -27,7 +27,6 @@ import java.util.logging.Logger; import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NotConnectedException; -import org.jivesoftware.smack.StanzaCollector; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.packet.IQ; @@ -400,8 +399,10 @@ public class RTPBridge extends IQ { * @return the new RTPBridge * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. + * @throws XMPPErrorException if there was an XMPP error returned. + * @throws NoResponseException if there was no response from the remote entity. */ - public static RTPBridge getRTPBridge(XMPPConnection connection, String sessionID) throws NotConnectedException, InterruptedException { + public static RTPBridge getRTPBridge(XMPPConnection connection, String sessionID) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException { if (!connection.isConnected()) { return null; @@ -416,12 +417,7 @@ public class RTPBridge extends IQ { } rtpPacket.setTo(jid); - StanzaCollector collector = connection.createStanzaCollectorAndSend(rtpPacket); - - RTPBridge response = collector.nextResult(); - - // Cancel the collector. - collector.cancel(); + RTPBridge response = connection.sendIqRequestAndWaitForResponse(rtpPacket); return response; } @@ -477,8 +473,10 @@ public class RTPBridge extends IQ { * @return the RTPBridge * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. + * @throws XMPPErrorException if there was an XMPP error returned. + * @throws NoResponseException if there was no response from the remote entity. */ - public static RTPBridge relaySession(XMPPConnection connection, String sessionID, String pass, TransportCandidate proxyCandidate, TransportCandidate localCandidate) throws NotConnectedException, InterruptedException { + public static RTPBridge relaySession(XMPPConnection connection, String sessionID, String pass, TransportCandidate proxyCandidate, TransportCandidate localCandidate) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException { if (!connection.isConnected()) { return null; @@ -502,12 +500,7 @@ public class RTPBridge extends IQ { // LOGGER.debug("Relayed to: " + candidate.getIp() + ":" + candidate.getPort()); - StanzaCollector collector = connection.createStanzaCollectorAndSend(rtpPacket); - - RTPBridge response = collector.nextResult(); - - // Cancel the collector. - collector.cancel(); + RTPBridge response = connection.sendIqRequestAndWaitForResponse(rtpPacket); return response; } @@ -519,8 +512,10 @@ public class RTPBridge extends IQ { * @return public IP String or null if not found * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. + * @throws XMPPErrorException if there was an XMPP error returned. + * @throws NoResponseException if there was no response from the remote entity. */ - public static String getPublicIP(XMPPConnection xmppConnection) throws NotConnectedException, InterruptedException { + public static String getPublicIP(XMPPConnection xmppConnection) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException { if (!xmppConnection.isConnected()) { return null; @@ -538,12 +533,7 @@ public class RTPBridge extends IQ { // LOGGER.debug("Relayed to: " + candidate.getIp() + ":" + candidate.getPort()); - StanzaCollector collector = xmppConnection.createStanzaCollectorAndSend(rtpPacket); - - RTPBridge response = collector.nextResult(); - - // Cancel the collector. - collector.cancel(); + RTPBridge response = xmppConnection.sendIqRequestAndWaitForResponse(rtpPacket); if (response == null) return null; diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/STUN.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/STUN.java index ec1080f47..7aa4166f8 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/STUN.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/STUN.java @@ -22,10 +22,11 @@ import java.util.List; import java.util.logging.Logger; import org.jivesoftware.smack.SmackException; +import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NotConnectedException; -import org.jivesoftware.smack.StanzaCollector; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.packet.SimpleIQ; import org.jivesoftware.smack.packet.XmlEnvironment; import org.jivesoftware.smack.provider.IQProvider; @@ -180,8 +181,10 @@ public class STUN extends SimpleIQ { * @return the STUN server address * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. + * @throws XMPPErrorException if there was an XMPP error returned. + * @throws NoResponseException if there was no response from the remote entity. */ - public static STUN getSTUNServer(XMPPConnection connection) throws NotConnectedException, InterruptedException { + public static STUN getSTUNServer(XMPPConnection connection) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException { if (!connection.isConnected()) { return null; @@ -196,12 +199,7 @@ public class STUN extends SimpleIQ { } stunPacket.setTo(jid); - StanzaCollector collector = connection.createStanzaCollectorAndSend(stunPacket); - - STUN response = collector.nextResult(); - - // Cancel the collector. - collector.cancel(); + STUN response = connection.sendIqRequestAndWaitForResponse(stunPacket); return response; } diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TransportNegotiator.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TransportNegotiator.java index 6890de67b..127a7364c 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TransportNegotiator.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TransportNegotiator.java @@ -25,8 +25,10 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.jivesoftware.smack.SmackException; +import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smackx.jingleold.ContentNegotiator; @@ -346,7 +348,7 @@ public abstract class TransportNegotiator extends JingleNegotiator { try { triggerTransportEstablished(getAcceptedLocalCandidate(), bestRemote); } - catch (InterruptedException | NotConnectedException e) { + catch (InterruptedException | NotConnectedException | NoResponseException | XMPPErrorException e) { throw new IllegalStateException(e); } break; @@ -801,8 +803,10 @@ public abstract class TransportNegotiator extends JingleNegotiator { * @param remote TransportCandidate that has been agreed. * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. + * @throws XMPPErrorException if there was an XMPP error returned. + * @throws NoResponseException if there was no response from the remote entity. */ - private void triggerTransportEstablished(TransportCandidate local, TransportCandidate remote) throws NotConnectedException, InterruptedException { + private void triggerTransportEstablished(TransportCandidate local, TransportCandidate remote) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException { List listeners = getListenersList(); for (JingleListener li : listeners) { if (li instanceof JingleTransportListener) { diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/Agent.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/Agent.java index 94d1c96f3..1382b549c 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/Agent.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/Agent.java @@ -43,7 +43,7 @@ public class Agent { public static Collection getWorkgroups(Jid serviceJID, Jid agentJID, XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { AgentWorkgroups request = new AgentWorkgroups(agentJID); request.setTo(serviceJID); - AgentWorkgroups response = connection.createStanzaCollectorAndSend(request).nextResultOrThrow(); + AgentWorkgroups response = connection.sendIqRequestAndWaitForResponse(request); return response.getWorkgroups(); } @@ -78,7 +78,7 @@ public class Agent { agentInfo.setType(IQ.Type.get); agentInfo.setTo(workgroupJID); agentInfo.setFrom(getUser()); - AgentInfo response = connection.createStanzaCollectorAndSend(agentInfo).nextResultOrThrow(); + AgentInfo response = connection.sendIqRequestAndWaitForResponse(agentInfo); return response.getName(); } @@ -100,6 +100,6 @@ public class Agent { agentInfo.setTo(workgroupJID); agentInfo.setFrom(getUser()); agentInfo.setName(newName); - connection.createStanzaCollectorAndSend(agentInfo).nextResultOrThrow(); + connection.sendIqRequestAndWaitForResponse(agentInfo); } } diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentSession.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentSession.java index ad52c8200..4c2e57c52 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentSession.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentSession.java @@ -596,7 +596,7 @@ public class AgentSession { request.setType(IQ.Type.get); request.setTo(workgroupJID); - OccupantsInfo response = (OccupantsInfo) connection.createStanzaCollectorAndSend(request).nextResultOrThrow(); + OccupantsInfo response = (OccupantsInfo) connection.sendIqRequestAndWaitForResponse(request); return response; } @@ -868,7 +868,7 @@ public class AgentSession { notes.setTo(workgroupJID); notes.setSessionID(sessionID); notes.setNotes(note); - connection.createStanzaCollectorAndSend(notes).nextResultOrThrow(); + connection.sendIqRequestAndWaitForResponse(notes); } /** @@ -887,7 +887,7 @@ public class AgentSession { request.setTo(workgroupJID); request.setSessionID(sessionID); - ChatNotes response = connection.createStanzaCollectorAndSend(request).nextResultOrThrow(); + ChatNotes response = connection.sendIqRequestAndWaitForResponse(request); return response; } @@ -901,8 +901,9 @@ public class AgentSession { * @throws XMPPException if an error occurs while retrieving the AgentChatHistory. * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. + * @throws NoResponseException if there was no response from the remote entity. */ - public AgentChatHistory getAgentHistory(EntityBareJid jid, int maxSessions, Date startDate) throws XMPPException, NotConnectedException, InterruptedException { + public AgentChatHistory getAgentHistory(EntityBareJid jid, int maxSessions, Date startDate) throws XMPPException, NotConnectedException, InterruptedException, NoResponseException { AgentChatHistory request; if (startDate != null) { request = new AgentChatHistory(jid, maxSessions, startDate); @@ -914,8 +915,8 @@ public class AgentSession { request.setType(IQ.Type.get); request.setTo(workgroupJID); - AgentChatHistory response = connection.createStanzaCollectorAndSend( - request).nextResult(); + AgentChatHistory response = connection.sendIqRequestAndWaitForResponse( + request); return response; } @@ -934,7 +935,7 @@ public class AgentSession { request.setType(IQ.Type.get); request.setTo(workgroupJID); - SearchSettings response = connection.createStanzaCollectorAndSend(request).nextResultOrThrow(); + SearchSettings response = connection.sendIqRequestAndWaitForResponse(request); return response; } @@ -954,7 +955,7 @@ public class AgentSession { request.setTo(workgroupJID); request.setPersonal(!global); - Macros response = connection.createStanzaCollectorAndSend(request).nextResultOrThrow(); + Macros response = connection.sendIqRequestAndWaitForResponse(request); return response.getRootGroup(); } @@ -974,7 +975,7 @@ public class AgentSession { request.setPersonal(true); request.setPersonalMacroGroup(group); - connection.createStanzaCollectorAndSend(request).nextResultOrThrow(); + connection.sendIqRequestAndWaitForResponse(request); } /** @@ -985,14 +986,15 @@ public class AgentSession { * @throws XMPPException if an error occurs while getting information from the server. * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. + * @throws NoResponseException if there was no response from the remote entity. */ - public Map> getChatMetadata(String sessionID) throws XMPPException, NotConnectedException, InterruptedException { + public Map> getChatMetadata(String sessionID) throws XMPPException, NotConnectedException, InterruptedException, NoResponseException { ChatMetadata request = new ChatMetadata(); request.setType(IQ.Type.get); request.setTo(workgroupJID); request.setSessionID(sessionID); - ChatMetadata response = connection.createStanzaCollectorAndSend(request).nextResult(); + ChatMetadata response = connection.sendIqRequestAndWaitForResponse(request); return response.getMetadata(); } @@ -1033,7 +1035,7 @@ public class AgentSession { iq.setTo(workgroupJID); iq.setFrom(connection.getUser()); - connection.createStanzaCollectorAndSend(iq).nextResultOrThrow(); + connection.sendIqRequestAndWaitForResponse(iq); } /** @@ -1070,7 +1072,7 @@ public class AgentSession { iq.setTo(workgroupJID); iq.setFrom(connection.getUser()); - connection.createStanzaCollectorAndSend(iq).nextResultOrThrow(); + connection.sendIqRequestAndWaitForResponse(iq); } /** @@ -1089,8 +1091,8 @@ public class AgentSession { setting.setType(IQ.Type.get); setting.setTo(workgroupJID); - GenericSettings response = connection.createStanzaCollectorAndSend( - setting).nextResultOrThrow(); + GenericSettings response = connection.sendIqRequestAndWaitForResponse( + setting); return response; } @@ -1099,7 +1101,7 @@ public class AgentSession { request.setType(IQ.Type.get); request.setTo(workgroupJID); - MonitorPacket response = connection.createStanzaCollectorAndSend(request).nextResultOrThrow(); + MonitorPacket response = connection.sendIqRequestAndWaitForResponse(request); return response.isMonitor(); } @@ -1109,6 +1111,6 @@ public class AgentSession { request.setTo(workgroupJID); request.setSessionID(sessionID); - connection.createStanzaCollectorAndSend(request).nextResultOrThrow(); + connection.sendIqRequestAndWaitForResponse(request); } } diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/TranscriptManager.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/TranscriptManager.java index e9b59af28..cba2756fd 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/TranscriptManager.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/TranscriptManager.java @@ -56,7 +56,7 @@ public class TranscriptManager { public Transcript getTranscript(EntityBareJid workgroupJID, String sessionID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { Transcript request = new Transcript(sessionID); request.setTo(workgroupJID); - Transcript response = connection.createStanzaCollectorAndSend(request).nextResultOrThrow(); + Transcript response = connection.sendIqRequestAndWaitForResponse(request); return response; } @@ -75,7 +75,7 @@ public class TranscriptManager { public Transcripts getTranscripts(EntityBareJid workgroupJID, Jid userID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { Transcripts request = new Transcripts(userID); request.setTo(workgroupJID); - Transcripts response = connection.createStanzaCollectorAndSend(request).nextResultOrThrow(); + Transcripts response = connection.sendIqRequestAndWaitForResponse(request); return response; } } diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/TranscriptSearchManager.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/TranscriptSearchManager.java index c2456f8b3..33be9730a 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/TranscriptSearchManager.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/TranscriptSearchManager.java @@ -61,8 +61,8 @@ public class TranscriptSearchManager { search.setType(IQ.Type.get); search.setTo(serviceJID); - TranscriptSearch response = connection.createStanzaCollectorAndSend( - search).nextResultOrThrow(); + TranscriptSearch response = connection.sendIqRequestAndWaitForResponse( + search); return Form.from(response); } @@ -85,8 +85,8 @@ public class TranscriptSearchManager { search.setTo(serviceJID); search.addExtension(completedForm.getDataFormToSubmit()); - TranscriptSearch response = connection.createStanzaCollectorAndSend( - search).nextResultOrThrow(); + TranscriptSearch response = connection.sendIqRequestAndWaitForResponse( + search); return ReportedData.getReportedDataFrom(response); } } diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/user/Workgroup.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/user/Workgroup.java index 6244a622c..9ca424c18 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/user/Workgroup.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/user/Workgroup.java @@ -355,7 +355,7 @@ public class Workgroup { JoinQueuePacket joinPacket = new JoinQueuePacket(workgroupJID, answerForm, userID); - connection.createStanzaCollectorAndSend(joinPacket).nextResultOrThrow(); + connection.sendIqRequestAndWaitForResponse(joinPacket); // Notify listeners that we've joined the queue. fireQueueJoinedEvent(); } @@ -436,7 +436,7 @@ public class Workgroup { } DepartQueuePacket departPacket = new DepartQueuePacket(this.workgroupJID); - connection.createStanzaCollectorAndSend(departPacket).nextResultOrThrow(); + connection.sendIqRequestAndWaitForResponse(departPacket); // Notify listeners that we're no longer in the queue. fireQueueDepartedEvent(); @@ -657,7 +657,7 @@ public class Workgroup { request.setType(IQ.Type.get); request.setTo(workgroupJID); - ChatSettings response = connection.createStanzaCollectorAndSend(request).nextResultOrThrow(); + ChatSettings response = connection.sendIqRequestAndWaitForResponse(request); return response; } @@ -697,7 +697,7 @@ public class Workgroup { request.setType(IQ.Type.get); request.setTo(workgroupJID); - return connection.createStanzaCollectorAndSend(request).nextResultOrThrow(); + return connection.sendIqRequestAndWaitForResponse(request); } /** @@ -714,7 +714,7 @@ public class Workgroup { request.setType(IQ.Type.get); request.setTo(workgroupJID); - return connection.createStanzaCollectorAndSend(request).nextResultOrThrow(); + return connection.sendIqRequestAndWaitForResponse(request); } /** @@ -731,7 +731,7 @@ public class Workgroup { request.setType(IQ.Type.get); request.setTo(workgroupJID); - return connection.createStanzaCollectorAndSend(request).nextResultOrThrow(); + return connection.sendIqRequestAndWaitForResponse(request); } /** @@ -750,8 +750,8 @@ public class Workgroup { request.setType(IQ.Type.get); request.setTo(workgroupJID); - return connection.createStanzaCollectorAndSend( - request).nextResultOrThrow(); + return connection.sendIqRequestAndWaitForResponse( + request); } @@ -771,8 +771,8 @@ public class Workgroup { workgroupForm.setType(IQ.Type.get); workgroupForm.setTo(workgroupJID); - WorkgroupForm response = connection.createStanzaCollectorAndSend( - workgroupForm).nextResultOrThrow(); + WorkgroupForm response = connection.sendIqRequestAndWaitForResponse( + workgroupForm); return Form.from(response); } }