@Override public DnsClient createDnsClient(int port, String host) { return createDnsClient(new DnsClientOptions().setHost(host).setPort(port)); }
case "host": if (member.getValue() instanceof String) { obj.setHost((String)member.getValue()); obj.setLogActivity((Boolean)member.getValue()); obj.setPort(((Number)member.getValue()).intValue()); obj.setQueryTimeout(((Number)member.getValue()).longValue()); obj.setRecursionDesired((Boolean)member.getValue());
@Override public DnsClient createDnsClient(DnsClientOptions options) { String host = options.getHost(); int port = options.getPort(); if (host == null || port < 0) { DnsResolverProvider provider = new DnsResolverProvider(this, addressResolverOptions); InetSocketAddress address = provider.nameServerAddresses().get(0); // provide the host and port options = new DnsClientOptions(options) .setHost(address.getAddress().getHostAddress()) .setPort(address.getPort()); } return new DnsClientImpl(this, options); }
public static void toJson(DnsClientOptions obj, java.util.Map<String, Object> json) { if (obj.getHost() != null) { json.put("host", obj.getHost()); } json.put("logActivity", obj.getLogActivity()); json.put("port", obj.getPort()); json.put("queryTimeout", obj.getQueryTimeout()); json.put("recursionDesired", obj.isRecursionDesired()); } }
@Test public void testTimeout() throws Exception { DnsClient dns = vertx.createDnsClient(new DnsClientOptions().setHost("localhost").setPort(10000).setQueryTimeout(5000)); dns.lookup("vertx.io", onFailure(result -> { assertEquals(VertxException.class, result.getClass()); assertEquals("DNS query timeout for vertx.io", result.getMessage()); ((DnsClientImpl) dns).inProgressQueries(num -> { assertEquals(0, (int)num); testComplete(); }); })); await(); }
@Test public void testDoNotLogActivity() throws Exception { TestLoggerFactory factory = testLogging(new DnsClientOptions().setLogActivity(false)); assertFalse(factory.hasName("io.netty.handler.logging.LoggingHandler")); }
@Test public void testRecursionDesired() throws Exception { final String ip = "10.0.0.1"; dnsServer.testResolveA(ip); DnsClient dns = prepareDns(new DnsClientOptions().setRecursionDesired(true)); dns.resolveA("vertx.io", onSuccess(result -> { assertFalse(result.isEmpty()); assertEquals(1, result.size()); assertEquals(ip, result.get(0)); DnsMessage msg = dnsServer.pollMessage(); assertTrue(msg.isRecursionDesired()); ((DnsClientImpl) dns).inProgressQueries(num -> { assertEquals(0, (int)num); testComplete(); }); })); await(); }
public DnsClientImpl(VertxInternal vertx, DnsClientOptions options) { Objects.requireNonNull(options, "no null options accepted"); Objects.requireNonNull(options.getHost(), "no null host accepted"); this.options = new DnsClientOptions(options); this.dnsServer = new InetSocketAddress(options.getHost(), options.getPort()); if (this.dnsServer.isUnresolved()) { throw new IllegalArgumentException("Cannot resolve the host to a valid ip address"); channel.config().setAllocator(PartialPooledByteBufAllocator.INSTANCE); actualCtx.nettyEventLoop().register(channel); if (options.getLogActivity()) { channel.pipeline().addLast("logging", new LoggingHandler());
private DnsClient prepareDns() throws Exception { return prepareDns(new DnsClientOptions().setQueryTimeout(15000)); }
@Override public DnsClient createDnsClient() { return createDnsClient(new DnsClientOptions()); }
@Test public void testTimeout() throws Exception { DnsClient dns = vertx.createDnsClient(new DnsClientOptions().setHost("localhost").setPort(10000).setQueryTimeout(5000)); dns.lookup("vertx.io", onFailure(result -> { assertEquals(VertxException.class, result.getClass()); assertEquals("DNS query timeout for vertx.io", result.getMessage()); ((DnsClientImpl) dns).inProgressQueries(num -> { assertEquals(0, (int)num); testComplete(); }); })); await(); }
@Test public void testLogActivity() throws Exception { TestLoggerFactory factory = testLogging(new DnsClientOptions().setLogActivity(true)); assertTrue(factory.hasName("io.netty.handler.logging.LoggingHandler")); }
@Test public void testRecursionNotDesired() throws Exception { final String ip = "10.0.0.1"; dnsServer.testResolveA(ip); DnsClient dns = prepareDns(new DnsClientOptions().setRecursionDesired(false)); dns.resolveA("vertx.io", onSuccess(result -> { assertFalse(result.isEmpty()); assertEquals(1, result.size()); assertEquals(ip, result.get(0)); DnsMessage msg = dnsServer.pollMessage(); assertFalse(msg.isRecursionDesired()); ((DnsClientImpl) dns).inProgressQueries(num -> { assertEquals(0, (int)num); testComplete(); }); })); await(); }
public DnsClientImpl(VertxInternal vertx, DnsClientOptions options) { Objects.requireNonNull(options, "no null options accepted"); Objects.requireNonNull(options.getHost(), "no null host accepted"); this.options = new DnsClientOptions(options); this.dnsServer = new InetSocketAddress(options.getHost(), options.getPort()); if (this.dnsServer.isUnresolved()) { throw new IllegalArgumentException("Cannot resolve the host to a valid ip address"); channel.config().setAllocator(PartialPooledByteBufAllocator.INSTANCE); actualCtx.nettyEventLoop().register(channel); if (options.getLogActivity()) { channel.pipeline().addLast("logging", new LoggingHandler());
public static void toJson(DnsClientOptions obj, java.util.Map<String, Object> json) { if (obj.getHost() != null) { json.put("host", obj.getHost()); } json.put("logActivity", obj.getLogActivity()); json.put("port", obj.getPort()); json.put("queryTimeout", obj.getQueryTimeout()); json.put("recursionDesired", obj.isRecursionDesired()); } }
private DnsClient prepareDns() throws Exception { return prepareDns(new DnsClientOptions().setQueryTimeout(15000)); }
@Test public void testDefaultDnsClientWithOptions() throws Exception { testDefaultDnsClient(vertx -> vertx.createDnsClient(new DnsClientOptions())); }
private DnsClient prepareDns(DnsClientOptions options) throws Exception { InetSocketAddress addr = dnsServer.localAddress(); return vertx.createDnsClient(new DnsClientOptions(options).setPort(addr.getPort()).setHost(addr.getAddress().getHostAddress())); } }
case "host": if (member.getValue() instanceof String) { obj.setHost((String)member.getValue()); obj.setLogActivity((Boolean)member.getValue()); obj.setPort(((Number)member.getValue()).intValue()); obj.setQueryTimeout(((Number)member.getValue()).longValue()); obj.setRecursionDesired((Boolean)member.getValue());
@Override public DnsClient createDnsClient(DnsClientOptions options) { String host = options.getHost(); int port = options.getPort(); if (host == null || port < 0) { DnsResolverProvider provider = new DnsResolverProvider(this, addressResolverOptions); InetSocketAddress address = provider.nameServerAddresses().get(0); // provide the host and port options = new DnsClientOptions(options) .setHost(address.getAddress().getHostAddress()) .setPort(address.getPort()); } return new DnsClientImpl(this, options); }