Commit f7bd9f68 authored by Günther Niess's avatar Günther Niess Committed by niess

OF-44: Corrected some changes after a talk with Guus

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@11222 b35dd754-fafc-0310-a699-88a17e54d16e
parent cd51acc7
...@@ -15,12 +15,14 @@ package org.jivesoftware.openfire.net; ...@@ -15,12 +15,14 @@ package org.jivesoftware.openfire.net;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import javax.naming.NameNotFoundException;
import javax.naming.NamingException; import javax.naming.NamingException;
import javax.naming.directory.Attribute; import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes; import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext; import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext; import javax.naming.directory.InitialDirContext;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
...@@ -115,21 +117,17 @@ public class DNSUtil { ...@@ -115,21 +117,17 @@ public class DNSUtil {
} }
// Attempt the SRV lookup. // Attempt the SRV lookup.
try {
results = srvLookup("_xmpp-server._tcp." + domain); results = srvLookup("_xmpp-server._tcp." + domain);
} if (results == null || results.isEmpty()) {
catch (Exception e) {
// Attempt lookup with older "jabber" name.
try {
results = srvLookup("_jabber._tcp." + domain); results = srvLookup("_jabber._tcp." + domain);
} }
catch (Exception e2) {
// Do nothing
}
}
// Use domain and default port as fallback. // Use domain and default port as fallback.
if (results == null || results.isEmpty()) { if (results == null) {
results = new ArrayList<HostAddress>();
results.add(new HostAddress(domain, defaultPort));
}
else if (results.isEmpty()) {
results.add(new HostAddress(domain, defaultPort)); results.add(new HostAddress(domain, defaultPort));
} }
return results; return results;
...@@ -186,7 +184,11 @@ public class DNSUtil { ...@@ -186,7 +184,11 @@ public class DNSUtil {
return answer; return answer;
} }
private static List<HostAddress> srvLookup(String lookup) throws NamingException { private static List<HostAddress> srvLookup(String lookup) {
if (lookup == null) {
throw new NullPointerException("DNS lookup can't be null");
}
try {
Attributes dnsLookup = Attributes dnsLookup =
context.getAttributes(lookup, new String[]{"SRV"}); context.getAttributes(lookup, new String[]{"SRV"});
Attribute srvRecords = dnsLookup.get("SRV"); Attribute srvRecords = dnsLookup.get("SRV");
...@@ -199,14 +201,22 @@ public class DNSUtil { ...@@ -199,14 +201,22 @@ public class DNSUtil {
} }
return Arrays.asList(hosts); return Arrays.asList(hosts);
} }
catch (NameNotFoundException e) {
Log.debug("No SRV record found for: " + lookup, e);
}
catch (NamingException e) {
Log.error("Can't process DNS lookup!", e);
}
return null;
}
/** /**
* Encapsulates a hostname and port. * Encapsulates a hostname and port.
*/ */
public static class HostAddress { public static class HostAddress {
private String host; private final String host;
private int port; private final int port;
private HostAddress(String host, int port) { private HostAddress(String host, int port) {
// Host entries in DNS should end with a ".". // Host entries in DNS should end with a ".".
...@@ -247,8 +257,8 @@ public class DNSUtil { ...@@ -247,8 +257,8 @@ public class DNSUtil {
*/ */
public static class WeightedHostAddress extends HostAddress { public static class WeightedHostAddress extends HostAddress {
private int priority; private final int priority;
private int weight; private final int weight;
private WeightedHostAddress(String [] srvRecordEntries) { private WeightedHostAddress(String [] srvRecordEntries) {
super(srvRecordEntries[srvRecordEntries.length-1], super(srvRecordEntries[srvRecordEntries.length-1],
...@@ -285,7 +295,9 @@ public class DNSUtil { ...@@ -285,7 +295,9 @@ public class DNSUtil {
/** /**
* A comparator for sorting multiple weighted host addresses according to RFC 2782. * A comparator for sorting multiple weighted host addresses according to RFC 2782.
*/ */
public static class SrvRecordWeightedPriorityComparator implements Comparator<HostAddress> { public static class SrvRecordWeightedPriorityComparator implements Comparator<HostAddress>, Serializable {
private static final long serialVersionUID = -9207293572898848260L;
public int compare(HostAddress o1, HostAddress o2) { public int compare(HostAddress o1, HostAddress o2) {
if (o1 instanceof WeightedHostAddress && o2 instanceof WeightedHostAddress) { if (o1 instanceof WeightedHostAddress && o2 instanceof WeightedHostAddress) {
WeightedHostAddress srv1 = (WeightedHostAddress) o1; WeightedHostAddress srv1 = (WeightedHostAddress) o1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment