Example usage for io.netty.handler.codec.dns DnsRecordType TXT

List of usage examples for io.netty.handler.codec.dns DnsRecordType TXT

Introduction

In this page you can find the example usage for io.netty.handler.codec.dns DnsRecordType TXT.

Prototype

DnsRecordType TXT

To view the source code for io.netty.handler.codec.dns DnsRecordType TXT.

Click Source Link

Document

Text record RFC 1035 Originally for arbitrary human-readable text in a DNS record.

Usage

From source file:com.linecorp.armeria.client.endpoint.dns.DnsTextEndpointGroup.java

License:Apache License

DnsTextEndpointGroup(EventLoop eventLoop, int minTtl, int maxTtl,
        DnsServerAddressStreamProvider serverAddressStreamProvider, Backoff backoff, String hostname,
        Function<byte[], Endpoint> mapping) {
    super(eventLoop, minTtl, maxTtl, serverAddressStreamProvider, backoff,
            ImmutableList.of(new DefaultDnsQuestion(hostname, DnsRecordType.TXT)), unused -> {
            });/*from w w  w .  j a  v  a2 s.co  m*/
    this.mapping = mapping;
    start();
}

From source file:com.linecorp.armeria.client.endpoint.dns.DnsTextEndpointGroup.java

License:Apache License

@Override
ImmutableSortedSet<Endpoint> onDnsRecords(List<DnsRecord> records, int ttl) throws Exception {
    final ImmutableSortedSet.Builder<Endpoint> builder = ImmutableSortedSet.naturalOrder();
    for (DnsRecord r : records) {
        if (!(r instanceof DnsRawRecord) || r.type() != DnsRecordType.TXT) {
            continue;
        }/*from  w  ww .j ava  2  s  .co  m*/

        final ByteBuf content = ((ByteBufHolder) r).content();
        if (!content.isReadable()) { // Missing length octet
            warnInvalidRecord(DnsRecordType.TXT, content);
            continue;
        }

        content.markReaderIndex();
        final int txtLen = content.readUnsignedByte();
        if (txtLen == 0) { // Empty content
            continue;
        }

        if (content.readableBytes() != txtLen) { // Mismatching number of octets
            content.resetReaderIndex();
            warnInvalidRecord(DnsRecordType.TXT, content);
            continue;
        }

        final byte[] txt = new byte[txtLen];
        content.readBytes(txt);

        final Endpoint endpoint;
        try {
            endpoint = mapping.apply(txt);
        } catch (Exception e) {
            content.resetReaderIndex();
            warnInvalidRecord(DnsRecordType.TXT, content);
            continue;
        }

        if (endpoint != null) {
            if (endpoint.isGroup()) {
                logger().warn("{} Ignoring group endpoint: {}", logPrefix(), endpoint);
            } else {
                builder.add(endpoint);
            }
        }
    }

    final ImmutableSortedSet<Endpoint> endpoints = builder.build();
    if (logger().isDebugEnabled()) {
        logger().debug("{} Resolved: {} (TTL: {})", logPrefix(),
                endpoints.stream().map(Object::toString).collect(Collectors.joining(", ")), ttl);
    }

    return endpoints;
}

From source file:io.vertx.core.dns.impl.DnsClientImpl.java

License:Open Source License

@Override
public DnsClient resolveTXT(String name, Handler<AsyncResult<List<String>>> handler) {
    lookupList(name, new Handler<AsyncResult<List<String>>>() {
        @SuppressWarnings("unchecked")
        @Override/*from  w  ww .j a v  a  2  s. com*/
        public void handle(AsyncResult event) {
            if (event.failed()) {
                handler.handle(event);
            } else {
                List<String> txts = new ArrayList<>();
                List<List<String>> records = (List<List<String>>) event.result();
                for (List<String> txt : records) {
                    txts.addAll(txt);
                }
                handler.handle(Future.succeededFuture(txts));
            }
        }
    }, DnsRecordType.TXT);
    return this;
}