Issue with JS Code in apigee

Hi

I’m badly stuck with one issue right now, if you can please shed some light. Initially I worked with AssignMessage policy using following settings :

<AssignMessage name='AM-1'>
  <AssignVariable> 
    <Name>target.copy.queryparams</Name> 
    <Value>true</Value> 
    <Ref/> 
  </AssignVariable> 
  <AssignVariable> 
    <Name>target.copy.pathsuffix</Name> 
    <Value>false</Value> 
    <Ref/> 
  </AssignVariable> 
  <AssignVariable> 
    <Name>targetpath</Name> 
    <Value>/v5/addresses/find</Value> 
    <Ref/> 
  </AssignVariable>
</AssignMessage>

when calling APIGEE svc, my URL is :

https://apidev02.ftr.com/address/v1/autaddressqualification/v5/addresses/find?address=streeaddress&city=abdc&state=TX&zip=750454

which using AssignMessage policy transforms to :

http://addressqualification.stg.corp.ftr.com/v5/addresses/find?address=streeaddress&city=abdc&state=...54 (which is perfect)

but when I’m trying to do the same thing using JavaScript, as I need to add some conditional logic before setting {targetPath}, using following javascript code :

context.setVariable("targert.copy.pathsuffix", false);

context.setVariable("targert.copy.queryparams", true);

context.setVariable("targetpath", "/v5/address/find");

my outbound URL is getting transformed to :

http://addressqualification.stg.corp.ftr.com/v5/address/find/autaddressqualification/v5/addresses/fi...

Solved Solved
0 8 311
1 ACCEPTED SOLUTION

See here:

https://community.apigee.com/answers/58814/view.html

Also I looked in your code. You have a typo. You are using "targert" and not "target".

your code:

context.setVariable("targert.copy.pathsuffix", false);
context.setVariable("targert.copy.queryparams", false);

Correct code:

context.setVariable("target.copy.pathsuffix", false);
context.setVariable("target.copy.queryparams", false);

View solution in original post

8 REPLIES 8

What is your question? I'm not clear on the problem you're facing.

Can you state it more explicitly for me, please?

You described what you're trying, and what you're seeing.

What do you expect to see?

Where is the JS policy attached?

I'm calling the javascript code from TargetEndpointPoint Preflow :

<TargetEndpoint name="autaddressqualification"> <Description/> <FaultRules/> <PreFlow name="PreFlow"> <Request> <Step> <Name>JS-SetHeaders.js</Name> </Step> </Request> <Response/> </PreFlow>

and my javascript code is like this :

context.setVariable("targert.copy.pathsuffix", false); context.setVariable("targert.copy.queryparams", false);

var uripath = "/v5/address/find"; context.setVariable("targetpath", uripath + "?address=805%20S%20Central%20expy&city=allen&state=TX&zip=75013");

I want to see my target URL to look like this :

http://addressqualification.stg.corp.ftr.com/v5/addresses/find?address=streetaddress&city=citya&stat...

but instead it comes out like this (which is wrong):

http://addressqualification.stg.corp.ftr.com/v5/address/find/autaddressqualification/v5/addresses/fi...

Attaching the code itself here.

address-v1-rev2-2019-01-31.zip

my main objective is to set the correct targetURL using javascript code and for host information I need to read it from LoadBalancer like this :

<HTTPTargetConnection> <LoadBalancer> <Server name="AccessCSSAddress"/> <!--Create the provider endpoint host & port informaton under Environment Configration/Target Servers --> </LoadBalancer> <Path>{targetpath}</Path> </HTTPTargetConnection>

Does anyone has any update on this ??

Using javascript I'm unable to construct my target URL like this:

http://addressqualification.stg.corp.ftr.com/v5/addresses/find?address=streetaddress&city=citya&stat...

with my HTTPTargetConnection defined like this :

<HTTPTargetConnection> 
  <LoadBalancer> 
    <Server name="AccessCSSAddress"/> 
    <!--Create the provider endpoint host & port informaton under Environment Configration/Target Servers --> 
  </LoadBalancer> 
  <Path>{targetpath}</Path> 
</HTTPTargetConnection>

If I got the route of setting target.url using JS , then I have NO way to access : context.getVariable("loadbalancing.targetserver") as this context variable gets set in response flow only and NULL gets returned for the request flow.

Can someone please help, how can I proceed here ??

Can someone please help, how can I proceed here ??

Sorry, I'm sure it's frustrating. but I don't understansd the problem you're facing.

How to proceed doing WHAT?

  1. What is your goal? Try to be specific and relate it to something in Apigee Edge.
  2. What are you trying? Be specific and detailed.
  3. What results are you seeing?
  4. What results do you expect to see, or desire to see?

You are clearly experiencing a problem, but I have read both of your messages and I cannot figure out what the problem is. This second message seems totally different than the first. I'm at a loss.

@Dino-at-Google - Hi Dino, you got any updates for me ??

my issue still not resolved

See here:

https://community.apigee.com/answers/58814/view.html

Also I looked in your code. You have a typo. You are using "targert" and not "target".

your code:

context.setVariable("targert.copy.pathsuffix", false);
context.setVariable("targert.copy.queryparams", false);

Correct code:

context.setVariable("target.copy.pathsuffix", false);
context.setVariable("target.copy.queryparams", false);

Thank you so much for helping me out, yes that was one of the major issue which was causing the outbound URL to get build up incorrectly.

Thanks once again Dino !!