I have set the "target.url" variable in the target endpoint but it is not getting set as the trace shows below:
Also this is not getting read by the apigee and the call is failing. The HTTPTargetConnection looks like this:
<HTTPTargetConnection>
<URL>http://sample</URL>
</HTTPTargetConnection>
https://www.googlecloudcommunity.com/gc/Apigee/how-to-use-variables-in-target-endpoint-url/m-p/12464
The above post suggest i modify the target.url in the target endpoint but it is not working as expected. Please help me with this. Thanks in advance.
Solved! Go to Solution.
Hi there,
I'm unable to replicate your issue. I was able to implement a simple target.url change in a hello-world proxy as shown below, take a look at that and let me know how it goes. An important note to make is that the AssignMessage policy must go in the Target Endpoint request flow.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="default">
<PreFlow name="PreFlow">
<Request/>
<Response/>
</PreFlow>
<Flows/>
<PostFlow name="PostFlow">
<Request>
<Step>
<Name>ChangeTarget</Name>
</Step>
</Request>
<Response/>
</PostFlow>
<HTTPTargetConnection>
<URL>https://mocktarget.apigee.net/user</URL>
</HTTPTargetConnection>
</TargetEndpoint>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage continueOnError="false" enabled="true" name="ChangeTarget">
<DisplayName>ChangeTarget</DisplayName>
<Properties/>
<AssignVariable>
<Name>target.url</Name>
<Value>http://mocktarget.apigee.net/user?user=FrodoBaggins</Value>
</AssignVariable>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>
If you're still having issues after reviewing this please post more details about your AssignMessage policy and where it resides in the proxy flow.
Ah, I see the issue now. Your targetUrl is an invalid URL as it is missing "https://" (or maybe just "http://") before the host name. Update your JS policy as shown below
var targetPathSuffix = context.getVariable("targetPathSuffix");
var ehrHost = context.getVariable("tenant.ehrHost");
var targetUrl = "https://" + ehrHost + targetPathSuffix;
context.setVariable("targetUrl",targetUrl);
Hi there,
I'm unable to replicate your issue. I was able to implement a simple target.url change in a hello-world proxy as shown below, take a look at that and let me know how it goes. An important note to make is that the AssignMessage policy must go in the Target Endpoint request flow.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="default">
<PreFlow name="PreFlow">
<Request/>
<Response/>
</PreFlow>
<Flows/>
<PostFlow name="PostFlow">
<Request>
<Step>
<Name>ChangeTarget</Name>
</Step>
</Request>
<Response/>
</PostFlow>
<HTTPTargetConnection>
<URL>https://mocktarget.apigee.net/user</URL>
</HTTPTargetConnection>
</TargetEndpoint>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage continueOnError="false" enabled="true" name="ChangeTarget">
<DisplayName>ChangeTarget</DisplayName>
<Properties/>
<AssignVariable>
<Name>target.url</Name>
<Value>http://mocktarget.apigee.net/user?user=FrodoBaggins</Value>
</AssignVariable>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>
If you're still having issues after reviewing this please post more details about your AssignMessage policy and where it resides in the proxy flow.
The code for the Target Endpoint is :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="default">
<PreFlow name="PreFlow">
<Request>
</Request>
<Response/>
</PreFlow>
<Flows/>
<PostFlow name="PostFlow">
<Request>
<Step>
<Name>JS-set-target-path</Name>
</Step>
<Step>
<Name>AM-set-target-url</Name>
</Step>
</Request>
<Response/>
</PostFlow>
<HTTPTargetConnection>
<URL>http://sample</URL>
</HTTPTargetConnection>
<!--<HTTPTargetConnection>
<Properties/>
<LoadBalancer>
<Server name="EHR-server-2"/>
</LoadBalancer>
<Path>{targetPathSuffix}</Path>
</HTTPTargetConnection>-->
</TargetEndpoint>
The code of the assign message is :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="AM-set-target-url">
<DisplayName>AM-set-target-url</DisplayName>
<AssignVariable>
<Name>target.url</Name>
<Ref>targetUrl</Ref>
</AssignVariable>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>
The code for JS policy is :
var targetPathSuffix = context.getVariable("targetPathSuffix");
var ehrHost = context.getVariable("tenant.ehrHost");
var targetUrl = ehrHost + targetPathSuffix;
context.setVariable("targetUrl",targetUrl);
Please note the the variable "targetUrl" is getting successfully resolved as seen in the screenshot in the original post.
Ah, I see the issue now. Your targetUrl is an invalid URL as it is missing "https://" (or maybe just "http://") before the host name. Update your JS policy as shown below
var targetPathSuffix = context.getVariable("targetPathSuffix");
var ehrHost = context.getVariable("tenant.ehrHost");
var targetUrl = "https://" + ehrHost + targetPathSuffix;
context.setVariable("targetUrl",targetUrl);
The issue is resolved by following the last step. Thanks a lot.