Getting null response from REST message

neha501
Giga Contributor

Hi All,

I configured two REST messages with two different end points and I am calling them from FIX script to see how they are working. I am passing one of the variables from the REST Message1 response as query parameter to the second REST message. So for instance if we get response for element1  for 15 times, we need to get the individual response for all those 15 from second REST message. See the sample response from REST message1 below.

"RESPONSE":{"DATE":"2018-12-06T12:18:17Z","TESTS":{"OUTPUT":[{"element0":"2018-12-12T16:50:42Z","element1":"1234","element2":"2018-12-05T16:00:40Z","element3":"CSV","element4":"989.51 KB","element5":{"element6":"Completed"},"element7":"XYZ","element8":"AAA","element9":"XXX"},{"element0":"2018-12-12T16:50:10Z","element1":"1321","element2":"2018-12-05T16:00:35Z","element3":"CSV","element4":"5.33 MB","element5":{"element6":"Completed"},"element7":"WYX","element8":"AAA","element9":"YYY"}, 

Here the issue is that i am getting response as null for some of the element1's. See my code below. I also tried adding HttpTimeout and waitForResponse but there is no change in the response body when I tested that. I also tried testing with the same element1 in postman tool, there i am getting the response but its taking 2 to 3 mins to get the response. 

r.setQueryParameter("element1", newList[j]);

r.setHttpTimeout(200000);
var response = r.executeAsync();
response.waitForResponse(180);
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();

gs.print("response body is" +responseBody);

}
catch(ex) {
var message = ex.getMessage();
}

 

Can anyone please help me with this.

8 REPLIES 8

neha501
Giga Contributor

Hi Aman,

Sorry, I am bit confused with your previous reply. 

Also, I tried executing my code with r.execute() method instead of r.executeAsync(), in this case its not returning any response(not even null). 

Can't we add some other validations to the script to get this issue resolved, instead of having discussions with 3rd party application people. My only concern is that I am getting response from postman when I tried with the same element1 values, but getting late response.

 

charliesdev
Giga Expert

I haven't used "executeAsync", but have several scheduled jobs that do a similar thing.  Maybe 180 mS is too short of a time to wait for a response.

Example of what we do:

	var instanceName = gs.getProperty('instance_name');
	var endpoint = 'ourTestServer';
	if(instanceName == 'ourCompanyName'){
		endpoint = 'ourProdServer';
	}
	// get token
	var tokenMsg = new sn_ws.RESTMessageV2('MT Auth Token', 'Default GET');
	tokenMsg.setStringParameterNoEscape('server_name', endpoint);
	var tokenResponse = tokenMsg.execute();
	var tokenBody = tokenResponse.getBody();
	var tokenStatus = tokenResponse.getStatusCode();
	if(tokenStatus == 200){
		var jsonToken = JSON.parse(tokenBody);
		
		var r = new sn_ws.RESTMessageV2('WeightUnitsRestMsg', 'Default GET');
		r.setStringParameterNoEscape('server_name', endpoint);
		r.setStringParameterNoEscape('theToken', jsonToken["token"]);
		var response = r.execute();
		var responseBody = response.getBody();
		var httpStatus = response.getStatusCode();
		if(httpStatus == 200){
			var wuObjs = JSON.parse(responseBody);

Hi Charlie,

Thanks for your reply!

TimeoutSecs 180 is in seconds, to wait for the response.

neha501
Giga Contributor

I noticed that it is taking 2 to 3 mins to get the response in postman so, I felt that it is a good number. Also, I tried executing this code with r.execute() method instead of r.executeAsync(), in this case its not returning any response(not even null).