Search in sources :

Example 11 with TextParseException

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();
    }
}
Also used : DNSRecord(org.nhindirect.config.store.DNSRecord) ArrayList(java.util.ArrayList) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) DNSEntryForm(org.nhindirect.config.ui.form.DNSEntryForm) SOARecord(org.xbill.DNS.SOARecord) TextParseException(org.xbill.DNS.TextParseException)

Example 12 with TextParseException

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;
}
Also used : ExtendedResolver(org.xbill.DNS.ExtendedResolver) UnknownHostException(java.net.UnknownHostException) Lookup(org.xbill.DNS.Lookup) ARecord(org.xbill.DNS.ARecord) Record(org.xbill.DNS.Record) InetAddress(java.net.InetAddress) TextParseException(org.xbill.DNS.TextParseException)

Aggregations

TextParseException (org.xbill.DNS.TextParseException)12 ARecord (org.xbill.DNS.ARecord)7 UnknownHostException (java.net.UnknownHostException)6 ArrayList (java.util.ArrayList)5 Name (org.xbill.DNS.Name)5 Lookup (org.xbill.DNS.Lookup)4 InetAddress (java.net.InetAddress)3 JSONArray (org.json.JSONArray)3 JSONException (org.json.JSONException)3 JSONObject (org.json.JSONObject)3 DNSEntryForm (org.nhindirect.config.ui.form.DNSEntryForm)3 AAAARecord (org.xbill.DNS.AAAARecord)3 MXRecord (org.xbill.DNS.MXRecord)3 NSRecord (org.xbill.DNS.NSRecord)3 Record (org.xbill.DNS.Record)3 SOARecord (org.xbill.DNS.SOARecord)3 IOException (java.io.IOException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 X509Certificate (java.security.cert.X509Certificate)2 CertificateEncodingException (javax.security.cert.CertificateEncodingException)2