I confused on how it works. So creating a new post to get it resolved.
See I have defined a Target Server and calling it in Target Endpoint HTTP Target Connection.
Now I want to re-write the target with Javascript.
//context.setVariable("target.copy.pathsuffix", false);
var name =context.getVariable("name");
if(name !== null ){
var targeturl = context.getVariable("target.url");
context.setVariable("target.url", targeturl+"/siddharth1/sandbox/volvos/"+name);
}
Using the above code I can re-write the target if I hardcode the targe url in Http target connections.
How can I re-write target by Java Script if I use Target Servers?
What I know is, for Target servers, the following variables are available in the âTarget Responseâ flow,
target.host,target.ip,request.path.
1 Like
anilsr
June 30, 2016, 4:44pm
2
@Barahalikar Siddharth
You mean the changing the target server dynamically in API flow in run time ? You mean you have defined target server like below,
<TargetEndpoint name="default">
<HTTPTargetConnection>
<LoadBalancer>
<Server name="target1" />
</LoadBalancer>
<Path>/test</Path>
</HTTPTargetConnection>
</TargetEndpoint>
And , Would you like to change the target server name to something like âtarget2â in the API Proxy ?
I am afraid , As far as i know, itâs not allowed. Since you can actually define more than one target server inside load balancer & changing one target server in API Proxy flow doesnât make any sense since multiple servers will be used for load balancing.
Yes, @Anil Sagar I have defined it in that way.
If target1 is api.user.com
I want to append url to target 1 through js as, target1+â/nameâ === api.user.com/name .
Is this not possible through Service callout/kvm/ any other?
anilsr
June 30, 2016, 5:36pm
4
Very Interesting Use Case @Barahalikar Siddharth ,
I can see a way to implement same ,
Define an API Proxy with target server config like below,
<HTTPTargetConnection>
<LoadBalancer>
<Server name="target1"/>
<Server name="target2"/>
</LoadBalancer>
<Path>/{request.queryparam.dynamicPath}</Path>
</HTTPTargetConnection>
Basically, use any flow variable to update target basePath like above. Keep us posted.
3 Likes
In proxyendpoint define like below
(proxy.pathsuffix MatchesPath â/Testâ)
BinayaTest
Then Go to the Target Endpoints name BinayaTest
BinayaTest is my traget server where you can define the URL.
/v1/availability
Then call the below java script code
context.setVariable(âtarget.copy.pathsuffixâ, false); preflow of the Tragetendpoint BinayaTest
Try This
This solution worked flawlessly for me.
Hi,
I am trying to append variable {env} in the middle of the Target URL.
For example,
https://myManager.svc .{env}.myValue/accounts/{accounts_id}
It is working fine in the ServiceCallout policy but when I tried to use in Target - default.xml, it is not working.
I donât want to use the JavaScript and RouteRule options.
If any one know about - how to append or concat variable (Example here - {env}) in the Target URL really very help ful.
Hi @Rajeev Chaturvedi , AFAIK we cant do that in TargetEndpont default.xml.
You need to use a JS policy on Targetendpoint preflow to set the target.url
var env = context.getVariable(xyz);
var accounts_id = ap235xyz;
var targetURL = 'https://myManager.svc.' + env + '.myValue/accounts/' + accounts_id;
context.setVariable("target.url",targetURL);<br>
BTW this is a very old post, please create a new post with, issue & requirement.
Is it possible to override port number during runtime? @Anil Sagar @ Google