use of org.xbill.DNS.ExtendedResolver in project nhin-d by DirectProject.
the class ProxyDNSStore method get.
/**
* {@inheritDoc}
*/
@Override
public Message get(Message dnsMsg) throws DNSException {
ExtendedResolver resolver = createExResolver(servers, port, 2, 2000);
// try UPD first
Message response = null;
try {
response = resolver.send(dnsMsg);
} catch (IOException e) {
/* no-op */
}
if (response == null) {
// try TCP
resolver.setTCP(true);
try {
response = resolver.send(dnsMsg);
} catch (IOException e) {
/* no-op */
}
}
return response;
}
use of org.xbill.DNS.ExtendedResolver in project nhin-d by DirectProject.
the class ProxyDNSStore method createExResolver.
/*
* Create the resolver that will do the DNS requests.
*/
private ExtendedResolver createExResolver(String[] servers, int port, int retries, int timeout) {
ExtendedResolver retVal = null;
try {
retVal = new ExtendedResolver(servers);
retVal.setRetries(retries);
retVal.setTimeout(timeout);
} catch (UnknownHostException e) {
LOGGER.warn("Proxy store resolver could not be created: " + e.getMessage(), e);
}
return retVal;
}
use of org.xbill.DNS.ExtendedResolver in project nhin-d by DirectProject.
the class DNSConnectionTest method performLookup.
private static void performLookup() throws Exception {
// turn on debug settings for the DNS client
Options.set("verbose", "true");
Cache ch = Lookup.getDefaultCache(DClass.IN);
ch.clearCache();
if (servers == null || servers.length == 0)
servers = ResolverConfig.getCurrentConfig().servers();
System.out.println("\r\nConfigure DNS resolvers:");
for (String server : servers) {
System.out.println("\t" + server);
}
System.out.println("\r\nLookup up record " + lookupRec);
Lookup lu = new Lookup(new Name(lookupRec), recType);
ExtendedResolver resolver = new ExtendedResolver(servers);
resolver.setTCP(useTCP);
lu.setResolver(resolver);
Record[] retRecords = lu.run();
if (retRecords != null && retRecords.length > 0)
System.out.println(retRecords.length + " records found.");
else
System.out.println("No records found.");
}
use of org.xbill.DNS.ExtendedResolver in project nhin-d by DirectProject.
the class LdapPublicCertUtilImpl method createExResolver.
/**
* Creates the resolver used by the DNS lookup.
* @param servers Array or DNS servers
* @param retries Number of times to retry the lookup if the case of failure
* @param timeout Timeout in seconds to wait for a response for a DNS query
* @return Configured DNS resolver object
*/
protected ExtendedResolver createExResolver(String[] servers, int retries, int timeout) {
ExtendedResolver retVal = null;
try {
retVal = new ExtendedResolver(servers);
retVal.setRetries(retries);
retVal.setTimeout(timeout);
retVal.setTCP(false);
} catch (UnknownHostException e) {
/* no-op */
}
return retVal;
}
use of org.xbill.DNS.ExtendedResolver in project nhin-d by DirectProject.
the class DNSCertificateStore method createExResolver.
protected ExtendedResolver createExResolver(String[] servers, int retries, int timeout) {
// create a default ExtendedResolver
ExtendedResolver extendedResolver;
try {
extendedResolver = new ExtendedResolver();
} catch (UnknownHostException e) {
LOGGER.error("", e);
throw new IllegalStateException("unable to create default ExtendedResolver", e);
}
// remove all resolvers from default ExtendedResolver
Resolver[] resolvers = extendedResolver.getResolvers();
if (!ArrayUtils.isEmpty(resolvers)) {
for (Resolver resolver : resolvers) {
extendedResolver.deleteResolver(resolver);
}
}
// add the specified servers
if (!ArrayUtils.isEmpty(servers)) {
for (String server : servers) {
// support for IP addresses instead of names
server = server.replaceFirst("\\.$", "");
try {
// create and add a SimpleResolver for each server
SimpleResolver simpleResolver = new SimpleResolver(server);
extendedResolver.addResolver(simpleResolver);
} catch (UnknownHostException e) {
LOGGER.debug("unable to add resolver for " + server, e);
continue;
}
}
extendedResolver.setRetries(retries);
extendedResolver.setTimeout(timeout);
extendedResolver.setTCP(true);
}
return extendedResolver;
}
Aggregations