Our environment just allows HTTPS connections so they provide us an HTTPS proxy which is the only way of connecting to the outside world. We have to route all traffics through this proxy as well as our Java application (a which uses OkHttp as its HTTP client.
We've setup the proxy like this:
Authenticator proxyAuthenticator = new Authenticator() {
@Override
public Request authenticate(Route route, Response response) throws IOException {
String credential = Credentials.basic(username, password);
return response.request().newBuilder()
.header("Proxy-Authorization", credential)
.build();
}
};
return builder
.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)))
.proxyAuthenticator(proxyAuthenticator)
.build();
And we tested it using squid (as HTTP proxy). But we found out that this doesn't work in the real environment. as the proxy is HTTPS (SSL or TLS tunnelling?) not HTTP.
We could force all other Linux applications like wget to use the https proxy by setting the following environment variable:
export https_proxy='http://domain\user:password@prox-server:port'
But the Java application doesn't work and can't route traffics using this proxy.
BTW we couldn't config JVM to route all traffics through proxy by setting system properties http.proxyHost
, http.proxyPort
, https.proxyHost
, https.proxyPort
etc.
Is there any simple and straightforward way to set HTTPS proxy for a Java application?