I have 2 proxies calling internally calling Proxy 1 to Proxy 2 using path chaining. First endpoint in Proxy 2 returns a message back to Proxy 1 for additional processing then it calls Proxy 2 again on a different endpoint.
Proxy 2 needs to use the same target, which was invoked in first call, but with a different endpoint (endpoint basepath is same, but path suffix is different).
I am setting context.setVariable('target.copy.pathsuffix', false); using a javascript in preflow of target endpoint. This worked when on first call on proxy 2 while invoking a Target. In Second call target target.url is blank so I am not able to set path preffix.
Can you please advise?
Here I have simplified:
My proxy uses Target Servers.
The TargetEndpoint looks like this:
<TargetEndpoint name="Sampleservice"> <PreFlow name="PreFlow"> <Request> <Step> <Name>JS-AddPathSuffix</Name> </Step> </Request> </PreFlow> <HTTPTargetConnection> <SSLInfo> <Enabled>true</Enabled> </SSLInfo> <LoadBalancer> <Server name="testserver"/> </LoadBalancer> <Path>/v1/sample</Path> </HTTPTargetConnection> </TargetEndpoint>
This is the logic for AddPathSuffix.js :
context.setVariable('target.copy.pathsuffix', false); var targeturl = context.getVariable('target.url'); context.setVariable('target.url', targeturl + '/contacts' );
I want it to call https://testserver.com/v1/sample/contacts but it is calling https://testserver.com/v1/sample .
How can I append an arbitrary suffix to the target url, when using Target Servers?
Solved! Go to Solution.
When using Target Servers, you can set the path via a message template.
Use this:
<TargetEndpoint name="Sampleservice"> <PreFlow name="PreFlow"> <Request> <Step> <Name>JS-AddPathSuffix</Name> </Step> </Request> </PreFlow> <HTTPTargetConnection> <SSLInfo> <Enabled>true</Enabled> </SSLInfo> <LoadBalancer> <Server name="testserver"/> </LoadBalancer> <Path>/v1/sample{mypathsuffix}</Path> </HTTPTargetConnection> </TargetEndpoint>
And this:
context.setVariable('target.copy.pathsuffix', false); context.setVariable('mypathsuffix', '/contacts');