Class ResolverApi

  • Direct Known Subclasses:
    DnssecResolverApi

    public class ResolverApi
    extends Object
    The high-level MiniDNS resolving API. It is designed to be easy to use.

    A simple exammple how to resolve the IPv4 address of a given domain:

     
     ResolverResult<A> result = DnssecResolverApi.INSTANCE.resolve("verteiltesysteme.net", A.class);
     if (!result.wasSuccessful()) {
       RESPONSE_CODE responseCode = result.getResponseCode();
       // Perform error handling.
       …
       return;
     }
     if (!result.isAuthenticData()) {
       // Response was not secured with DNSSEC.
       …
       return;
     }
     Set<A> answers = result.getAnswers();
     for (A a : answers) {
       InetAddress inetAddress = a.getInetAddress();
       // Do someting with the InetAddress, e.g. connect to.
       …
     }
     
     

    MiniDNS also supports SRV resource records as first class citizens:

     
     SrvResolverResult result = DnssecResolverApi.INSTANCE.resolveSrv(SrvType.xmpp_client, "example.org")
     if (!result.wasSuccessful()) {
       RESPONSE_CODE responseCode = result.getResponseCode();
       // Perform error handling.
       …
       return;
     }
     if (!result.isAuthenticData()) {
       // Response was not secured with DNSSEC.
       …
       return;
     }
     List<ResolvedSrvRecord> srvRecords = result.getSortedSrvResolvedAddresses();
     // Loop over the domain names pointed by the SRV RR. MiniDNS will return the list
     // correctly sorted by the priority and weight of the related SRV RR.
     for (ResolvedSrvRecord srvRecord : srvRecord) {
       // Loop over the Internet Address RRs resolved for the SRV RR. The order of
       // the list depends on the prefered IP version setting of MiniDNS.
       for (InternetAddressRR inetAddressRR : srvRecord.addresses) {
         InetAddress inetAddress = inetAddressRR.getInetAddress();
         int port = srvAddresses.port;
         // Try to connect to inetAddress at port.
         …
       }
     }