1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-09 00:59:39 +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

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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<JingleListener> listeners = getListenersList();
for (JingleListener li : listeners) {
if (li instanceof JingleTransportListener) {