aboutsummaryrefslogtreecommitdiff
path: root/juick-xmpp/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-xmpp/src/main/java')
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionOut.java4
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/s2s/DNSQueries.java34
2 files changed, 17 insertions, 21 deletions
diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionOut.java b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionOut.java
index 87e3cdbda..e39c143d8 100644
--- a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionOut.java
+++ b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionOut.java
@@ -12,6 +12,7 @@ import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSocket;
import java.io.EOFException;
import java.io.IOException;
+import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketException;
import java.security.KeyManagementException;
@@ -64,7 +65,8 @@ public class ConnectionOut extends Connection implements Runnable {
logger.info("stream to {} start", to);
try {
socket = new Socket();
- socket.connect(DNSQueries.getServerAddress(to));
+ InetSocketAddress address = DNSQueries.getServerAddress(to);
+ socket.connect(address);
restartParser();
sendOpenStream();
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 6de9e15d6..887dfc5c3 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,5 +1,7 @@
package com.juick.components.s2s;
+import org.apache.commons.lang3.math.NumberUtils;
+
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.Hashtable;
@@ -17,31 +19,23 @@ public class DNSQueries {
private static Random rand = new Random();
- public static InetSocketAddress getServerAddress(String hostname) throws UnknownHostException {
+ public static InetSocketAddress getServerAddress(String hostname) throws UnknownHostException, NamingException {
String host = hostname;
int port = 5269;
- try {
- Hashtable<String, String> env = new Hashtable<String, String>(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());
- try {
- String srv[] = att.get(i).toString().split(" ");
- port = Integer.parseInt(srv[2]);
- host = srv[3];
- } catch (Exception e) {
- }
- }
-
- ctx.close();
- } catch (NamingException e) {
- }
+ 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];
+ }
+ ctx.close();
return new InetSocketAddress(host, port);
}
}