mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-21 19:42:05 +01:00
Improve NoResponseException messages
This commit is contained in:
parent
2079ba6bd6
commit
9a00e09c0a
6 changed files with 37 additions and 21 deletions
|
@ -194,13 +194,13 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
* parsed.
|
||||
*/
|
||||
protected final SynchronizationPoint<Exception> lastFeaturesReceived = new SynchronizationPoint<Exception>(
|
||||
AbstractXMPPConnection.this);
|
||||
AbstractXMPPConnection.this, "last stream features received from server");
|
||||
|
||||
/**
|
||||
* Set to success if the sasl feature has been received.
|
||||
*/
|
||||
protected final SynchronizationPoint<SmackException> saslFeatureReceived = new SynchronizationPoint<SmackException>(
|
||||
AbstractXMPPConnection.this);
|
||||
AbstractXMPPConnection.this, "SASL mechanisms stream feature from server");
|
||||
|
||||
/**
|
||||
* The SASLAuthentication manager that is responsible for authenticating with the server.
|
||||
|
|
|
@ -207,7 +207,7 @@ public final class SASLAuthentication {
|
|||
}
|
||||
|
||||
if (!authenticationSuccessful) {
|
||||
throw NoResponseException.newWith(connection);
|
||||
throw NoResponseException.newWith(connection, "successful SASL authentication");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2014 Florian Schmaus
|
||||
* Copyright 2014-2015 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -68,6 +68,10 @@ public class SmackException extends Exception {
|
|||
|
||||
private final StanzaFilter filter;
|
||||
|
||||
private NoResponseException(String message) {
|
||||
this(message, null);
|
||||
}
|
||||
|
||||
private NoResponseException(String message, StanzaFilter filter) {
|
||||
super(message);
|
||||
this.filter = filter;
|
||||
|
@ -82,8 +86,10 @@ public class SmackException extends Exception {
|
|||
return filter;
|
||||
}
|
||||
|
||||
public static NoResponseException newWith(XMPPConnection connection) {
|
||||
return newWith(connection, (StanzaFilter) null);
|
||||
public static NoResponseException newWith(XMPPConnection connection, String waitingFor) {
|
||||
final StringBuilder sb = getWaitingFor(connection);
|
||||
sb.append(" While waiting for ").append(waitingFor);
|
||||
return new NoResponseException(sb.toString());
|
||||
}
|
||||
|
||||
public static NoResponseException newWith(XMPPConnection connection,
|
||||
|
@ -92,11 +98,8 @@ public class SmackException extends Exception {
|
|||
}
|
||||
|
||||
public static NoResponseException newWith(XMPPConnection connection, StanzaFilter filter) {
|
||||
final long replyTimeout = connection.getPacketReplyTimeout();
|
||||
final StringBuilder sb = new StringBuilder(256);
|
||||
sb.append("No response received within reply timeout. Timeout was "
|
||||
+ replyTimeout + "ms (~"
|
||||
+ replyTimeout / 1000 + "s). Used filter: ");
|
||||
final StringBuilder sb = getWaitingFor(connection);
|
||||
sb.append(" Waited for response using: ");
|
||||
if (filter != null) {
|
||||
sb.append(filter.toString());
|
||||
}
|
||||
|
@ -107,6 +110,14 @@ public class SmackException extends Exception {
|
|||
return new NoResponseException(sb.toString(), filter);
|
||||
}
|
||||
|
||||
private static StringBuilder getWaitingFor(XMPPConnection connection) {
|
||||
final long replyTimeout = connection.getPacketReplyTimeout();
|
||||
final StringBuilder sb = new StringBuilder(256);
|
||||
sb.append("No response received within reply timeout. Timeout was "
|
||||
+ replyTimeout + "ms (~"
|
||||
+ replyTimeout / 1000 + "s).");
|
||||
return sb;
|
||||
}
|
||||
}
|
||||
|
||||
public static class NotLoggedInException extends SmackException {
|
||||
|
|
|
@ -31,6 +31,7 @@ public class SynchronizationPoint<E extends Exception> {
|
|||
private final AbstractXMPPConnection connection;
|
||||
private final Lock connectionLock;
|
||||
private final Condition condition;
|
||||
private final String waitFor;
|
||||
|
||||
// Note that there is no need to make 'state' and 'failureException' volatile. Since 'lock' and 'unlock' have the
|
||||
// same memory synchronization effects as synchronization block enter and leave.
|
||||
|
@ -41,11 +42,13 @@ public class SynchronizationPoint<E extends Exception> {
|
|||
* Construct a new synchronization point for the given connection.
|
||||
*
|
||||
* @param connection the connection of this synchronization point.
|
||||
* @param waitFor a description of the event this synchronization point handles.
|
||||
*/
|
||||
public SynchronizationPoint(AbstractXMPPConnection connection) {
|
||||
public SynchronizationPoint(AbstractXMPPConnection connection, String waitFor) {
|
||||
this.connection = connection;
|
||||
this.connectionLock = connection.getConnectionLock();
|
||||
this.condition = connection.getConnectionLock().newCondition();
|
||||
this.waitFor = waitFor;
|
||||
init();
|
||||
}
|
||||
|
||||
|
@ -253,7 +256,7 @@ public class SynchronizationPoint<E extends Exception> {
|
|||
case Initial:
|
||||
case NoResponse:
|
||||
case RequestSent:
|
||||
throw NoResponseException.newWith(connection);
|
||||
throw NoResponseException.newWith(connection, waitFor);
|
||||
case Success:
|
||||
return true;
|
||||
case Failure:
|
||||
|
|
|
@ -114,7 +114,7 @@ public abstract class StreamNegotiator {
|
|||
}
|
||||
|
||||
if (streamMethodInitiation == null) {
|
||||
throw NoResponseException.newWith(connection);
|
||||
throw NoResponseException.newWith(connection, "stream initiation");
|
||||
}
|
||||
XMPPErrorException.ifHasErrorThenThrow(streamMethodInitiation);
|
||||
return streamMethodInitiation;
|
||||
|
|
|
@ -174,25 +174,27 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
|||
*/
|
||||
protected PacketReader packetReader;
|
||||
|
||||
private final SynchronizationPoint<Exception> initalOpenStreamSend = new SynchronizationPoint<Exception>(this);
|
||||
private final SynchronizationPoint<Exception> initalOpenStreamSend = new SynchronizationPoint<>(
|
||||
this, "initial open stream element send to server");
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private final SynchronizationPoint<XMPPException> maybeCompressFeaturesReceived = new SynchronizationPoint<XMPPException>(
|
||||
this);
|
||||
this, "stream compression feature");
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private final SynchronizationPoint<XMPPException> compressSyncPoint = new SynchronizationPoint<XMPPException>(
|
||||
this);
|
||||
this, "stream compression");
|
||||
|
||||
/**
|
||||
* A synchronization point which is successful if this connection has received the closing
|
||||
* stream element from the remote end-point, i.e. the server.
|
||||
*/
|
||||
private final SynchronizationPoint<Exception> closingStreamReceived = new SynchronizationPoint<Exception>(this);
|
||||
private final SynchronizationPoint<Exception> closingStreamReceived = new SynchronizationPoint<>(
|
||||
this, "stream closing element received");
|
||||
|
||||
/**
|
||||
* The default bundle and defer callback, used for new connections.
|
||||
|
@ -221,10 +223,10 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
|||
private String smSessionId;
|
||||
|
||||
private final SynchronizationPoint<XMPPException> smResumedSyncPoint = new SynchronizationPoint<XMPPException>(
|
||||
this);
|
||||
this, "stream resumed element");
|
||||
|
||||
private final SynchronizationPoint<XMPPException> smEnabledSyncPoint = new SynchronizationPoint<XMPPException>(
|
||||
this);
|
||||
this, "stream enabled element");
|
||||
|
||||
/**
|
||||
* The client's preferred maximum resumption time in seconds.
|
||||
|
@ -1169,7 +1171,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
|||
* Needs to be protected for unit testing purposes.
|
||||
*/
|
||||
protected SynchronizationPoint<NoResponseException> shutdownDone = new SynchronizationPoint<NoResponseException>(
|
||||
XMPPTCPConnection.this);
|
||||
XMPPTCPConnection.this, "shutdown completed");
|
||||
|
||||
/**
|
||||
* If set, the stanza(/packet) writer is shut down
|
||||
|
|
Loading…
Reference in a new issue