Search in sources :

Example 16 with ExtendedResolver

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;
}
Also used : ExtendedResolver(org.xbill.DNS.ExtendedResolver) UnknownHostException(java.net.UnknownHostException) Lookup(org.xbill.DNS.Lookup) ARecord(org.xbill.DNS.ARecord) Record(org.xbill.DNS.Record) InetAddress(java.net.InetAddress) TextParseException(org.xbill.DNS.TextParseException)

Aggregations

ExtendedResolver (org.xbill.DNS.ExtendedResolver)16 UnknownHostException (java.net.UnknownHostException)8 Name (org.xbill.DNS.Name)6 Record (org.xbill.DNS.Record)6 Lookup (org.xbill.DNS.Lookup)5 X509Certificate (java.security.cert.X509Certificate)4 Resolver (org.xbill.DNS.Resolver)3 Certificate (java.security.cert.Certificate)2 Message (org.xbill.DNS.Message)2 SimpleResolver (org.xbill.DNS.SimpleResolver)2 TextParseException (org.xbill.DNS.TextParseException)2 File (java.io.File)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InetAddress (java.net.InetAddress)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 Converter (org.apache.camel.Converter)1 CacheException (org.apache.jcs.access.exception.CacheException)1 CollectionProperty (org.apache.jmeter.testelement.property.CollectionProperty)1