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.
Solved! Go to Solution.
Very Interesting Use Case @Barahalikar Siddharth ,
I can see a way to implement same ,
<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.
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?
Very Interesting Use Case @Barahalikar Siddharth ,
I can see a way to implement same ,
<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.
This solution worked flawlessly for me.
Is it possible to override port number during runtime? @Anil Sagar @ Google
In proxyendpoint define like below
<RouteRule name="BinayaRoute">
<Condition>(proxy.pathsuffix MatchesPath "/Test") </Condition>
<TargetEndpoint>BinayaTest</TargetEndpoint>
</RouteRule>
Then Go to the Target Endpoints name BinayaTest
BinayaTest is my traget server where you can define the URL.
<HTTPTargetConnection>
<Properties/>
<LoadBalancer>
<Server name="BinayaTest"/>
</LoadBalancer>
<Path>/v1/availability</Path>
</HTTPTargetConnection>
Then call the below java script code
context.setVariable("target.copy.pathsuffix", false); preflow of the Tragetendpoint BinayaTest
Try This
Hi,
I am trying to append variable {env} in the middle of the Target URL.
For example,
<URL>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.
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |