aboutsummaryrefslogtreecommitdiff
path: root/juick-xmpp/src/main/java/com/juick/components
diff options
context:
space:
mode:
Diffstat (limited to 'juick-xmpp/src/main/java/com/juick/components')
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/s2s/DNSQueries.java28
1 files changed, 18 insertions, 10 deletions
diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/DNSQueries.java b/juick-xmpp/src/main/java/com/juick/components/s2s/DNSQueries.java
index 887dfc5c..ea4585a1 100644
--- a/juick-xmpp/src/main/java/com/juick/components/s2s/DNSQueries.java
+++ b/juick-xmpp/src/main/java/com/juick/components/s2s/DNSQueries.java
@@ -1,6 +1,8 @@
package com.juick.components.s2s;
import org.apache.commons.lang3.math.NumberUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
@@ -17,25 +19,31 @@ import javax.naming.directory.InitialDirContext;
*/
public class DNSQueries {
+ private static final Logger logger = LoggerFactory.getLogger(DNSQueries.class);
+
private static Random rand = new Random();
- public static InetSocketAddress getServerAddress(String hostname) throws UnknownHostException, NamingException {
+ public static InetSocketAddress getServerAddress(String hostname) {
String host = hostname;
int port = 5269;
Hashtable<String, String> env = new Hashtable<>(5);
env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
- DirContext ctx = new InitialDirContext(env);
- Attribute att = ctx.getAttributes("_xmpp-server._tcp." + hostname, new String[]{"SRV"}).get("SRV");
-
- if (att != null && att.size() > 0) {
- int i = rand.nextInt(att.size());
- String srv[] = att.get(i).toString().split(" ");
- port = NumberUtils.toInt(srv[2], 5269);
- host = srv[3];
+ try {
+ DirContext ctx = new InitialDirContext(env);
+ Attribute att = ctx.getAttributes("_xmpp-server._tcp." + hostname, new String[]{"SRV"}).get("SRV");
+
+ if (att != null && att.size() > 0) {
+ int i = rand.nextInt(att.size());
+ String srv[] = att.get(i).toString().split(" ");
+ port = NumberUtils.toInt(srv[2], 5269);
+ host = srv[3];
+ }
+ ctx.close();
+ } catch (NamingException e) {
+ logger.info("SRV record for {} is not resolved, falling back to A record", hostname);
}
- ctx.close();
return new InetSocketAddress(host, port);
}
}