Jmeter http post sampler syntax - testing

I'm triyng to test a rest api using jmeter script. When I launch the test, I get the following exception:
{"timestamp" : 1463775753585,
"status" : 400,
"error" : "Bad Request",
"exception" : "org.springframework.http.converter.HttpMessageNotReadableException",
"message" : "Could not read JSON: (was java.lang.NullPointerException) (through reference chain: com.tutos.example.models.Product[\"category\"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: com.tutos.example.models.Product[\"category\"])",
"path" : "/product"
}
Here is my data of post:
{"code":${productCode}, "intitule":"${productName}", "cost":"${cost}", "category":{"id":"${categoryId}"}}
But when I remove the property category, everything is OK.
What am I missing please ?

Related

Mule design centre defining 400 response but trying it does not return same response

I am defining my api contract in RAML in Mule Anypoint platform Design centre .
Here is the simple contract :
#%RAML 1.0
title: test_experiment
version: v1
mediaType: application/json
/test:
put:
headers:
trackingId:
type: string
description: "Track each request"
minLength: 3
responses:
200:
body:
application/json:
example:
{
"msg": "successfully done"
}
400:
body:
application/json:
example:
{
"msg": "something bad was submitted",
"id" : "001"
}
Next I am trying to 'test it' in Documentation tab and when I purposefully do not enter a trackingId I do get a 400 response code but the response payload is different.
I have defined the response payload as : ( expected payload )
{
"msg": "something bad was submitted",
"id" : "001"
}
However the payload response in 'try it' in design centre is :
{
"code": "REQUEST_VALIDATION_ERROR",
"message": "Error validating header: expected minLength: 3, actual: 0"
}
So why is the 400 response not being returned as I have it defined in my raml ?
Edit1 : This behaviour is all observed in Design Centre , I am not providing an implementation and then testing it , I am using design centre Documentation and 'Try it' feature as per image below :
Because it is a mock, not a real implementation. When you are testing in Design Center you are using the Mocking Service that simulates reponses. The error you are getting is because the request doesn't match with the specification. The Mocking Service usually uses only the first status code it finds in the API RAML. If you want it to return your error use a behavioral header like MS2-Status-Code to set the error code. For example set the header MS2-Status-Code to 200,400. Although I'm not sure it will work to override the validation error from the Mocking Service. You will need to try.

Customize the message returned when accessing the server url of a connexion (python) service

I am writing a python service with connexion. I have access to the swagger gui of the service via localhost:<port>/ui. However, when I enter localhost:<port> in the browser without the /ui (automatically added by connexion), I get the following message:
{
"detail": "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.",
"status": 404,
"title": "Not Found",
"type": "about:blank"
}
Is it possible to customize this message ? In my case, I want localhost:<port> to return the following message instead:
{"message": "check /ui to have access to the Swagger UI"}
I think I found a solution. Just add the following to the openspec api:
/:
get:
operationId: path.to.function
summary: "my personlized message"
responses:
......

"error trying invoke chaincode. Error: chaincode error (status: 500, message: TypeError: cannot read property 'getFullyQualifiedIdentifier' of null)",

I am getting below error while following tutorial here.
https://hyperledger.github.io/composer/unstable/managing/current-participant.html
I have created one Participant and issued identity to it. But in my transaction processor function,when I verify the participant ID of the current participant by using the getCurrentParticipant function through rest apis I get below error.
{
"error": {
"statusCode": 500,
"name": "Error",
"message": "error trying invoke chaincode. Error: chaincode error (status: 500, message: TypeError: cannot read property 'getFullyQualifiedIdentifier' of null)",
"stack": "Error: error trying invoke chaincode. Error: chaincode error (status: 500, message: TypeError: cannot read property 'getFullyQualifiedIdentifier' of null)\n at _initializeChannel.then.then.then.then.catch (/home/praval/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:847:34)"
}
}
Can anybody explain the reason?
It looks like the mapping from certificate to participant is not in place. The easiest way to test this is to use the composer identity issue command and then use composer network ping -- which will return the current participant. Once that is working then getCurrentParticipant() should work.
https://hyperledger.github.io/composer/managing/identity-issue.html
When you composer network ping your participant will try to access the network metadata. The ACL rule below will permit this access. Please ensure that you are using the latest version of the basic-sample-network which includes this rule.
rule SystemACL {
description: "System ACL to permit all access"
participant: "org.hyperledger.composer.system.Participant"
operation: ALL
resource: "org.hyperledger.composer.system.**"
action: ALLOW
}

google-oauth calendar returns 401 error

I tried the calendar-appengine-sample on google calendar api java sample and when I used the client_secrets.json for running in localhost it always give me back my calendar list, but when I use the client_secrets.json to be run on google app engine, it give me following error message :
ERROR: 401
{
"code" : 401,
"errors" : [ {
"domain" : "global",
"location" : "Authorization",
"locationType" : "header",
"message" : "Invalid Credentials",
"reason" : "authError"
} ],
"message" : "Invalid Credentials"
}
Before it work with the same client_secrets.json, but suddenly it doesn't work. Would anyone be so kindly tell me how to fix this problem?
thanks.
I had asked this some time back (assuming your using version 3 of the API), and here is a potential answer.
If you get a 403 error, which I did after fixing this then try this.

HTTP Adapter Error "Runtime: Failed to parse JSON string"

I am using IBM Worklight Studio, and trying to create HTTP Adapter which retrieve JSON object from external http server.
When I just access target http server with HTTP Get access(with browser, for example), I know their response is like following array style JSON format:
[
{ "xxx":"aaa", "yyy":"bbb", ... },
{ "xxx":"ccc", "yyy":"ddd", ... },
:
{ "xxx":"eee", "yyy":"fff", ... }
]
And I had created HTTP Adapter which would retrieve above information
var input = {
method : 'get',
returnedContentType : 'json',
path : path
};
return WL.Server.invokeHttp(input);
Now I tried to invoke this adapter with "Run As -> Invoke Worklight Procedure", then I got this error message:
{
"errors": [
"Runtime: Failed to parse JSON string\n\n[\n {\n
(raw JSON data) } ],
"info": [],
"isSuccessful": false,
"warnings": []
}
And in my log console, worklight says following error messages:
FWLSE0101E: Caused by: java.io.IOException: Expecting '{' on line 2, column 2 instead, obtained token: 'Token: ['
From above information, it seems that worklight would expect that returned JSON object need to start with "{", not "[".
Is this my guess right? Are there any workaround for this?
Thanks for advance.
Worklight knows how to handle JSON objects that start with [ (JSON arrays). In such case Worklight will return the response as:
{ "array" : [*the json array*]}
Looking at the code of the HTTP Adapter, I see that there is a bug with parsing JSON arrays that do not start with [.
I do not see a workaround for this problem, except changing the response returned from the http server.
I opened an internal bug about this, thank you for helping us find this bug.
You can change returnedContentType to "plain", this will make WL server return content as a big string and not attempt to parse it.
Then in your adapter you can use var obj = JSON.parse(response.text)