Skip to content

Commit

Permalink
[java] Reverting changes made regarding setting proxy via system prop…
Browse files Browse the repository at this point in the history
…erties

@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.
  • Loading branch information
pujagani committed Nov 14, 2023
1 parent b65ad22 commit 3ae7ae2
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Proxy> select(URI uri) {
if (proxy == null) {
Proxy proxy = config.proxy();
if (proxy != null) {
ProxySelector proxySelector =
new ProxySelector() {
@Override
public List<Proxy> 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) {
Expand Down

0 comments on commit 3ae7ae2

Please sign in to comment.