use of org.xbill.DNS.ExtendedResolver in project jmeter by apache.
the class DNSCacheManager method requestLookup.
/**
* Sends DNS request via system or custom DNS resolver
* @param host Host
* @return array of {@link InetAddress} or null if lookup did not return result
*/
private InetAddress[] requestLookup(String host) throws UnknownHostException {
InetAddress[] addresses = null;
if (isCustomResolver()) {
ExtendedResolver extendedResolver = getResolver();
if (extendedResolver != null) {
if (extendedResolver.getResolvers().length > 0) {
try {
Lookup lookup = new Lookup(host, Type.A);
lookup.setCache(lookupCache);
if (timeoutMs > 0) {
resolver.setTimeout(timeoutMs / 1000, timeoutMs % 1000);
}
lookup.setResolver(resolver);
Record[] records = lookup.run();
if (records == null || records.length == 0) {
throw new UnknownHostException("Failed to resolve host name: " + host);
}
addresses = new InetAddress[records.length];
for (int i = 0; i < records.length; i++) {
addresses[i] = ((ARecord) records[i]).getAddress();
}
} catch (TextParseException tpe) {
log.debug("Failed to create Lookup object: " + tpe);
}
return addresses;
}
} else {
throw new UnknownHostException("Could not resolve host:" + host + ", failed to initialize resolver" + " or no resolver found");
}
}
addresses = systemDefaultDnsResolver.resolve(host);
if (log.isDebugEnabled()) {
log.debug("Cache miss: {} Thread #{}, resolved with system resolver into {}", host, JMeterContextService.getContext().getThreadNum(), Arrays.toString(addresses));
}
return addresses;
}
Aggregations