Search in sources :

Example 1 with Record

use of org.xbill.DNS.Record in project camel by apache.

the class DnsDigProducer method process.

@Override
public void process(Exchange exchange) throws Exception {
    String server = exchange.getIn().getHeader(DnsConstants.DNS_SERVER, String.class);
    SimpleResolver resolver = new SimpleResolver(server);
    int type = Type.value(exchange.getIn().getHeader(DnsConstants.DNS_TYPE, String.class));
    if (type == -1) {
        // default: if unparsable value given, use A.
        type = Type.A;
    }
    String dclassValue = exchange.getIn().getHeader(DnsConstants.DNS_CLASS, String.class);
    if (dclassValue == null) {
        dclassValue = "";
    }
    int dclass = DClass.value(dclassValue);
    if (dclass == -1) {
        // by default, value is IN.
        dclass = DClass.IN;
    }
    Name name = Name.fromString(exchange.getIn().getHeader(DnsConstants.DNS_NAME, String.class), Name.root);
    Record rec = Record.newRecord(name, type, dclass);
    Message query = Message.newQuery(rec);
    Message response = resolver.send(query);
    exchange.getIn().setBody(response);
}
Also used : Message(org.xbill.DNS.Message) Record(org.xbill.DNS.Record) SimpleResolver(org.xbill.DNS.SimpleResolver) Endpoint(org.apache.camel.Endpoint) Name(org.xbill.DNS.Name)

Example 2 with Record

use of org.xbill.DNS.Record in project camel by apache.

the class DnsServiceDiscovery method getServices.

@Override
public List<ServiceDefinition> getServices(String name) {
    final Lookup lookup = cache.computeIfAbsent(name, this::createLookup);
    final Record[] records = lookup.run();
    List<ServiceDefinition> services;
    if (Objects.nonNull(records) && lookup.getResult() == Lookup.SUCCESSFUL) {
        services = Arrays.stream(records).filter(SRVRecord.class::isInstance).map(SRVRecord.class::cast).sorted(COMPARATOR).map(record -> asService(name, record)).collect(Collectors.toList());
    } else {
        services = Collections.emptyList();
    }
    return services;
}
Also used : Lookup(org.xbill.DNS.Lookup) SRVRecord(org.xbill.DNS.SRVRecord) Record(org.xbill.DNS.Record) SRVRecord(org.xbill.DNS.SRVRecord) DefaultServiceDefinition(org.apache.camel.impl.cloud.DefaultServiceDefinition) ServiceDefinition(org.apache.camel.cloud.ServiceDefinition)

Example 3 with Record

use of org.xbill.DNS.Record in project camel by apache.

the class DnsLookupEndpointSpringTest method testDNSWithNameHeaderAndType.

@Test
@Ignore("Testing behind nat produces timeouts")
public void testDNSWithNameHeaderAndType() throws Exception {
    resultEndpoint.expectedMessageCount(1);
    resultEndpoint.expectedMessagesMatches(new Predicate() {

        public boolean matches(Exchange exchange) {
            Record[] record = (Record[]) exchange.getIn().getBody();
            return record[0].getName().toString().equals("www.example.com.");
        }
    });
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put("dns.name", "www.example.com");
    headers.put("dns.type", "A");
    template.sendBodyAndHeaders("hello", headers);
    resultEndpoint.assertIsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) HashMap(java.util.HashMap) Record(org.xbill.DNS.Record) Predicate(org.apache.camel.Predicate) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with Record

use of org.xbill.DNS.Record in project camel by apache.

the class DnsLookupEndpointSpringTest method testDNSWithNameHeader.

@Test
@Ignore("Testing behind nat produces timeouts")
public void testDNSWithNameHeader() throws Exception {
    resultEndpoint.expectedMessageCount(1);
    resultEndpoint.expectedMessagesMatches(new Predicate() {

        public boolean matches(Exchange exchange) {
            Record[] record = (Record[]) exchange.getIn().getBody();
            return record[0].getName().toString().equals("www.example.com.");
        }
    });
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put("dns.name", "www.example.com");
    template.sendBodyAndHeaders("hello", headers);
    resultEndpoint.assertIsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) HashMap(java.util.HashMap) Record(org.xbill.DNS.Record) Predicate(org.apache.camel.Predicate) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with Record

use of org.xbill.DNS.Record in project camel by apache.

the class DnsLookupEndpointTest method testDNSWithNameHeaderAndType.

@Test
@Ignore("Testing behind nat produces timeouts")
public void testDNSWithNameHeaderAndType() throws Exception {
    resultEndpoint.expectedMessageCount(1);
    resultEndpoint.expectedMessagesMatches(new Predicate() {

        public boolean matches(Exchange exchange) {
            Record[] record = (Record[]) exchange.getIn().getBody();
            return record[0].getName().toString().equals("www.example.com.");
        }
    });
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put("dns.name", "www.example.com");
    headers.put("dns.type", "A");
    template.sendBodyAndHeaders("hello", headers);
    resultEndpoint.assertIsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) HashMap(java.util.HashMap) Record(org.xbill.DNS.Record) Predicate(org.apache.camel.Predicate) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Record (org.xbill.DNS.Record)41 Name (org.xbill.DNS.Name)16 Lookup (org.xbill.DNS.Lookup)14 ARecord (org.xbill.DNS.ARecord)10 ArrayList (java.util.ArrayList)9 DnsRecord (org.nhind.config.DnsRecord)8 Message (org.xbill.DNS.Message)8 CERTRecord (org.xbill.DNS.CERTRecord)7 CNAMERecord (org.xbill.DNS.CNAMERecord)7 MXRecord (org.xbill.DNS.MXRecord)7 Test (org.junit.Test)6 SimpleResolver (org.xbill.DNS.SimpleResolver)6 ExtendedResolver (org.xbill.DNS.ExtendedResolver)5 SOARecord (org.xbill.DNS.SOARecord)5 UnknownHostException (java.net.UnknownHostException)4 HashMap (java.util.HashMap)4 Exchange (org.apache.camel.Exchange)4 Predicate (org.apache.camel.Predicate)4 Ignore (org.junit.Ignore)4 CertificateConversionException (org.nhindirect.config.model.exceptions.CertificateConversionException)4