Frustrating 500's on a post

507 views
Skip to first unread message

Jason Rainbird

unread,
Jul 10, 2014, 6:06:29 AM7/10/14
to gat...@googlegroups.com
Hello,

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
    .noProxyFor("localhost")
    .acceptHeader("*/*")
    .acceptCharsetHeader("ISO-8859-1,utf-8;q=0.7,*;q=0.3")
    .acceptLanguageHeader("en-GB,en-US;q=0.8,en;q=0.6")
    .acceptEncodingHeader("gzip,deflate,sdch")
    .userAgentHeader("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36")
    .disableCaching
    .disableWarmUp
  val scn = scenario("Web Service API Test").during(1000 milliseconds) {
 exec(http("POST test")
   .post("URL REMOVED FOR PRIVACY")
   .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": ""}"""))
   .check(status.is(200)))
   }
  
  setUp(scn.inject(atOnceUsers(1)).protocols(httpConf))


Easy isn't it?

Logback gives me the following output...


Request:
POST test: KO status.is(200), but actually found 500
=========================
Session:
Session(Web Service API Test,1781151826160433670-0,Map(728cd795-f875-47ab-b8f7-839fe3d42536 -> 3, timestamp.728cd795-f875-47ab-b8f7-839fe3d42536 -> 1404985727356, gatling.http.cookies -> CookieJar(Map())),1404985727353,46,KO,List(ExitASAPLoopBlock(728cd795-f875-47ab-b8f7-839fe3d42536,<function1>,Actor[akka://GatlingSystem/user/$d/$a#59091219])))
=========================
HTTP request:
POST URL REMOVED FOR PRIVACY
headers=
Accept: [*/*]
Accept-Charset: [ISO-8859-1,utf-8;q=0.7,*;q=0.3]
Accept-Language: [en-GB,en-US;q=0.8,en;q=0.6]
Accept-Encoding: [gzip,deflate,sdch]
User-Agent: [Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36]
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": ""}
=========================
HTTP response:
status=
500 Internal Server Error
headers=
Date: [Thu, 10 Jul 2014 09:48:47 GMT]
Server: [Apache/2.2.15 (CentOS)]
X-Powered-By: [PHP/5.5.13]
Vary: [Accept-Encoding]
Connection: [close]
Content-Type: [application/json]


Any ideas?


Jason

Stéphane Landelle

unread,
Jul 10, 2014, 6:13:37 AM7/10/14
to gat...@googlegroups.com
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.

Jason Rainbird

unread,
Jul 10, 2014, 6:16:59 AM7/10/14
to gat...@googlegroups.com
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
  1. 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?

    Stéphane Landelle

    unread,
    Jul 10, 2014, 6:22:48 AM7/10/14
    to gat...@googlegroups.com
    REST Console sends Content-Type: application/xml for a JSON payload, really???

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


    --
    You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

    Jason Rainbird

    unread,
    Jul 10, 2014, 6:43:09 AM7/10/14
    to gat...@googlegroups.com
    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.

    Stéphane Landelle

    unread,
    Jul 10, 2014, 6:53:31 AM7/10/14
    to gat...@googlegroups.com
    http("POST test")
       .post("URL REMOVED FOR PRIVACY")
       .header("Content-Type", "application/json")
       . body....

    Jason Rainbird

    unread,
    Jul 10, 2014, 7:06:14 AM7/10/14
    to gat...@googlegroups.com

    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")
       .post(
    VALID DEFINED URL HERE)
       .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
       .check(status.is(200)))
       }

    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.

    Stéphane Landelle

    unread,
    Jul 10, 2014, 7:25:38 AM7/10/14
    to gat...@googlegroups.com
    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. 


    --

    Jason Rainbird

    unread,
    Jul 10, 2014, 7:39:25 AM7/10/14
    to gat...@googlegroups.com
    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.

    Stéphane Landelle

    unread,
    Jul 10, 2014, 8:01:24 AM7/10/14
    to gat...@googlegroups.com
    You're welcome.
    Have fun!


    2014-07-10 13:39 GMT+02:00 Jason Rainbird <mrjason...@gmail.com>:
    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.

    --
    Reply all
    Reply to author
    Forward
    0 new messages