From 181d58c996cdeac25ea7e4d1cc2595e6db287a7e Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 26 Aug 2015 21:35:54 +0200 Subject: [PATCH] Don't log a compression releated warning if the server doesn't support stream compression. --- .../smack/tcp/XMPPTCPConnection.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) 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 9f4a1f1fc..81bd7c08a 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 @@ -371,9 +371,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { // If compression is enabled then request the server to use stream compression. XEP-170 // recommends to perform stream compression before resource binding. - if (config.isCompressionEnabled()) { - useCompression(); - } + maybeEnableCompression(); if (isSmResumptionPossible()) { smResumedSyncPoint.sendAndWaitForResponse(new Resume(clientHandledStanzasCount, smSessionId)); @@ -739,12 +737,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { * @return a instance of XMPPInputOutputStream or null if no suitable instance was found * */ - private XMPPInputOutputStream maybeGetCompressionHandler() { - Compress.Feature compression = getFeature(Compress.Feature.ELEMENT, Compress.NAMESPACE); - if (compression == null) { - // Server does not support compression - return null; - } + private XMPPInputOutputStream maybeGetCompressionHandler(Compress.Feature compression) { for (XMPPInputOutputStream handler : SmackConfiguration.getCompresionHandlers()) { String method = handler.getCompressionMethod(); if (compression.getMethods().contains(method)) @@ -776,11 +769,19 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { * @throws NoResponseException * @throws InterruptedException */ - private void useCompression() throws NotConnectedException, NoResponseException, XMPPException, InterruptedException { + private void maybeEnableCompression() throws NotConnectedException, NoResponseException, XMPPException, InterruptedException { + if (!config.isCompressionEnabled()) { + return; + } maybeCompressFeaturesReceived.checkIfSuccessOrWait(); + Compress.Feature compression = getFeature(Compress.Feature.ELEMENT, Compress.NAMESPACE); + if (compression == null) { + // Server does not support compression + return; + } // If stream compression was offered by the server and we want to use // compression then send compression request to the server - if ((compressionHandler = maybeGetCompressionHandler()) != null) { + if ((compressionHandler = maybeGetCompressionHandler(compression)) != null) { compressSyncPoint.sendAndWaitForResponseOrThrow(new Compress(compressionHandler.getCompressionMethod())); } else { LOGGER.warning("Could not enable compression because no matching handler/method pair was found");