diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/dns/DNSResolver.java b/smack-core/src/main/java/org/jivesoftware/smack/util/dns/DNSResolver.java index c2823213c..dc1b79306 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/dns/DNSResolver.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/dns/DNSResolver.java @@ -20,6 +20,7 @@ import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Arrays; import java.util.List; +import java.util.logging.Level; import java.util.logging.Logger; import org.jivesoftware.smack.ConnectionConfiguration.DnssecMode; @@ -91,6 +92,22 @@ public abstract class DNSResolver { return Arrays.asList(inetAddressArray); } + protected final boolean shouldContinue(CharSequence name, CharSequence hostname, List hostAddresses) { + if (hostAddresses == null) { + return true; + } + + // If hostAddresses is not null but empty, then the DNS resolution was successful but the domain did not + // have any A or AAAA resource records. + if (hostAddresses.isEmpty()) { + LOGGER.log(Level.INFO, "The DNS name " + name + ", points to a hostname (" + hostname + + ") which has neither A or AAAA resource records. This is an indication of a broken DNS setup."); + return true; + } + + return false; + } + private final void checkIfDnssecRequestedAndSupported(DnssecMode dnssecMode) { if (dnssecMode != DnssecMode.disabled && !supportsDnssec) { throw new UnsupportedOperationException("This resolver does not support DNSSEC"); diff --git a/smack-resolver-dnsjava/src/main/java/org/jivesoftware/smack/util/dns/dnsjava/DNSJavaResolver.java b/smack-resolver-dnsjava/src/main/java/org/jivesoftware/smack/util/dns/dnsjava/DNSJavaResolver.java index dd449fce3..f9aeee32d 100644 --- a/smack-resolver-dnsjava/src/main/java/org/jivesoftware/smack/util/dns/dnsjava/DNSJavaResolver.java +++ b/smack-resolver-dnsjava/src/main/java/org/jivesoftware/smack/util/dns/dnsjava/DNSJavaResolver.java @@ -1,6 +1,6 @@ /** * - * Copyright 2013-2016 Florian Schmaus + * Copyright 2013-2017 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ package org.jivesoftware.smack.util.dns.dnsjava; import java.net.InetAddress; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; import org.jivesoftware.smack.ConnectionConfiguration.DnssecMode; import org.jivesoftware.smack.initializer.SmackInitializer; @@ -74,13 +73,7 @@ public class DNSJavaResolver extends DNSResolver implements SmackInitializer { int weight = srvRecord.getWeight(); List hostAddresses = lookupHostAddress0(host, failedAddresses, dnssecMode); - if (hostAddresses == null || hostAddresses.isEmpty()) { - // If hostAddresses is not null but empty, then the DNS resolution was successful but the domain did not - // have any A or AAAA resource records. - if (hostAddresses.isEmpty()) { - LOGGER.log(Level.INFO, "The DNS name " + name + ", points to a hostname (" + host - + ") which has neither A or AAAA resource records. This is an indication of a broken DNS setup."); - } + if (shouldContinue(name, host, hostAddresses)) { continue; } diff --git a/smack-resolver-javax/src/main/java/org/jivesoftware/smack/util/dns/javax/JavaxResolver.java b/smack-resolver-javax/src/main/java/org/jivesoftware/smack/util/dns/javax/JavaxResolver.java index 1afce4198..f1cabcc13 100644 --- a/smack-resolver-javax/src/main/java/org/jivesoftware/smack/util/dns/javax/JavaxResolver.java +++ b/smack-resolver-javax/src/main/java/org/jivesoftware/smack/util/dns/javax/JavaxResolver.java @@ -111,13 +111,7 @@ public class JavaxResolver extends DNSResolver implements SmackInitializer { String host = srvRecordEntries[srvRecordEntries.length - 1]; List hostAddresses = lookupHostAddress0(host, failedAddresses, dnssecMode); - if (hostAddresses == null || hostAddresses.isEmpty()) { - // If hostAddresses is not null but empty, then the DNS resolution was successful but the domain did not - // have any A or AAAA resource records. - if (hostAddresses.isEmpty()) { - LOGGER.log(Level.INFO, "The DNS name " + name + ", points to a hostname (" + host - + ") which has neither A or AAAA resource records. This is an indication of a broken DNS setup."); - } + if (shouldContinue(name, host, hostAddresses)) { continue; } diff --git a/smack-resolver-minidns/src/main/java/org/jivesoftware/smack/util/dns/minidns/MiniDnsResolver.java b/smack-resolver-minidns/src/main/java/org/jivesoftware/smack/util/dns/minidns/MiniDnsResolver.java index 24e4c985c..2ecd717da 100644 --- a/smack-resolver-minidns/src/main/java/org/jivesoftware/smack/util/dns/minidns/MiniDnsResolver.java +++ b/smack-resolver-minidns/src/main/java/org/jivesoftware/smack/util/dns/minidns/MiniDnsResolver.java @@ -24,7 +24,6 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Set; -import java.util.logging.Level; import org.jivesoftware.smack.ConnectionConfiguration.DnssecMode; import org.jivesoftware.smack.initializer.SmackInitializer; @@ -91,13 +90,7 @@ public class MiniDnsResolver extends DNSResolver implements SmackInitializer { for (SRV srv : result.getAnswers()) { String hostname = srv.name.ace; List hostAddresses = lookupHostAddress0(hostname, failedAddresses, dnssecMode); - if (hostAddresses == null || hostAddresses.isEmpty()) { - // If hostAddresses is not null but empty, then the DNS resolution was successful but the domain did not - // have any A or AAAA resource records. - if (hostAddresses.isEmpty()) { - LOGGER.log(Level.INFO, "The DNS name " + name + ", points to a hostname (" + hostname - + ") which has neither A or AAAA resource records. This is an indication of a broken DNS setup."); - } + if (shouldContinue(name, hostname, hostAddresses)) { continue; }