Skip to content

Commit 2fbbef3

Browse files
author
gm2552
committed
Fixing DNS resolver spring configuration issue.
1 parent 2f6bddd commit 2fbbef3

2 files changed

Lines changed: 28 additions & 17 deletions

File tree

src/main/java/org/nhindirect/gateway/springconfig/DNSResolverConfig.java

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.nhindirect.gateway.springconfig;
22

33
import java.net.UnknownHostException;
4+
import java.util.Arrays;
5+
import java.util.List;
46

57
import org.apache.commons.lang3.ArrayUtils;
68
import org.apache.commons.lang3.StringUtils;
@@ -11,6 +13,7 @@
1113
import org.springframework.context.annotation.Configuration;
1214
import org.xbill.DNS.ExtendedResolver;
1315
import org.xbill.DNS.Resolver;
16+
import org.xbill.DNS.ResolverConfig;
1417
import org.xbill.DNS.SimpleResolver;
1518

1619
@Configuration
@@ -43,24 +46,23 @@ public ExtendedResolver getDNSResolver() throws Exception
4346
}
4447
}
4548

46-
if (!StringUtils.isEmpty(dnsServers))
49+
final List<String> servers = getDNSServers();
50+
51+
for (String server : servers)
4752
{
48-
for (String server : dnsServers.split(","))
49-
{
50-
// support for IP addresses instead of names
51-
server = server.replaceFirst("\\.$", "");
53+
// support for IP addresses instead of names
54+
server = server.replaceFirst("\\.$", "");
5255

53-
try
54-
{
55-
// create and add a SimpleResolver for each server
56-
SimpleResolver simpleResolver = new SimpleResolver(server);
57-
extendedResolver.addResolver(simpleResolver);
58-
}
59-
catch (UnknownHostException e)
60-
{
61-
LOGGER.warn("Unable to add resolver for " + server, e);
62-
continue;
63-
}
56+
try
57+
{
58+
// create and add a SimpleResolver for each server
59+
SimpleResolver simpleResolver = new SimpleResolver(server);
60+
extendedResolver.addResolver(simpleResolver);
61+
}
62+
catch (UnknownHostException e)
63+
{
64+
LOGGER.warn("Unable to add resolver for " + server, e);
65+
continue;
6466
}
6567
}
6668

@@ -69,4 +71,12 @@ public ExtendedResolver getDNSResolver() throws Exception
6971

7072
return extendedResolver;
7173
}
74+
75+
protected List<String> getDNSServers()
76+
{
77+
final String[] configedServers = (!StringUtils.isEmpty(dnsServers)) ? dnsServers.split(",") :
78+
ResolverConfig.getCurrentConfig().servers();
79+
80+
return Arrays.asList(configedServers);
81+
}
7282
}

src/test/java/org/nhindirect/stagent/TestApplication.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.nhindirect.stagent;
22

3+
import org.nhindirect.gateway.springconfig.KeyStoreProtectionMgrConfig;
34
import org.springframework.boot.SpringApplication;
45
import org.springframework.boot.autoconfigure.SpringBootApplication;
56
import org.springframework.cloud.openfeign.EnableFeignClients;
@@ -9,7 +10,7 @@
910
@SpringBootApplication
1011
@ComponentScan({"org.nhindirect.config", "org.nhind.config"})
1112
@EnableFeignClients({"org.nhind.config.rest.feign"})
12-
@Import(StreamsConfiguration.class)
13+
@Import({StreamsConfiguration.class, KeyStoreProtectionMgrConfig.class})
1314
public class TestApplication
1415
{
1516
public static void main(String[] args)

0 commit comments

Comments
 (0)