mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-10 02:39:42 +02:00
Add smack-resolver-minidns
This commit is contained in:
parent
1f6d0fa415
commit
609c225865
6 changed files with 127 additions and 0 deletions
|
@ -36,6 +36,7 @@ import org.jivesoftware.smack.compression.XMPPInputOutputStream;
|
|||
import org.jivesoftware.smack.initializer.SmackInitializer;
|
||||
import org.jivesoftware.smack.parsing.ExceptionThrowingCallback;
|
||||
import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
|
||||
import org.jivesoftware.smack.util.DNSUtil;
|
||||
import org.jivesoftware.smack.util.FileUtils;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
@ -167,6 +168,9 @@ public final class SmackConfiguration {
|
|||
catch (Exception e) {
|
||||
// Ignore.
|
||||
}
|
||||
|
||||
// Initialize the DNS resolvers
|
||||
DNSUtil.init();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.jivesoftware.smack.util;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
|
@ -39,6 +41,31 @@ public class DNSUtil {
|
|||
private static final Logger LOGGER = Logger.getLogger(DNSUtil.class.getName());
|
||||
private static DNSResolver dnsResolver = null;
|
||||
|
||||
/**
|
||||
* Initializes DNSUtil. This method is automatically called by SmackConfiguration, you don't
|
||||
* have to call it manually.
|
||||
*/
|
||||
public static void init() {
|
||||
final String[] RESOLVERS = new String[] { "javax.JavaxResolver", "minidns.MiniDnsResolver",
|
||||
"dnsjava.DNSJavaResolver" };
|
||||
for (String resolver :RESOLVERS) {
|
||||
DNSResolver availableResolver = null;
|
||||
String resolverFull = "org.jivesoftware.smack.util.dns" + resolver;
|
||||
try {
|
||||
Class<?> resolverClass = Class.forName(resolverFull);
|
||||
Method getInstanceMethod = resolverClass.getMethod("getInstance");
|
||||
availableResolver = (DNSResolver) getInstanceMethod.invoke(null);
|
||||
if (availableResolver != null) {
|
||||
setDNSResolver(availableResolver);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (ClassNotFoundException|NoSuchMethodException|SecurityException|IllegalAccessException|IllegalArgumentException|InvocationTargetException e) {
|
||||
LOGGER.log(Level.FINE, "Exception on init", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the DNS resolver that should be used to perform DNS lookups.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue