Skip to content

Commit 914217c

Browse files
tomas-sexenianBeta Bot
authored andcommitted
Revert branch 'genexuslabs:fix-doctype-disallowed' into beta
1 parent 018ed82 commit 914217c

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

java/src/main/java/com/genexus/internet/HttpClientJavaLib.java

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,35 +66,45 @@
6666

6767
public class HttpClientJavaLib extends GXHttpClient {
6868

69-
private static final DnsResolver FIRST_IP_DNS_RESOLVER = host -> {
70-
InetAddress[] allIps = SystemDefaultDnsResolver.INSTANCE.resolve(host);
71-
if (allIps != null && allIps.length > 1) {
72-
return new InetAddress[]{allIps[0]};
69+
private static class FirstIpDnsResolver implements DnsResolver {
70+
private final DnsResolver defaultDnsResolver = new SystemDefaultDnsResolver();
71+
72+
@Override
73+
public InetAddress[] resolve(final String host) throws UnknownHostException {
74+
InetAddress[] allIps = defaultDnsResolver.resolve(host);
75+
if (allIps != null && allIps.length > 0) {
76+
return new InetAddress[]{allIps[0]};
77+
}
78+
return allIps;
7379
}
74-
return allIps;
75-
};
80+
}
7681

77-
private static boolean isFirstIpDnsEnabled() {
82+
private static String getGxIpResolverConfig() {
7883
String name = "GX_USE_FIRST_IP_DNS";
7984
String gxDns = System.getProperty(name);
8085
if (gxDns == null || gxDns.trim().isEmpty()) {
8186
gxDns = System.getenv(name);
8287
}
83-
return gxDns != null && gxDns.trim().equalsIgnoreCase("true");
88+
if (gxDns != null && gxDns.trim().equalsIgnoreCase("true")) {
89+
return gxDns.trim();
90+
} else {
91+
return null;
92+
}
8493
}
8594

95+
8696
public HttpClientJavaLib() {
8797
getPoolInstance();
8898
ConnectionKeepAliveStrategy myStrategy = generateKeepAliveStrategy();
8999
HttpClientBuilder builder = HttpClients.custom()
90100
.setConnectionManager(connManager)
91101
.setConnectionManagerShared(true)
92102
.setKeepAliveStrategy(myStrategy);
93-
if (isFirstIpDnsEnabled()) {
94-
builder.setDnsResolver(FIRST_IP_DNS_RESOLVER);
103+
if (getGxIpResolverConfig() != null) {
104+
builder.setDnsResolver(new FirstIpDnsResolver());
95105
}
96106
httpClientBuilder = builder;
97-
cookies = new BasicCookieStore();
107+
cookies = new BasicCookieStore();
98108
streamsToClose = new Vector<>();
99109
}
100110

@@ -104,11 +114,10 @@ private static void getPoolInstance() {
104114
RegistryBuilder.<ConnectionSocketFactory>create()
105115
.register("http", PlainConnectionSocketFactory.INSTANCE).register("https",getSSLSecureInstance())
106116
.build();
107-
if (isFirstIpDnsEnabled()) {
108-
connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry, FIRST_IP_DNS_RESOLVER);
109-
} else {
110-
connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
111-
}
117+
boolean useCustomDnsResolver = getGxIpResolverConfig() != null;
118+
PoolingHttpClientConnectionManager connManager = useCustomDnsResolver
119+
? new PoolingHttpClientConnectionManager(socketFactoryRegistry, new FirstIpDnsResolver())
120+
: new PoolingHttpClientConnectionManager(socketFactoryRegistry);
112121
connManager.setMaxTotal((int) CommonUtil.val(clientCfg.getProperty("Client", "HTTPCLIENT_MAX_SIZE", "1000")));
113122
connManager.setDefaultMaxPerRoute((int) CommonUtil.val(clientCfg.getProperty("Client", "HTTPCLIENT_MAX_PER_ROUTE", "1000")));
114123

@@ -650,7 +659,7 @@ public void execute(String method, String url) {
650659
resetStateAdapted();
651660
}
652661
}
653-
662+
654663
private synchronized void displayHTTPConnections(){
655664
Iterator<HttpRoute> iterator = storedRoutes.iterator();
656665
while (iterator.hasNext()) {

0 commit comments

Comments
 (0)