Search in sources :

Example 1 with ExtendedResolver

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;
}
Also used : ExtendedResolver(org.xbill.DNS.ExtendedResolver) Message(org.xbill.DNS.Message) IOException(java.io.IOException)

Example 2 with ExtendedResolver

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

Example 3 with ExtendedResolver

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.");
}
Also used : ExtendedResolver(org.xbill.DNS.ExtendedResolver) Lookup(org.xbill.DNS.Lookup) Record(org.xbill.DNS.Record) Cache(org.xbill.DNS.Cache) Name(org.xbill.DNS.Name)

Example 4 with ExtendedResolver

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

Example 5 with ExtendedResolver

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;
}
Also used : ExtendedResolver(org.xbill.DNS.ExtendedResolver) UnknownHostException(java.net.UnknownHostException) SimpleResolver(org.xbill.DNS.SimpleResolver) ExtendedResolver(org.xbill.DNS.ExtendedResolver) Resolver(org.xbill.DNS.Resolver) SimpleResolver(org.xbill.DNS.SimpleResolver)

Aggregations

ExtendedResolver (org.xbill.DNS.ExtendedResolver)18 UnknownHostException (java.net.UnknownHostException)9 Name (org.xbill.DNS.Name)7 Record (org.xbill.DNS.Record)7 X509Certificate (java.security.cert.X509Certificate)4 Lookup (org.xbill.DNS.Lookup)4 Resolver (org.xbill.DNS.Resolver)4 Message (org.xbill.DNS.Message)3 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)2 Certificate (java.security.cert.Certificate)2 ArrayList (java.util.ArrayList)2 SimpleResolver (org.xbill.DNS.SimpleResolver)2 TextParseException (org.xbill.DNS.TextParseException)2 File (java.io.File)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 TreeSet (java.util.TreeSet)1 Converter (org.apache.camel.Converter)1