VMware Cloud Community
lshgfksahkjashg
Contributor
Contributor

Setting proxy for RESTHostManager.createTransientHostFrom() not working

Hello folks,

I tried to invoke a URL request via RESTHostManager.createTransientHostFrom(), where the the proxy is set programmatically.

But it seems it does not pick up the proxy setting. I used the script I found at

Executes a transient RESTOperation for a transient RESTHost · GitHub

I replaced the proxy setting with our settings:

host.proxyHost = "<nice proxy server>";

host.proxyPort = 81;

I always get a timeout.

If I do the same request via a permanent REST host from the inventory with proper proxy settings it works.

So, I am stuck. Has somebody a hint for me?

Thx

Cheers

Roland

5 Replies
qc4vmware
Virtuoso
Virtuoso

Can you supply your full code?  In the spots where I use these I do something along these lines:

var restHost = RESTHostManager.getHost(hostResource.name);

var transientRestHost = RESTHostManager.createTransientHostFrom(restHost);

Works like a charm for me.

Reply
0 Kudos
lshgfksahkjashg
Contributor
Contributor

I build up a new REST host with proxy settings. But the proxy settings have no effect.

// Create a transient RESTHost
// If given user/password, uses Basic auth in Shared Session mode
function createHost(url, user, pw) {
System.log("Creating transient REST host with base URL: " + url);
var host = new RESTHost(url);
host.name = generateNameFromUrl(url);
host.url = url;
host.hostVerification = false;
host.proxyHost = "<my proxy server>";
host.proxyPort = <my proxy port>;
host.authentication = createSharedBasicAuth(user, pw);
host = RESTHostManager.createTransientHostFrom(host);
RESTHostManager.reloadConfiguration();
return host;
}

I know this, because if I use the a host with the same settings from the inventory (where the proxy is defined as well) it works.

So it seems, that in in this code the proxy settings have no effect.

Btw, I am using vRO 7.5. But didn't work for older versions as well...

Cheers

Roland

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee

I'm not sure that RESTHostManager.createTransientHostFrom(host) copies the proxy host/port from the host passed as an argument.

Could you try to set the proxy host/port on the result host object _after_ the call to this method?

qc4vmware
Virtuoso
Virtuoso

I agree I do all mods after creating the transient rest host as well.

Reply
0 Kudos
lshgfksahkjashg
Contributor
Contributor

Set the proxy after host creation:

// Create a transient RESTHost

// If given user/password, uses Basic auth in Shared Session mode

function createHost(url, user, pw) {

    System.log("Creating transient REST host with base URL: " + url);

    var host = new RESTHost(url);

    host.name = generateNameFromUrl(url);

    host.url = url;

    host.hostVerification = false;

    host.proxyHost = null;

    host.proxyPort = 0;

    host.authentication = createSharedBasicAuth(user, pw);

    host = RESTHostManager.createTransientHostFrom(host);

    // set proxy after object has been created, but request times out as well

    // see https://communities.vmware.com/message/2859238#2859238

    host.proxyHost = "<proxy server>";

    host.proxyPort = 81;

    // if proxyAuthentication is set to null, the request cannot be executed at all

    // host.proxyAuthentication = null;

    RESTHostManager.reloadConfiguration();

    return host;

}

I get a timeout as well. Did not work... Smiley Sad

Reply
0 Kudos