Configuring the Javascript callout to use a Webproxy Server for httpClient requests

Not applicable

We are working with an on-prem deployment of Apigee Edge. All calls going out to the internet through the message processors pass through a web proxy server.

When using the httpClient.get() method (async-callout sample), in Javascript if the call needs to go out to the internet it will time out, my guess is because it's trying to go directly instead of using the proxy.

I found that if I create an Edge-proxy to the target that I'm trying to reach, I can hit the same endpoints that were timing out and get the response that I wanted, but this is not ideal (see example):

Let's call the two proxies in question Proxy A and Proxy B:

Proxy A is deployed to https://sample-sandbox.api.abc.com/v1/apikey and passes through to http://weather.yahooapis.com/ via the webproxy using the use.proxy property

Proxy B is deployed to https://sample-sandbox.api.abc.com/v1/async-callout and has a javascript policy on it that uses the javascript file called 'callout.js'

callout.js (Not ideal solution)

//What I find to be not ideal here is Proxy B goes through Proxy A instead of reaching straight out through the web proxy itself

var paloAlto = httpClient.get('https://sample-sandbox.api.abc.com/v1/apikey/forecastrss?apikey=Key&w=2467861'); 
context.session['paloAlto'] = paloAlto;

var anchorage = httpClient.get('https://sample-sandbox.api.abc.com/v1/apikey/forecastrss?apikey=Key&w=2354490'); 
context.session['anchorage'] = anchorage;

var honolulu = httpClient.get('https://sample-sandbox.api.abc.com/v1/apikey/forecastrss?apikey=Key=2423945');
context.session['honolulu'] = honolulu;

var newyork = httpClient.get('https://sample-sandbox.api.abc.com/v1/apikey/forecastrss?apikey=Key&w=2459115');
context.session['newyork'] = newyork;

var dublin = httpClient.get('https://sample-sandbox.api.abc.com/v1/apikey/forecastrss?apikey=Key&w=560743');
context.session['dublin'] = dublin;

callout.js (Ideal solution)

var paloAlto = httpClient.get('http://weather.yahooapis.com/forecastrss?w=2467861'); 
context.session['paloAlto'] = paloAlto;

var anchorage = httpClient.get('http://weather.yahooapis.com/forecastrss?w=2354490'); 
context.session['anchorage'] = anchorage;

var honolulu = httpClient.get('http://weather.yahooapis.com/forecastrss?w=2423945');
context.session['honolulu'] = honolulu;

var newyork = httpClient.get('http://weather.yahooapis.com/forecastrss?w=2459115');
context.session['newyork'] = newyork;

var dublin = httpClient.get('http://weather.yahooapis.com/forecastrss?w=560743');
context.session['dublin'] = dublin;

My question: Is it possible to configure httpClient to use the web proxy server?

Or is the best route to just write our own with plain javascript using either XMLHttpRequest(s) or some library and import that script into each policy that has scripts that need to reach out?

Solved Solved
1 9 5,519
1 ACCEPTED SOLUTION

Not applicable

Am I correct to assume that httpClient cannot make requests through a web proxy server?

View solution in original post

9 REPLIES 9

I don't know a good way to use the JavaScript http client to do what you describe.

You said that you can create an Edge proxy to connect to the target. I suppose you're using the http proxy settings in the HttpTargetConnection. And you said this is not ideal. I'm guessing the reason it's not ideal is... that the primary target for the proxy is not this thing. You want to callout to 2 different systems.

Do you know about the Servicecallout policy? It can be configured with an HttpTargetConnection, which means you could specify the "use.proxy" property. Would that satisfy?

So I don't have a particular use case in mind and probably should have included some code/policies with the original post (I'll add those here in a bit).

The reason I want to know about getting httpClient.get() to use the web proxy is because I want to know if I can, with certainty, tell new users to our edge deployment that they can or cannot use it.

I have updated my post to better reflect what I find ideal vs not ideal.

And if the answer is just tell users to simply use servicecallout instead of httpclient, then that is fine for my purposes. I just want to know what if it is possible to have the httpclient mind the webproxy.

Not applicable

Am I correct in assuming that the httpClient cannot send requests through a web proxy server then?

Not applicable

Am I correct to assume that httpClient cannot make requests through a web proxy server?

You are correct. Currently there is no way to configure the JS httpClient to utilize the httpProxy server configured for Edge. We have it as an enhancement request. For your reference, our internal ticket number is APIRT-2587.

Hi @DChiesa !

I'm new to googlecloudcommunity.
Is there a way I can check the APIRT-2587 ticket's status or can you provide some update?

Thanks,
Alex

In Apigee hybrid, it is possible to configure an http proxy. See the documentation.

For Apigee Private Cloud, there is a different configuration. See here.

For Apigee X or Edge,  this question is irrelevant. 

Thank you! I'll take a look into that and if it is currently enabled at us or not.