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);
}
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;
}
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();
}
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();
}
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();
}
Aggregations