From d04517cd0853e198aac8a620f1f695efaaa9887c Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sun, 5 Oct 2014 17:00:13 +0200 Subject: [PATCH] Add message String to all SmackExceptions SMACK-599 --- .../jivesoftware/smack/SmackException.java | 37 ++++++++++++++++--- .../smack/tcp/XMPPTCPConnection.java | 7 ++-- 2 files changed, 36 insertions(+), 8 deletions(-) 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 3a638bdbf..90d5432d7 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/SmackException.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/SmackException.java @@ -54,7 +54,7 @@ public class SmackException extends Exception { } /** - * Exception thrown always when there was no response to an IQ request within the packet reply + * Exception thrown always when there was no response to an (IQ) request within the packet reply * timeout of the used connection instance. */ public static class NoResponseException extends SmackException { @@ -64,6 +64,7 @@ public class SmackException extends Exception { private static final long serialVersionUID = -6523363748984543636L; public NoResponseException() { + super("No response received within packet reply timeout"); } } @@ -75,6 +76,7 @@ public class SmackException extends Exception { private static final long serialVersionUID = 3216216839100019278L; public NotLoggedInException() { + super("Client is not logged in"); } } @@ -86,6 +88,7 @@ public class SmackException extends Exception { private static final long serialVersionUID = 5011416918049935231L; public AlreadyLoggedInException() { + super("Client is already logged in"); } } @@ -97,6 +100,7 @@ public class SmackException extends Exception { private static final long serialVersionUID = 5011416918049135231L; public AlreadyConnectedException() { + super("Client is already connected"); } } @@ -108,6 +112,7 @@ public class SmackException extends Exception { private static final long serialVersionUID = 9197980400776001173L; public NotConnectedException() { + super("Client is not, or no longer, connected"); } } @@ -122,21 +127,40 @@ public class SmackException extends Exception { } } - public static class SecurityRequiredException extends SmackException { + public static abstract class SecurityRequiredException extends SmackException { /** * */ private static final long serialVersionUID = 384291845029773545L; - public SecurityRequiredException() { - } - public SecurityRequiredException(String message) { super(message); } } + public static class SecurityRequiredByClientException extends SecurityRequiredException { + /** + * + */ + private static final long serialVersionUID = 2395325821201543159L; + + public SecurityRequiredByClientException() { + super("SSL/TLS required by client but not supported by server"); + } + } + + public static class SecurityRequiredByServerException extends SecurityRequiredException { + /** + * + */ + private static final long serialVersionUID = 8268148813117631819L; + + public SecurityRequiredByServerException() { + super("SSL/TLS required by server but disabled in client"); + } + } + public static class SecurityNotPossibleException extends SmackException { /** @@ -238,5 +262,8 @@ public class SmackException extends Exception { */ private static final long serialVersionUID = 2346934138253437571L; + public ResourceBindingNotOfferedException() { + super("Resource binding was not offered by server"); + } } } diff --git a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java index b7e2afb66..42eecd238 100644 --- a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java +++ b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java @@ -29,6 +29,8 @@ import org.jivesoftware.smack.SmackException.AlreadyLoggedInException; import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.SmackException.ConnectionException; +import org.jivesoftware.smack.SmackException.SecurityRequiredByClientException; +import org.jivesoftware.smack.SmackException.SecurityRequiredByServerException; import org.jivesoftware.smack.SmackException.SecurityRequiredException; import org.jivesoftware.smack.SynchronizationPoint; import org.jivesoftware.smack.XMPPException.StreamErrorException; @@ -922,8 +924,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { StartTls startTlsFeature = getFeature(StartTls.ELEMENT, StartTls.NAMESPACE); if (startTlsFeature != null) { if (startTlsFeature.required() && config.getSecurityMode() == SecurityMode.disabled) { - notifyConnectionError(new SecurityRequiredException( - "TLS required by server but not allowed by connection configuration")); + notifyConnectionError(new SecurityRequiredByServerException()); return; } @@ -938,7 +939,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { // and are secure, however (features get parsed a second time after TLS is established). if (!isSecureConnection() && startTlsFeature == null && getConfiguration().getSecurityMode() == SecurityMode.required) { - throw new SecurityRequiredException(); + throw new SecurityRequiredByClientException(); } if (getSASLAuthentication().authenticationSuccessful()) {