Java Code Examples for org.xbill.DNS.Lookup#setDefaultCache()

The following examples show how to use org.xbill.DNS.Lookup#setDefaultCache() . 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: 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 2
Source File: DNSJavaServiceTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@After
public void tearDown() throws Exception {
    dnsServer.setCache(null);
    dnsServer = null;
    Lookup.setDefaultCache(defaultCache, DClass.IN);
    Lookup.setDefaultResolver(defaultResolver);
    Lookup.setDefaultSearchPath(defaultSearchPaths);
}
 
Example 3
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");
}