Javascript LocalTargetConnection callout

Not applicable

I have two proxies: proxy1 and proxy2. I need to make a callout to proxy2 using javascript in proxy1 flow.

I tried LocalTargetConnection in ServiceCallout policy using Path: /<proxy2>/<somePath> and it works fine but I need to do the same in Javascript policy

I was trying to do it like that

var req = new Request("/<proxy2>/<somePath>", "POST", {"Content-Type":"application/json"}, JSON.stringify(bodyObj));
    var exchange = httpClient.send(req);
	

but I get Error: Connection refused.

How should i create request so it would be resolved to local proxy?

Solved Solved
2 4 409
1 ACCEPTED SOLUTION

Dear @MSaichuk,

The proxy chaining feature using the similar way as you would do in ServiceCallout with LocalTargetConnection is not yet available with Javascript as documented here.

But I think you should be able to make a call from one Proxy to another Proxy in Javascript by giving the complete URL. Have you tried that ?

Thanks,

Amar

View solution in original post

4 REPLIES 4

Not applicable

I'm not 100% sure this is possible at the moment. Couldn't you for now simply definine your bodyObj, then set it via context.setVariable, and finally use a serviceCallout to do the same thing? I realize it's a workaround but it would definitely work, right?

/geir

I thought about that too but it would be much more optimal and simple if I could do it within single JS Policy. Thanks for your answer!

There is no special provision in the Request object available to JavaScript to route to a "local" proxy.

Therefore you will need to manually build the full url including scheme, to get to where you want to go.

If you'd like to take a shortcut, you need to use Proxy chaining, which involves a ServiceCallout or regular HTTPTargetConnection . Read about it here.

Dear @MSaichuk,

The proxy chaining feature using the similar way as you would do in ServiceCallout with LocalTargetConnection is not yet available with Javascript as documented here.

But I think you should be able to make a call from one Proxy to another Proxy in Javascript by giving the complete URL. Have you tried that ?

Thanks,

Amar