google-ads-java icon indicating copy to clipboard operation
google-ads-java copied to clipboard

Partial proxy for GoogleAdsClient

Open rawatnikita opened this issue 7 months ago • 7 comments

I want to use partial proxy for GoogleAdsClient but cannot find any way to do so. Can someone suggest a way or a workaround for the same. The proxy I want to use does not require authentication, I just need to set the proxy before calling the search stream service.

rawatnikita avatar May 20 '25 14:05 rawatnikita

It'd be helpful to understand the goal of your proxying approach, such as which call(s) you want to proxy. For example, do you want to proxy the service clients returned by googleAdsClient.getLatestVersion().createXyzServiceClient() or something else?

Thanks, Josh, Google Ads API Team

jradcliff avatar May 20 '25 15:05 jradcliff

Yes, I am trying to proxy the service client returned by googleAdsClient. I basically want to route calls through my company's proxy server and I believe I'll have to proxy on the service clients for that. Please let me know if that is the right approach.

rawatnikita avatar May 20 '25 16:05 rawatnikita

Thanks for clarifying. Would using setEndpoint(...) when building the GoogleAdsClient work?

jradcliff avatar May 20 '25 16:05 jradcliff

I tried setEndpoint("proxyHost:proxyPort") and also setEndpoint("proxyHost/googleads.googleapis.com:443") but it didn't work.

rawatnikita avatar May 20 '25 16:05 rawatnikita

Got it. I just remembered: you should be able to use the standard Java system properties. For example:

-Dhttps.proxyHost=YOUR_PROXY_POST -Dhttps.proxyPort=YOUR_PROXY_PORT

Please give that a try and let us know how it goes.

Thanks

jradcliff avatar May 20 '25 16:05 jradcliff

I am already using System.setProperty() to set the proxy and it is working fine. But I don't want to set proxy for all calls as different services in my application will use different proxies.How can I set proxy only for GoogleAdsClient?

rawatnikita avatar May 20 '25 16:05 rawatnikita

You would need to use the 2nd or 3rd option described in https://github.com/grpc/grpc-java/issues/9057#issuecomment-1090380277.

For example, you could call the static method ProxySelector.setDefault(yourProxySelector), where yourProxySelector is a ProxySelector subclass that implements the select method to determine which proxy to use for a given URI. See https://docs.oracle.com/en/java/javase/12/docs/api/java.base/java/net/ProxySelector.html.

jradcliff avatar May 20 '25 18:05 jradcliff