Reputation: 1973
I am using Google's LanguageServiceClient
from com.google.cloud:google-cloud-vision:1.16.0
, and ImageAnnotatorClient
from com.google.cloud:google-cloud-language:1.16.0
.
They are used in a project that runs inside a private VPN. The company's infrastructure dictates that accessing external services must be done through a forward proxy. Furthermore, all forward proxies in the VPN are mandated to be on HTTP, not HTTPS.
So I have a forward proxy xx.xx.xx.xx, and all requests like http://xx.xx.xx.xx/somePath get forwarded to https://language.googleapis.com/somePath. I tested this with some curl requests and they way work correctly.
I have changed the endpoint as follows:
LanguageServiceSettings serviceSettings = LanguageServiceSettings.newBuilder()
.setEndpoint("xx.xx.xx.xx:80")
//the default value of this is "language.googleapis.com:443"
.build();
languageServiceClient = LanguageServiceClient.create(serviceSettings);
However, the client seems to be hitting the new endpoint via HTTPS. I can't figure out how to set the scheme. Any help would be appreciated.
Upvotes: 0
Views: 481
Reputation: 1973
Turns out that even getting a forward proxy on HTTPS would not have worked, since the library rejects requests upon seeing a mismatch between the SSL certificate domain (language.googleapis.com) and the request URL (the forward proxy IP).
Instead, I stuck with the HTTP proxies and made it work as follows:
HttpHost proxy = new HttpHost("xx.xx.xx.xx", 80);
HttpTransportFactory transportFactory = () -> new ApacheHttpTransport.Builder()
.setProxy(proxy)
.build();
CredentialsProvider credentialsProvider = () -> GoogleCredentials.getApplicationDefault(transportFactory);
LanguageServiceSettings serviceSettings = LanguageServiceSettings.newBuilder()
.setCredentialsProvider(credentialsProvider)
.build();
LanguageServiceClient languageServiceClient = LanguageServiceClient.create(serviceSettings);
This takes care of the auth step, however, the actual request is still being made to language.googleapis.com.
This cannot be similarly overriden since the request is made using GRPC instead of Google Http. GRPC does not have any provision for setting a proxy in code, as far as I can tell. One way around this is to set this environment variable:
export GRPC_PROXY_EXP=xx.xx.xx.xx:80
Upvotes: 2