Javascript Not Working for Target.url Update Runtime

Hi Team,

I am trying to update the target.url with context set but it's not working.

I am hitting this url -> 

 

https://xyz-eval-test.apigee.net/v1/edgemicro_proxy_ms/rel/1/pro/2/ws/3/stage/4/techstack/t4/techstackIp/52.170.150.5:8082?techstack=techstack-java

 

 

 

here is my project structure:

EV-URI-EXTRACT

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="EV-URI-EXTRACT">
    <DisplayName>EV-URI-EXTRACT</DisplayName>
    <Properties/>
    <URIPath>
        <Pattern ignoreCase="true">/rel/{rId}/pro/{pId}/ws/{wId}/stage/{sId}/techstack/{techstackId}/techstackIp/{techstackIp}</Pattern>
    </URIPath>
    <QueryParam name="techstack">
        <Pattern>techstack-{techstackName}</Pattern>
    </QueryParam>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <Source clearPayload="false">request</Source>
</ExtractVariables>

 

 target-rewrite

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Javascript async="false" continueOnError="false" enabled="true" timeLimit="200" name="target-rewrite">
    <DisplayName>target-rewrite</DisplayName>
    <Properties/>
    <ResourceURL>jsc://js-example.js</ResourceURL>
</Javascript>

 

proxy-endpoint

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
    <Description/>
    <FaultRules/>
    <Flows/>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <PreFlow name="PreFlow">
        <Request>
            <Step>
                <Name>EV-URI-EXTRACT</Name>
            </Step>
        </Request>
        <Response/>
    </PreFlow>
    <HTTPProxyConnection>
        <BasePath>/v1/edgemicro_proxy_ms</BasePath>
        <Properties/>
        <VirtualHost>default</VirtualHost>
        <VirtualHost>secure</VirtualHost>
    </HTTPProxyConnection>
    <RouteRule name="default">
        <TargetEndpoint>default</TargetEndpoint>
    </RouteRule>
</ProxyEndpoint>

 

target-endpoint

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="default">
    <Description/>
    <FaultRules/>
    <Flows/>
    <PostFlow name="PostFlow">
        <Request>
        </Request>
        <Response>
        </Response>
    </PostFlow>
    <PreFlow name="PreFlow">
        <Request>
            <Step>
                <Name>target-rewrite</Name>
            </Step>
        </Request>
        <Response>
        </Response>
    </PreFlow>
    <HTTPTargetConnection>
        <Properties/>
        <URL>https://mocktarget.apigee.net/</URL>
    </HTTPTargetConnection>
</TargetEndpoint>

 

js-exampls.js

 

if (context.flow=="TARGET_REQ_FLOW") {
     print(context.getVariable("techstackIp")) // PRINTS correct value
     context.setVariable("target.url", context.getVariable("techstackIp"));
     print(context.getVariable("target.url"))// PRINTS In-correct value, prints default target uri
     context.setVariable("target.copy.pathsuffix", false);
}

 

 Any Help? Can someone please help me find out the mistakes I am doing here ?

1 REPLY 1

I think this is a duplicate of this question. I Answered it there.