org.xbill.DNS.Cache Java Examples

The following examples show how to use org.xbill.DNS.Cache. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GoogleResolverCheck.java    From entrada with GNU General Public License v3.0 7 votes vote down vote up
@Override
protected List<String> fetch() {

  try {
    Resolver resolver = new SimpleResolver();
    // dns resolvers may take a long time to return a response.
    resolver.setTimeout(timeout);
    Lookup l =
        new Lookup(StringUtils.endsWith(hostname, ".") ? hostname : hostname + ".", Type.TXT);
    // always make sure the cache is empty
    l.setCache(new Cache());
    l.setResolver(resolver);
    Record[] records = l.run();
    if (records != null && records.length > 0) {
      return parse(records[0]);
    }
  } catch (Exception e) {
    log.error("Problem while adding Google resolvers, continue without", e);
  }

  log.error("No Google resolver addresses found");
  return Collections.emptyList();
}
 
Example #2
Source File: DNSJavaServiceTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    dnsServer = new TestableDNSServer();

    dnsServer.configure(FileConfigurationProvider.getConfig(new ByteArrayInputStream(DNS_SERVER_CONFIG)));
    dnsServer.init();

    defaultCache = Lookup.getDefaultCache(DClass.IN);
    defaultResolver = Lookup.getDefaultResolver();
    defaultSearchPaths = Lookup.getDefaultSearchPath();
    Lookup.setDefaultCache(null, DClass.IN);
    Lookup.setDefaultResolver(null);
    Lookup.setDefaultSearchPath(new Name[]{});

    dnsServer.setResolver(null);
    mockedCache = mock(Cache.class);
}
 
Example #3
Source File: jnamed.java    From dnsjava with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public <T extends Record> RRset findExactMatch(Name name, int type, int dclass, boolean glue) {
  Zone zone = findBestZone(name);
  if (zone != null) {
    return zone.findExactMatch(name, type);
  } else {
    List<RRset> rrsets;
    Cache cache = getCache(dclass);
    if (glue) {
      rrsets = cache.findAnyRecords(name, type);
    } else {
      rrsets = cache.findRecords(name, type);
    }
    if (rrsets == null) {
      return null;
    } else {
      return rrsets.get(0); /* not quite right */
    }
  }
}
 
Example #4
Source File: jnamed.java    From dnsjava with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void addCacheNS(Message response, Cache cache, Name name) {
  SetResponse sr = cache.lookupRecords(name, Type.NS, Credibility.HINT);
  if (!sr.isDelegation()) {
    return;
  }
  RRset nsRecords = sr.getNS();
  for (Record r : nsRecords.rrs()) {
    response.addRecord(r, Section.AUTHORITY);
  }
}
 
Example #5
Source File: DNSJavaService.java    From james-project with Apache License 2.0 4 votes vote down vote up
@PostConstruct
public void init() throws Exception {
    LOGGER.debug("DNSService init...");

    // If no DNS servers were configured, default to local host
    if (dnsServers.isEmpty()) {
        try {
            dnsServers.add(InetAddress.getLocalHost().getHostName());
        } catch (UnknownHostException ue) {
            dnsServers.add("127.0.0.1");
        }
    }

    // Create the extended resolver...
    final String[] serversArray = dnsServers.toArray(String[]::new);

    if (LOGGER.isInfoEnabled()) {
        for (String aServersArray : serversArray) {
            LOGGER.info("DNS Server is: " + aServersArray);
        }
    }

    try {
        resolver = new ExtendedResolver(serversArray);
    } catch (UnknownHostException uhe) {
        LOGGER.error("DNS service could not be initialized.  The DNS servers specified are not recognized hosts.", uhe);
        throw uhe;
    }

    cache = new Cache(DClass.IN);
    cache.setMaxEntries(maxCacheSize);
    cache.setMaxNCache(negativeCacheTTL);

    if (setAsDNSJavaDefault) {
        Lookup.setDefaultResolver(resolver);
        Lookup.setDefaultCache(cache, DClass.IN);
        Lookup.setDefaultSearchPath(searchPaths);
        LOGGER.info("Registered cache, resolver and search paths as DNSJava defaults");
    }

    // Cache the local hostname and local address. This is needed because
    // the following issues:
    // JAMES-787
    // JAMES-302
    InetAddress addr = getLocalHost();
    localCanonicalHostName = addr.getCanonicalHostName();
    localHostName = addr.getHostName();
    localAddress = addr.getHostAddress();

    LOGGER.debug("DNSService ...init end");
}
 
Example #6
Source File: DNSJavaServiceTest.java    From james-project with Apache License 2.0 4 votes vote down vote up
public void setCache(Cache c) {
    cache = c;
}