From def8fea05f5ca5f9d52b53f8f9600181789c9fbc Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 12 Nov 2014 12:27:36 +0100 Subject: [PATCH] Add reply timeout to NoResponseException message --- .../org/jivesoftware/smack/AbstractXMPPConnection.java | 2 +- .../java/org/jivesoftware/smack/PacketCollector.java | 2 +- .../org/jivesoftware/smack/SASLAuthentication.java | 6 +++--- .../java/org/jivesoftware/smack/SmackException.java | 10 ++++++---- .../org/jivesoftware/smack/SynchronizationPoint.java | 2 +- .../smackx/filetransfer/FaultTolerantNegotiator.java | 8 ++++---- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java index 1f2f27ddc..e506b213e 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java @@ -1185,7 +1185,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { // If the packetListener got removed, then it was never run and // we never received a response, inform the exception callback if (removed && exceptionCallback != null) { - exceptionCallback.processException(new NoResponseException()); + exceptionCallback.processException(new NoResponseException(AbstractXMPPConnection.this)); } } }, timeout, TimeUnit.MILLISECONDS); diff --git a/smack-core/src/main/java/org/jivesoftware/smack/PacketCollector.java b/smack-core/src/main/java/org/jivesoftware/smack/PacketCollector.java index 0ea20ee69..21294e8ae 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/PacketCollector.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/PacketCollector.java @@ -191,7 +191,7 @@ public class PacketCollector { P result = nextResult(timeout); cancel(); if (result == null) { - throw new NoResponseException(); + throw new NoResponseException(connection); } XMPPErrorException.ifHasErrorThenThrow(result); diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java b/smack-core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java index d01f9b8bf..5417d9dea 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java @@ -197,7 +197,7 @@ public class SASLAuthentication { maybeThrowException(); if (!authenticationSuccessful) { - throw new NoResponseException(); + throw new NoResponseException(connection); } } else { @@ -244,7 +244,7 @@ public class SASLAuthentication { maybeThrowException(); if (!authenticationSuccessful) { - throw new NoResponseException(); + throw new NoResponseException(connection); } } else { @@ -283,7 +283,7 @@ public class SASLAuthentication { maybeThrowException(); if (!authenticationSuccessful) { - throw new NoResponseException(); + throw new NoResponseException(connection); } } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SmackException.java b/smack-core/src/main/java/org/jivesoftware/smack/SmackException.java index 90d5432d7..807f68ef1 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/SmackException.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/SmackException.java @@ -54,8 +54,9 @@ public class SmackException extends Exception { } /** - * Exception thrown always when there was no response to an (IQ) request within the packet reply - * timeout of the used connection instance. + * Exception thrown always when there was no response to an request within the packet reply timeout of the used + * connection instance. You can modify (e.g. increase) the packet reply timeout with + * {@link XMPPConnection#setPacketReplyTimeout(long)}. */ public static class NoResponseException extends SmackException { /** @@ -63,8 +64,9 @@ public class SmackException extends Exception { */ private static final long serialVersionUID = -6523363748984543636L; - public NoResponseException() { - super("No response received within packet reply timeout"); + public NoResponseException(XMPPConnection connection) { + super("No response received within packet reply timeout. Timeout was " + connection.getPacketReplyTimeout() + + "ms (~" + connection.getPacketReplyTimeout() / 1000 + "s)"); } } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SynchronizationPoint.java b/smack-core/src/main/java/org/jivesoftware/smack/SynchronizationPoint.java index 4037fb64d..b0e4506d1 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/SynchronizationPoint.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/SynchronizationPoint.java @@ -173,7 +173,7 @@ public class SynchronizationPoint { case Initial: case NoResponse: case RequestSent: - throw new NoResponseException(); + throw new NoResponseException(connection); default: // Do nothing break; diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FaultTolerantNegotiator.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FaultTolerantNegotiator.java index 3a9792ca5..05f6585d4 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FaultTolerantNegotiator.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FaultTolerantNegotiator.java @@ -48,9 +48,9 @@ import org.jivesoftware.smackx.si.packet.StreamInitiation; */ public class FaultTolerantNegotiator extends StreamNegotiator { - private StreamNegotiator primaryNegotiator; - private StreamNegotiator secondaryNegotiator; - private XMPPConnection connection; + private final StreamNegotiator primaryNegotiator; + private final StreamNegotiator secondaryNegotiator; + private final XMPPConnection connection; private PacketFilter primaryFilter; private PacketFilter secondaryFilter; @@ -178,7 +178,7 @@ public class FaultTolerantNegotiator extends StreamNegotiator { public InputStream call() throws XMPPErrorException, InterruptedException, SmackException { Packet streamInitiation = collector.nextResult(); if (streamInitiation == null) { - throw new NoResponseException(); + throw new NoResponseException(connection); } StreamNegotiator negotiator = determineNegotiator(streamInitiation); return negotiator.negotiateIncomingStream(streamInitiation);