1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-09-09 10:19:41 +02:00

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.
This commit is contained in:
Florian Schmaus 2021-05-11 22:03:24 +02:00
parent c9ea1c11b6
commit aab48570c9
53 changed files with 206 additions and 188 deletions

View file

@ -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<Jid> 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<Jid> 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) {

View file

@ -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);

View file

@ -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);

View file

@ -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

View file

@ -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) {

View file

@ -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);
}
/**

View file

@ -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.

View file

@ -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;
}

View file

@ -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);
}
/**

View file

@ -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() {

View file

@ -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) {

View file

@ -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);
}
/*

View file

@ -119,7 +119,7 @@ public final class JingleS5BTransportManager extends JingleTransportManager<Jing
request.setType(IQ.Type.get);
request.setTo(proxy);
try {
Bytestream response = connection.createStanzaCollectorAndSend(request).nextResultOrThrow();
Bytestream response = connection.sendIqRequestAndWaitForResponse(request);
streamHosts.addAll(response.getStreamHosts());
}
catch (Exception e) {

View file

@ -137,8 +137,7 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
Jingle jingle = transportManager().createCandidateUsed(jingleSession.getRemote(), jingleSession.getInitiator(), jingleSession.getSessionId(),
content.getSenders(), content.getCreator(), content.getName(), theirProposal.getStreamId(), ourChoice.candidate.getCandidateId());
try {
jingleSession.getConnection().createStanzaCollectorAndSend(jingle)
.nextResultOrThrow();
jingleSession.getConnection().sendIqRequestAndWaitForResponse(jingle);
} catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) {
LOGGER.log(Level.WARNING, "Could not send candidate-used.", e);
}
@ -303,7 +302,7 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
activate.setToActivate(jingleSession.getRemote());
activate.setFrom(jingleSession.getLocal());
try {
jingleSession.getConnection().createStanzaCollectorAndSend(activate).nextResultOrThrow();
jingleSession.getConnection().sendIqRequestAndWaitForResponse(activate);
} catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) {
LOGGER.log(Level.WARNING, "Could not activate proxy.", e);
return;
@ -315,8 +314,7 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
content.getSenders(), content.getCreator(), content.getName(), nominated.transport.getStreamId(),
nominated.candidate.getCandidateId());
try {
jingleSession.getConnection().createStanzaCollectorAndSend(candidateActivate)
.nextResultOrThrow();
jingleSession.getConnection().sendIqRequestAndWaitForResponse(candidateActivate);
} catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) {
LOGGER.log(Level.WARNING, "Could not send candidate-activated", e);
return;

View file

@ -838,7 +838,7 @@ public class MultiUserChat {
iq.setTo(room);
iq.setType(IQ.Type.get);
IQ answer = connection.createStanzaCollectorAndSend(iq).nextResultOrThrow();
IQ answer = connection.sendIqRequestAndWaitForResponse(iq);
DataForm dataForm = DataForm.from(answer, MucConfigFormManager.FORM_TYPE);
return new Form(dataForm);
}
@ -867,7 +867,7 @@ public class MultiUserChat {
iq.setType(IQ.Type.set);
iq.addExtension(dataForm);
connection.createStanzaCollectorAndSend(iq).nextResultOrThrow();
connection.sendIqRequestAndWaitForResponse(iq);
}
/**
@ -892,7 +892,7 @@ public class MultiUserChat {
reg.setType(IQ.Type.get);
reg.setTo(room);
IQ result = connection.createStanzaCollectorAndSend(reg).nextResultOrThrow();
IQ result = connection.sendIqRequestAndWaitForResponse(reg);
DataForm dataForm = DataForm.from(result);
return new Form(dataForm);
}
@ -920,7 +920,7 @@ public class MultiUserChat {
reg.setTo(room);
reg.addExtension(form.getDataFormToSubmit());
connection.createStanzaCollectorAndSend(reg).nextResultOrThrow();
connection.sendIqRequestAndWaitForResponse(reg);
}
/**
@ -965,7 +965,7 @@ public class MultiUserChat {
iq.setDestroy(destroy);
try {
connection.createStanzaCollectorAndSend(iq).nextResultOrThrow();
connection.sendIqRequestAndWaitForResponse(iq);
}
catch (XMPPErrorException e) {
// Note that we do not call userHasLeft() here because an XMPPErrorException would usually indicate that the
@ -1718,7 +1718,7 @@ public class MultiUserChat {
MUCItem item = new MUCItem(affiliation, jid, reason);
iq.addItem(item);
connection.createStanzaCollectorAndSend(iq).nextResultOrThrow();
connection.sendIqRequestAndWaitForResponse(iq);
}
private void changeAffiliationByAdmin(Collection<? extends Jid> 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<Resourcepart> 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<Affiliate> affiliates = new ArrayList<Affiliate>();
@ -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<Occupant> participants = new ArrayList<Occupant>();
for (MUCItem mucadminItem : answer.getItems()) {

View file

@ -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);
}
}

View file

@ -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);
}
/**

View file

@ -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 <T extends Item> List<T> getItems(PubSub request,
List<XmlElement> 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 <T extends Item> void publish(Collection<T> 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);
}
}

View file

@ -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);
}
/**

View file

@ -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;
}

View file

@ -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();
}

View file

@ -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();
}
}

View file

@ -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);
}
}

View file

@ -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;
}

View file

@ -129,6 +129,17 @@ public class ConnectionUtils {
when(collector.nextResultOrThrow()).thenAnswer(answerOrThrow);
when(collector.nextResultOrThrow(anyLong())).thenAnswer(answerOrThrow);
Answer<IQ> responseIq = new Answer<IQ>() {
@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);