Frustrating 500's on a post


I’m new to this, so please bear with me.

I’m getting a pesky 500 call on a post from my gatling script that works fine when I use a normal rest client on my machine. Can any of you spot the issue? I appreciate that this is a vague question, but any help you can provide would be appreciated.

Here’s an edited version of my script…

val httpConf = http
.userAgentHeader(“Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36”)
val scn = scenario(“Web Service API Test”).during(1000 milliseconds) {
exec(http(“POST test”)
.body(StringBody("""{“params” :[ { “id”: “31675801”, “paramType”: “INPUT”, “name”: “Input - Input DataId”, “type”: “int”, “value”: “240007”, “unit”: “”, “values”: “” }, { “id”: “31675803”, “paramType”: “PARAM”, “name”: “Input - Invert”, “type”: “bool”, “value”: 0, “values”: “”}"""))


Easy isn’t it?

Logback gives me the following output…

POST test: KO, but actually found 500

You probably lack some request headers, like Content-Type, so that the server knows which kind of payload to expect?

Server logs would probably tell you.

I had wondered that too. On REST Console (a Chrome extension), the request headers are…

  1. Accept: /
  2. Connection: keep-alive
  3. Content-Type: application/xml
  4. Origin: chrome-extension: //rest-console-id
  5. User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36

…and that’s all. Call you see anything in that list that isn’t supported in httpConf?

REST Console sends Content-Type: application/xml for a JSON payload, really???

But then, yes, this Content-Type header is missing.

I guess REST Console defaults to application/xml.

…and now the embarrassing question. Can you recommend the best way of setting the contentType in my example?

The example .headers() function on exec I found gives me compilation errors

“value headers is not a member of io.gatling.http.request.builder.Http”

Sorry for the probably obvious question.

http(“POST test”)

.header(“Content-Type”, “application/json”)
. body…

Excellent, thank you. The header is now set, but I still get 500’s.

I had another idea. The Chrome client gives me 500’s if I pass an empty body. Does the body set up code look ok to you?

exec(http(“POST test”)
.header(“Content-Type”, “application/xml”)
.body(StringBody("""{“params” :[ { “id”: “31675801”, “paramType”: “INPUT”, “name”: “Input - Input DataId”, “type”: “int”, “value”: “240007”, “unit”: “”, “values”: “” }, { “id”: “31675803”, “paramType”: “PARAM”, “name”: “Input - Invert”, “type”: “bool”, “value”: 0, “values”: “”}""")).asJSON

Logback shows it as…

stringData={“params” :[ { “id”: “31675801”, “paramType”: “INPUT”, “name”: “Input - Input DataId”, “type”: “int”, “value”: “240007”, “unit”: “”, “values”: “” }, { “id”: “31675803”, “paramType”: “PARAM”, “name”: “Input - Invert”, “type”: “bool”, “value”: 0, “values”: “”}

…rather than something that explicitly says body.

I missed the fact you had “.asJSON”, that does exactly the same thing as .header(“Content-Type”, “application/xml”) (so you can remove it), sorry.

Now, I realize what your problem is: your JSON payload is broken!
You don’t close the “params” array, there’s a ] missing at the very end.

Ha! Sometimes it is the least of quirks that causes the greatest strife! It is now working like a charm.

Thank you for your help and your patience.

You’re welcome.
Have fun!