use of org.xbill.DNS.TextParseException in project nhin-d by DirectProject.
the class ServiceTest method testSOA.
// @Test
public void testSOA() {
DNSEntryForm SoadnsForm = new DNSEntryForm();
SoadnsForm.setName("savvy");
SoadnsForm.setTtl(84555L);
SoadnsForm.setAdmin("ns.savvy.com");
SoadnsForm.setDomain("ns2.savvy.com");
SoadnsForm.setSerial(4L);
SoadnsForm.setRefresh(6L);
SoadnsForm.setRetry(8L);
SoadnsForm.setExpire(66L);
SoadnsForm.setMinimum(22L);
Collection<DNSRecord> records = new ArrayList<DNSRecord>();
records.add(DNSRecordUtils.createSOARecord(SoadnsForm.getName(), SoadnsForm.getTtl(), SoadnsForm.getDomain(), SoadnsForm.getAdmin(), (int) SoadnsForm.getSerial(), SoadnsForm.getRefresh(), SoadnsForm.getRetry(), SoadnsForm.getExpire(), SoadnsForm.getMinimum()));
try {
configSvc.addDNS(records);
Collection<DNSRecord> arecords = configSvc.getDNSByType(DNSType.SOA.getValue());
for (Iterator<DNSRecord> iter = arecords.iterator(); iter.hasNext(); ) {
DNSRecord arec = iter.next();
SOARecord newrec = (SOARecord) Record.newRecord(Name.fromString(arec.getName()), arec.getType(), arec.getDclass(), arec.getTtl(), arec.getData());
System.out.println("A admin: " + newrec.getAdmin());
System.out.println("A name: " + newrec.getName());
}
} catch (ConfigurationServiceException e) {
e.printStackTrace();
} catch (TextParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.xbill.DNS.TextParseException in project jmeter by apache.
the class DNSCacheManager method requestLookup.
/**
* Sends DNS request via system or custom DNS resolver
* @param host Host
* @return array of {@link InetAddress} or null if lookup did not return result
*/
private InetAddress[] requestLookup(String host) throws UnknownHostException {
InetAddress[] addresses = null;
if (isCustomResolver()) {
ExtendedResolver extendedResolver = getResolver();
if (extendedResolver != null) {
if (extendedResolver.getResolvers().length > 0) {
try {
Lookup lookup = new Lookup(host, Type.A);
lookup.setCache(lookupCache);
if (timeoutMs > 0) {
resolver.setTimeout(timeoutMs / 1000, timeoutMs % 1000);
}
lookup.setResolver(resolver);
Record[] records = lookup.run();
if (records == null || records.length == 0) {
throw new UnknownHostException("Failed to resolve host name: " + host);
}
addresses = new InetAddress[records.length];
for (int i = 0; i < records.length; i++) {
addresses[i] = ((ARecord) records[i]).getAddress();
}
} catch (TextParseException tpe) {
log.debug("Failed to create Lookup object: " + tpe);
}
return addresses;
}
} else {
throw new UnknownHostException("Could not resolve host:" + host + ", failed to initialize resolver" + " or no resolver found");
}
}
addresses = systemDefaultDnsResolver.resolve(host);
if (log.isDebugEnabled()) {
log.debug("Cache miss: {} Thread #{}, resolved with system resolver into {}", host, JMeterContextService.getContext().getThreadNum(), Arrays.toString(addresses));
}
return addresses;
}
Aggregations