Garling 2.1.7 post request does not send json

94 views
Skip to first unread message

markus....@gmail.com

unread,
Aug 27, 2015, 10:54:34 AM8/27/15
to Gatling User Group
Good day community,

My Gatling simulation is defined below:

class GatlingSpec extends Simulation {

      val user = "markus"
      val password = "Cn3%Vkao0xiY3v"

      val postWithJSON = "postWithJSON"

      def getJSONStr(uuid: String, obj: String, objType: String) =
        StringBody(s"""{
          "uuid":"${uuid}","objectid":"${obj}","objecttype":"${objType}",
          "user":"${user}","password":"${password}"
          }"""
        )

      val postWithJSONStr = getJSONStr(java.util.UUID.randomUUID.toString, "MyObject", "MyObjectID")

      val httpProtocol = http
          .baseURL("https://id-38ih9fiw.google.com:444/MyServer/")
          .disableCaching
          .disableClientSharing

      val scn = scenario("oxGatlingTest").repeat(2) {
        exec(
            http(session => "Post with JSON")
                .post(postWithJSON)
                .body(postWithJSONStr)
                .asJSON
        )
      }

      setUp(scn.inject(atOnceUsers(10))).protocols(httpProtocol)

}

My Scala Play app receives request as below:

def postWithJSON = Action { implicit request =>
    val jsonRequest = request.body.asJson.get
    /* other code */
}

If I run the above scenario, it fails with "failed: but actually found 400" error so no communication happens with the server on which my app is hosted.

If I remove .asJSON from the test, communication happens (and I can successfully send GET requests without any JSON to my app using Gatling) in the following way:
request is of type play.api.mvc.Request, it is not null
request.body is of type play.api.mvc.AnyContent, it is not null
request.body.asJson is of type Option[AAA] but applying get on it afterwards throws a runtime exception: "java.util.NoSuchElementException: None.get"


Could you please tell me what is the right way to create and send JSON to my app? Love your tool, it is super cool.

Best wishes,
Markus

Stéphane LANDELLE

unread,
Aug 27, 2015, 11:53:13 AM8/27/15
to gat...@googlegroups.com
Hi,

400 means there WAS a communication with your server and that it replies that the request was malformed.
It typically means malformed payload or missing headers.

Lower logging level, or use something like Charles, and check the request that's being sent.

Cheers,

Stéphane Landelle
Lead developer


--
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.

Reply all
Reply to author
Forward
0 new messages