Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

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,660
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