use of io.vertx.core.dns.DnsClient in project vert.x by eclipse.
the class DNSTest method testReverseLookupIpv4.
@Test
public void testReverseLookupIpv4() throws Exception {
String address = "10.0.0.1";
final String ptr = "ptr.vertx.io";
DnsClient dns = prepareDns(FakeDNSServer.testReverseLookup(ptr));
dns.reverseLookup(address, ar -> {
String result = ar.result();
assertNotNull(result);
assertEquals(ptr, result);
testComplete();
});
await();
dnsServer.stop();
}
use of io.vertx.core.dns.DnsClient in project vert.x by eclipse.
the class DNSTest method testIllegalArguments.
@Test
public void testIllegalArguments() throws Exception {
DnsClient dns = prepareDns(FakeDNSServer.testResolveAAAA("::1"));
assertNullPointerException(() -> dns.lookup(null, ar -> {
}));
assertNullPointerException(() -> dns.lookup4(null, ar -> {
}));
assertNullPointerException(() -> dns.lookup6(null, ar -> {
}));
assertNullPointerException(() -> dns.resolveA(null, ar -> {
}));
assertNullPointerException(() -> dns.resolveAAAA(null, ar -> {
}));
assertNullPointerException(() -> dns.resolveCNAME(null, ar -> {
}));
assertNullPointerException(() -> dns.resolveMX(null, ar -> {
}));
assertNullPointerException(() -> dns.resolveTXT(null, ar -> {
}));
assertNullPointerException(() -> dns.resolvePTR(null, ar -> {
}));
assertNullPointerException(() -> dns.resolveNS(null, ar -> {
}));
assertNullPointerException(() -> dns.resolveSRV(null, ar -> {
}));
dnsServer.stop();
}
use of io.vertx.core.dns.DnsClient in project vert.x by eclipse.
the class DNSTest method testResolveAAAA.
@Test
public void testResolveAAAA() throws Exception {
DnsClient dns = prepareDns(FakeDNSServer.testResolveAAAA("::1"));
dns.resolveAAAA("vertx.io", ar -> {
List<String> result = ar.result();
assertNotNull(result);
assertFalse(result.isEmpty());
assertEquals(1, result.size());
assertEquals("0:0:0:0:0:0:0:1", result.get(0));
testComplete();
});
await();
dnsServer.stop();
}
use of io.vertx.core.dns.DnsClient in project vert.x by eclipse.
the class DNSTest method testLookup6.
@Test
public void testLookup6() throws Exception {
DnsClient dns = prepareDns(FakeDNSServer.testLookup6());
dns.lookup6("vertx.io", ar -> {
String result = ar.result();
assertNotNull(result);
assertEquals("0:0:0:0:0:0:0:1", result);
testComplete();
});
await();
dnsServer.stop();
}
use of io.vertx.core.dns.DnsClient in project vert.x by eclipse.
the class DnsClientImpl method reverseLookup.
@Override
public DnsClient reverseLookup(String address, Handler<AsyncResult<String>> handler) {
// An other option would be to change address to be of type InetAddress.
try {
InetAddress inetAddress = InetAddress.getByName(address);
byte[] addr = inetAddress.getAddress();
StringBuilder reverseName = new StringBuilder(64);
if (inetAddress instanceof Inet4Address) {
// reverse ipv4 address
reverseName.append(addr[3] & 0xff).append(".").append(addr[2] & 0xff).append(".").append(addr[1] & 0xff).append(".").append(addr[0] & 0xff);
} else {
// It is an ipv 6 address time to reverse it
for (int i = 0; i < 16; i++) {
reverseName.append(HEX_TABLE[(addr[15 - i] & 0xf)]);
reverseName.append(".");
reverseName.append(HEX_TABLE[(addr[15 - i] >> 4) & 0xf]);
if (i != 15) {
reverseName.append(".");
}
}
}
reverseName.append(".in-addr.arpa");
return resolvePTR(reverseName.toString(), handler);
} catch (UnknownHostException e) {
// Should never happen as we work with ip addresses as input
// anyway just in case notify the handler
actualCtx.runOnContext((v) -> handler.handle(Future.failedFuture(e)));
}
return this;
}
Aggregations