From 3ae7ae2f71ef074af5f62ada541ac773d0203c08 Mon Sep 17 00:00:00 2001 From: Puja Jagani Date: Tue, 14 Nov 2023 15:06:08 +0530 Subject: [PATCH] [java] Reverting changes made regarding setting proxy via system properties @joerg1985's comment on the change was correct. Java defaults to using the DefaultProxySelector which uses the system properties. Apologies, I headed down the wrong path earlier. Fixing it as part of this change. --- .../remote/http/jdk/JdkHttpClient.java | 44 ++++++++----------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java b/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java index cac66af47d3b0..7e94e812e3920 100644 --- a/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java +++ b/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java @@ -124,34 +124,28 @@ protected PasswordAuthentication getPasswordAuthentication() { builder = builder.authenticator(authenticator); } - String proxyHost = System.getProperty("http.proxyHost"); - String proxyPort = System.getProperty("http.proxyPort"); - - Proxy proxy = - (proxyHost != null && proxyPort != null) - ? new Proxy( - Proxy.Type.HTTP, new InetSocketAddress(proxyHost, Integer.parseInt(proxyPort))) - : config.proxy(); - - ProxySelector proxySelector = - new ProxySelector() { - @Override - public List select(URI uri) { - if (proxy == null) { + Proxy proxy = config.proxy(); + if (proxy != null) { + ProxySelector proxySelector = + new ProxySelector() { + @Override + public List select(URI uri) { + if (proxy == null) { + return List.of(); + } + if (uri.getScheme().toLowerCase().startsWith("http")) { + return List.of(proxy); + } return List.of(); } - if (uri.getScheme().toLowerCase().startsWith("http")) { - return List.of(proxy); - } - return List.of(); - } - @Override - public void connectFailed(URI uri, SocketAddress sa, IOException ioe) { - // Do nothing - } - }; - builder = builder.proxy(proxySelector); + @Override + public void connectFailed(URI uri, SocketAddress sa, IOException ioe) { + // Do nothing + } + }; + builder = builder.proxy(proxySelector); + } SSLContext sslContext = config.sslContext(); if (sslContext != null) {