This works.
HttpHost proxy = new HttpHost(properties.getProxyHost(), properties.getProxyPort());
RequestConfig config = RequestConfig.custom()
.setProxy(proxy)
.build();
URI uri = new URIBuilder(properties.getUri())
.build();
HttpGet request = new HttpGet(uri);
request.setConfig(config);
HttpResponse response = client.execute(request);
But when I try to set the proxy at startup
java \
${JAVA_OPTS} \
-Dhttp.proxyHost=my-proxy \
-Dhttp.proxyPort=my-port \
-jar ${PROJECT_DIR}/${TARGET_JAR} \
And run this script
URI uri = new URIBuilder(properties.getUri())
.build();
HttpGet request = new HttpGet(uri);
HttpResponse response = client.execute(request);
It fails with this error
I/O exception (java.net.SocketException) caught when processing request to {s}->https://site-address:443: Network is unreachable (connect failed)
Why does it fail? Isn't this basicaly the same thing?
Edit
My dependency
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>