Jmeter not showing JSON response - json

I am not sure, if I am missing something but unable to find on google as well.
I am looking into some features of Jmeter. I used postman as well.
We have API POST request and it returns JSON response.
While hitting my API from Postman, I am getting 'JSON' response. (i.e. no issues) and API triggers my service.
Now, if hit from Jmeter. Response if 200 and my service trigger too. But in response I am getting some code or key rather JSON values.
Like 'e5e9e97a9ba2144b448c8b150498b5a0'.
Sample HTTP Request:
Thread Name: First_API_Test 1-1
Sample Start: 2019-03-28 15:48:33 IST
Load time: 7608
Connect Time: 0
Latency: 7608
Size in bytes: 492
Sent bytes:0
Headers size in bytes: 127
Body size in bytes: 365
Sample Count: 1
Error Count: 0
Data type ("text"|"bin"|""): text
Response code: 200
Response message: HTTP/1.1 200
HTTPSampleResult fields:
ContentType: application/json;charset=UTF-8
DataEncoding: UTF-8
I tried changing HTTP Header Manager, but no luck.
I tried 'View Result Tree' JSON drop-down, but that was my bad to try because that will work once I get response. I am not getting response at all.
I search google and stackoverflow, but for JSON, everyone talking about handling/validating JSON response using JSON Extractor but for me I am getting JSON response at all.
I tried to store the output but here too I am getting this code stored in generated output file.
....
</requestHeader>
<responseData class="java.lang.String">e5e9e97a9ba2144b448c8b150498b5a0</responseData>
<responseFile class="java.lang.String"></responseFile>
<cookies class="java.lang.String"></cookies>
...
Expected result from Postman is:
{
"outgoingFileId": "25808",
"status": "Generated",
"createdDate": NA,
"reconcileStatus": null,
"failureMessage": NA,
"successMessage": NA,
"executionTS": 1552912975190,
"nextPayload": "{\"presentTS\":1553696530996,\"lastExecution\":1552912975190}"
}

This is caused because in Advanced tab of HTTP Request Save response as MD5 hash? is checked (you want to uncheck it)
Save response as MD5 hash? If this is selected, then the response is not stored in the sample result. Instead, the 32 character MD5 hash of the data is calculated and stored instead. This is intended for testing large amounts of data.

I think. I missed. I was using latest version 5.1.1.r1855137
Under Http request by default option 'Save response MD5 Hash?' was checked.
'un-check' resolved the issue.

Not sure if this was OP's issue, but I had an issue seeing response JSON because I had the dropdown above the request list in my results tree set to "Text". If I change it to "JSON" I can see the results.

Related

Character limit on an attribute in JSON response

I have an attribute which can store 1024 characters in the column of my table in db. Let's assume the name of attribute is statusMessage.
The value of statusMessage attribute in the column of table is:
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
But the json response which I get is instead something like below:
{
"statusCode": "success",
"statusMessage": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..."
}
So my observation is that the db is storing the complete 1024 characters in the column of its table but the JSON response is not able to show the complete data in its response for the given attribute.
What could be the possible reason for this? And how can it be rectified?
Note: Using SQL database and hybris platform for my web application and this scenario is only happening for v1 rest web API's. For v2 rest web API, it renders all 1024 characters.

JIRA API POST jql search

I need to get a bulk of issues that in the array of keys.
A GET URL-request like '...&issues in (key-1,key-2)...' is not an option for me because of length of the array may be more than 200 so it will be a 2000+ chars URL request and it is not good as I red here.
Here is Jira's API example but there is no comments about the jql property value format.
How should I fill the JSON-POST-model's jql property for get issues by keys?
You pass the jql as part of the request body. Here's a sample request body you can use for the /search endpoint using POST:
{
"jql": "status in (Done, \"in progress\") OR issue in (TEST-1, TEST-2) ORDER BY created"
}

Rest API -> passing json string as parameter value

Is it the recommended way to pass a JSON string as a parameter value in a REST API?
This is the data which I am trying to send :
http://127.0.0.1:8000/v1/product/?productName=&metrics={"memory":2,"disk_space":10}
Here, is it ok to pass the value of metrics as JSON value?
Initially, I tried passing the metrics JSON value in the body. As it is not supported/recommended standard I have removed it.
Is it the recommended way to pass a JSON string as a parameter value in a REST API?
REST is an architectural style and it doesn't enforce (or even define) any standards for passing JSON string as a parameter value.
If you want to send JSON in the query string, you must URL encode it first:
/v1/products?productName=&metrics=%7B%22memory%22%3A2%2C%22disk_space%22%3A10%7D
Alternativelly, you could redesign the parameters to be like:
/v1/products?productName=&metrics.memory=2&metrics.diskSpace=10
If the URL gets too long (or the query gets too complex to be expressed in the query string), you may want to consider POST instead of GET, and then send the JSON in the request payload:
POST /v1/products/search HTTP/1.1
Host: example.com
Content-Type: application/json
{
"productName": "foo",
"metrics": {
"memory": 2,
"diskSpace": 10
}
}
Sending JSON values in GET request is not recommended. You can do it but metrics json can be long and anybody can read the content.
You should use POST request to send parameters such as productName and metrics in the body.
You should refer to this answer for detailed explanation.
For use Content-Type Application Json Please use below line
request.AddParameter("application/json", "{\n\t\"lastName\":\"gaurav.sablok#agarwalpackers.com\"\n}", ParameterType.RequestBody);
This is used with "RestSharp" name spaces

Ajax/Json request to Controller in Play1.2.7 not working specifying content type

I have this js code
function sendJSon(){
var user = {"user_name" : $("#my_input_field").val()};
$.ajax({
url: 'http://localhost:9000/myAction',
type: 'POST',
data: JSON.stringify(user),
success: function(result) {
$("#my_res_div").html(result);
},
error: function(){
alert("error");
}
});
}
which works perfectly when passed to the application and then goes on success as it was meant to.
But I reached this goal after many tries because at the beginning (browsing this site) I found answers which suggested to specify also content type (application/json or text/javascript) and data type (json) for JSon requests.
I wonder why I get XMLHttpRequest cannot load http://localhost:9000/myAction. Invalid HTTP status code 404 if I specify either content or data types.
This the route line in route file
POST /myAction Application.jsonRequest
The error you're quoting basically means the response to the POST request is a 404 status, which is not an expected value for a POST request (you're sending content, it is illogical for the server to say it can't find that content).
Specifying the dataType field for $.ajax is generally not needed, because it will try to figure it out itself. However, this field should not cause a problem, because it is about parsing the response data, which only happens after the response is received, and the error code indicates a bad response in the first place (meaning it never goes to parsing).
The contentType field for $.ajax is more important for a request. It is a two part string, specifying the type of content being sent and the character set being used to encode the content. So the problem with setting it to either of the values you name is that there is that the character encoding is missing. Another problem is that you're specifying a datatype while at the same time not providing your data in that format. You're explicitly stringifying your content, which means it won't be JSON data.

Wrapping JSON payload with key in EmberJS

Ok basically I am sending a POST request with some JSON payload in it to Codeigniter. I use RESTAdapater. JSON get sent there with no key, so I have no access to it.
Here is model:
App.Bookmark = DS.Model.extend({
title: DS.attr("string"),
url : DS.attr("string")
});
Here is controller:
App.BookmarksNewController = Ember.ObjectController.extend({
save: function(){
this.get("model.transaction").commit();
this.get("target").transitionTo("bookmarks");
}
});
In REST implementation in CI that I use standard way to access the post request is $this->input("key"). But when the above request is generated, only raw JSON data is sent. Therefore I don't seem to have a way to reference it in any way.
Take this example:
function post(){
$this->response(var_dump(file_get_contents("php://input")),200);
}
Gives me this output:
string(48) "{"bookmark":{"title":"sdffdfsd","url":"sdfsdf"}}"
what I would like to see is:
string(48) payload="{"bookmark":{"title":"sdffdfsd","url":"sdfsdf"}}"
Then is server I would be able to access this JSON with something like $this->post("payload").
So 1 of 2. Anyway to wrap the JSON payload with key? Or anyway to access raw JSON data in CI with no key available??
Ok figured it out myself (or rather read properly the examples).
When using Adam Whitney's fork of Phil Sturgeons REST controller for CodeIgniter the JSON payload will be available in $this->_post_args. And in the underlying implementation he uses my already mentioned file_get_contents("php://input").
EDIT: Same convention applies for other type of requests as well, for example DELETE request data will be available in $this->_delete_args. Or $this->_args is the "magic" place where all types of args can be found.