Separate response from target server on setting target.url from Javascript policy

When we are hardcoding our target server url while creating a proxy in 'Backend Service URL' then we are getting 200 OK as a response

2997-capture-1.jpg

But when we are using JS policy to set our target.url(which is same as above) then we are getting 301 in response.

In JS we are setting target server url with

context.setVariable("target.url", targetserverurl);

2998-capture-2.jpg

Does anyone know where the problem can be .... in apigee routing?? or apigee server?? or in our backend web server ?? or something else like JS policy

Solved Solved
1 9 1,843
1 ACCEPTED SOLUTION

@Atanu Mazumdar,

Thanks for sharing the trace files for successful and failure responses. I had a look through them and notice both the requests are identical when they are passed on to the target server, but we get 301 when Javascript is used to modify the target URL.

1. For testing purpose, can you please set "target.header.host" in the Javascript with the IP address of the target server and see if that works ?

2. Please do provide the following information:

a) What version of Private Cloud are you using ?

b) Have you set the target URL in the target endpoint definition, to the same value as that in the Location header ? If not, what is the targetURL in the target endpoint definition?

c) Can you please check in your backend server code under what circumstances do you set the Location Header ?

Regards,

Amar

View solution in original post

9 REPLIES 9

@Atanu Mazumdar,

Could you please share the trace files for both the requests by clicking on Ask an expert ? I will check and get back to you.

Thanks,

Amar

I have sent you the trace file ...

Hi @Atanu Mazumdar,

Can you try setting context.setVariable("target.copy.pathsuffix", false); before setting the target url and try?

tried .... we are keeping pathsuffix as false

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

This is first line of my Java script

@Atanu Mazumdar , Interesting, Ideally, It should be same unless request to target has been changed between two changes. As you know, 301 is returned by target server not Apigee API Proxy. I strongly feel, Request has been changed between calls which resulted in different response code from the target. Please observe request sent in both the cases including query params, form params, payload, headers. That will throw some light.

Not applicable

This is definitely being generated by your target server. Almost always this is a result of a rewrite rule (mod_rewrite or equivalent) on your web-head. You might be getting something wonky in the target URL - maybe an extraneous character, a control character, or something else that is being intercepted and returned with a new value in the location header.

@Atanu Mazumdar,

Thanks for sharing the trace files for successful and failure responses. I had a look through them and notice both the requests are identical when they are passed on to the target server, but we get 301 when Javascript is used to modify the target URL.

1. For testing purpose, can you please set "target.header.host" in the Javascript with the IP address of the target server and see if that works ?

2. Please do provide the following information:

a) What version of Private Cloud are you using ?

b) Have you set the target URL in the target endpoint definition, to the same value as that in the Location header ? If not, what is the targetURL in the target endpoint definition?

c) Can you please check in your backend server code under what circumstances do you set the Location Header ?

Regards,

Amar

Thanks a lot Amar.

Your first suggestion -> setting "target.header.host" in JS made it work.

Dont know why we need to reset the "target.header.host" again.

@Atanu Mazumdar,

Good to know that the issue is resolved. But I think it's just a workaround to solve the problem. We need to figure out the root cause/proper solution for this issue. Can you please provide the information requested in my previous update ?

Thanks,

Amar