From 062e333a62a1302b33301b917fe9968bbcec461f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Sexenian?= <99925035+tomas-sexenian@users.noreply.github.com> Date: Wed, 6 Aug 2025 11:35:11 -0300 Subject: [PATCH 1/2] Do not override resolve method --- .../genexus/internet/HttpClientJavaLib.java | 43 ++++++++----------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/java/src/main/java/com/genexus/internet/HttpClientJavaLib.java b/java/src/main/java/com/genexus/internet/HttpClientJavaLib.java index 630729d1f..9c9184ab0 100644 --- a/java/src/main/java/com/genexus/internet/HttpClientJavaLib.java +++ b/java/src/main/java/com/genexus/internet/HttpClientJavaLib.java @@ -66,33 +66,23 @@ public class HttpClientJavaLib extends GXHttpClient { - private static class FirstIpDnsResolver implements DnsResolver { - private final DnsResolver defaultDnsResolver = new SystemDefaultDnsResolver(); - - @Override - public InetAddress[] resolve(final String host) throws UnknownHostException { - InetAddress[] allIps = defaultDnsResolver.resolve(host); - if (allIps != null && allIps.length > 0) { - return new InetAddress[]{allIps[0]}; - } - return allIps; + private static final DnsResolver FIRST_IP_DNS_RESOLVER = host -> { + InetAddress[] allIps = SystemDefaultDnsResolver.INSTANCE.resolve(host); + if (allIps != null && allIps.length > 1) { + return new InetAddress[]{allIps[0]}; } - } + return allIps; + }; - private static String getGxIpResolverConfig() { + private static boolean isFirstIpDnsEnabled() { String name = "GX_USE_FIRST_IP_DNS"; String gxDns = System.getProperty(name); if (gxDns == null || gxDns.trim().isEmpty()) { gxDns = System.getenv(name); } - if (gxDns != null && gxDns.trim().equalsIgnoreCase("true")) { - return gxDns.trim(); - } else { - return null; - } + return gxDns != null && gxDns.trim().equalsIgnoreCase("true"); } - public HttpClientJavaLib() { getPoolInstance(); ConnectionKeepAliveStrategy myStrategy = generateKeepAliveStrategy(); @@ -100,11 +90,11 @@ public HttpClientJavaLib() { .setConnectionManager(connManager) .setConnectionManagerShared(true) .setKeepAliveStrategy(myStrategy); - if (getGxIpResolverConfig() != null) { - builder.setDnsResolver(new FirstIpDnsResolver()); + if (isFirstIpDnsEnabled()) { + builder.setDnsResolver(FIRST_IP_DNS_RESOLVER); } httpClientBuilder = builder; - cookies = new BasicCookieStore(); + cookies = new BasicCookieStore(); streamsToClose = new Vector<>(); } @@ -114,10 +104,11 @@ private static void getPoolInstance() { RegistryBuilder.create() .register("http", PlainConnectionSocketFactory.INSTANCE).register("https", getSSLSecureInstance()) .build(); - boolean useCustomDnsResolver = getGxIpResolverConfig() != null; - PoolingHttpClientConnectionManager connManager = useCustomDnsResolver - ? new PoolingHttpClientConnectionManager(socketFactoryRegistry, new FirstIpDnsResolver()) - : new PoolingHttpClientConnectionManager(socketFactoryRegistry); + if (isFirstIpDnsEnabled()) { + connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry, FIRST_IP_DNS_RESOLVER); + } else { + connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry); + } connManager.setMaxTotal((int) CommonUtil.val(clientCfg.getProperty("Client", "HTTPCLIENT_MAX_SIZE", "1000"))); connManager.setDefaultMaxPerRoute((int) CommonUtil.val(clientCfg.getProperty("Client", "HTTPCLIENT_MAX_PER_ROUTE", "1000"))); @@ -675,7 +666,7 @@ public void execute(String method, String url) { resetStateAdapted(); } } - + private synchronized void displayHTTPConnections(){ Iterator iterator = storedRoutes.iterator(); while (iterator.hasNext()) { From a427a1cf2c0cf4347fa6a37d92c6b835fe4097e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Sexenian?= <99925035+tomas-sexenian@users.noreply.github.com> Date: Thu, 7 Aug 2025 16:29:35 -0300 Subject: [PATCH 2/2] Just one IP is enough --- java/src/main/java/com/genexus/internet/HttpClientJavaLib.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/src/main/java/com/genexus/internet/HttpClientJavaLib.java b/java/src/main/java/com/genexus/internet/HttpClientJavaLib.java index 9c9184ab0..05e6c942b 100644 --- a/java/src/main/java/com/genexus/internet/HttpClientJavaLib.java +++ b/java/src/main/java/com/genexus/internet/HttpClientJavaLib.java @@ -68,7 +68,7 @@ public class HttpClientJavaLib extends GXHttpClient { private static final DnsResolver FIRST_IP_DNS_RESOLVER = host -> { InetAddress[] allIps = SystemDefaultDnsResolver.INSTANCE.resolve(host); - if (allIps != null && allIps.length > 1) { + if (allIps != null && allIps.length > 0) { return new InetAddress[]{allIps[0]}; } return allIps;