Search in sources :

Example 21 with DnsClient

use of io.vertx.core.dns.DnsClient in project vert.x by eclipse.

the class DNSExamples method example6.

public void example6(Vertx vertx) {
    DnsClient client = vertx.createDnsClient(53, "10.0.0.1");
    client.resolveAAAA("vertx.io", ar -> {
        if (ar.succeeded()) {
            List<String> records = ar.result();
            for (String record : records) {
                System.out.println(record);
            }
        } else {
            System.out.println("Failed to resolve entry" + ar.cause());
        }
    });
}
Also used : DnsClient(io.vertx.core.dns.DnsClient)

Example 22 with DnsClient

use of io.vertx.core.dns.DnsClient in project vert.x by eclipse.

the class DNSExamples method example7.

public void example7(Vertx vertx) {
    DnsClient client = vertx.createDnsClient(53, "10.0.0.1");
    client.resolveCNAME("vertx.io", ar -> {
        if (ar.succeeded()) {
            List<String> records = ar.result();
            for (String record : records) {
                System.out.println(record);
            }
        } else {
            System.out.println("Failed to resolve entry" + ar.cause());
        }
    });
}
Also used : DnsClient(io.vertx.core.dns.DnsClient)

Example 23 with DnsClient

use of io.vertx.core.dns.DnsClient in project vert.x by eclipse.

the class DNSExamples method example15.

public void example15(Vertx vertx) {
    DnsClient client = vertx.createDnsClient(53, "10.0.0.1");
    client.reverseLookup("10.0.0.1", ar -> {
        if (ar.succeeded()) {
            String record = ar.result();
            System.out.println(record);
        } else {
            System.out.println("Failed to resolve entry" + ar.cause());
        }
    });
}
Also used : DnsClient(io.vertx.core.dns.DnsClient)

Example 24 with DnsClient

use of io.vertx.core.dns.DnsClient in project vert.x by eclipse.

the class DNSTest method testLookupNonExisting.

@Test
public void testLookupNonExisting() throws Exception {
    DnsClient dns = prepareDns(FakeDNSServer.testLookupNonExisting());
    dns.lookup("gfegjegjf.sg1", ar -> {
        DnsException cause = (DnsException) ar.cause();
        assertEquals(DnsResponseCode.NXDOMAIN, cause.code());
        testComplete();
    });
    await();
    dnsServer.stop();
}
Also used : DnsException(io.vertx.core.dns.DnsException) DnsClient(io.vertx.core.dns.DnsClient) Test(org.junit.Test)

Example 25 with DnsClient

use of io.vertx.core.dns.DnsClient in project vert.x by eclipse.

the class DNSTest method testResolveNS.

@Test
public void testResolveNS() throws Exception {
    final String ns = "ns.vertx.io";
    DnsClient dns = prepareDns(FakeDNSServer.testResolveNS(ns));
    dns.resolveNS("vertx.io", ar -> {
        List<String> result = ar.result();
        assertNotNull(result);
        assertFalse(result.isEmpty());
        assertEquals(1, result.size());
        assertEquals(ns, result.get(0));
        testComplete();
    });
    await();
    dnsServer.stop();
}
Also used : DnsClient(io.vertx.core.dns.DnsClient) Test(org.junit.Test)

Aggregations

DnsClient (io.vertx.core.dns.DnsClient)30 Test (org.junit.Test)16 DnsException (io.vertx.core.dns.DnsException)4 MxRecord (io.vertx.core.dns.MxRecord)4 SrvRecord (io.vertx.core.dns.SrvRecord)4 DnsResponseCode (io.vertx.core.dns.DnsResponseCode)3 NioDatagramChannel (io.netty.channel.socket.nio.NioDatagramChannel)2 InetAddress (java.net.InetAddress)2 InetSocketAddress (java.net.InetSocketAddress)2 List (java.util.List)2 Bootstrap (io.netty.bootstrap.Bootstrap)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelFutureListener (io.netty.channel.ChannelFutureListener)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 ChannelOption (io.netty.channel.ChannelOption)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 SimpleChannelInboundHandler (io.netty.channel.SimpleChannelInboundHandler)1 DatagramChannel (io.netty.channel.socket.DatagramChannel)1 DatagramDnsQuery (io.netty.handler.codec.dns.DatagramDnsQuery)1