Type mismatch error when trying to pass a string as parameter to .body for a POST request

1,871 views
Skip to first unread message

uguduru

unread,
Oct 16, 2013, 2:03:29 PM10/16/13
to gat...@googlegroups.com
Hi Everyone,
    I am new to Gatling and I am trying to fire a basic POST request with a single parameter. It is throwing me an type mismatch error when I passed a string as parameter to the '.body' method. I also tried using '.param' but got a  '406 Not acceptable'  as response from the server. Any help is greatly appreciated. I was able to successfully test the same scenario with JMeter.

POST body or param : {"ServiceProviderIdentifier":2108231}

My Simulation:

import io.gatling.core.Predef._
import io.gatling.core.session.Expression
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
import io.gatling.http.Headers.Names._
import io.gatling.http.Headers.Values._
import io.gatling.http.request._
import scala.concurrent.duration._
import bootstrap._
import assertions._

class ServiceGatewayRequest extends Simulation {

val httpProtocol = http
.connection("keep-alive")

val header = Map(
"""Access-Control-Allow-Origin""" -> """*""",
"""Access-Control-Allow-Headers""" -> """Origin, X-Requested-With, Content-Type, Accept""",
"""Content-Type""" -> """application/json""")
.headers(header))

val scn = scenario("Servive Gateway Request")
.exec(http("Fetch SP Details and Categories")
.headers(header)
.body("""{ "ServiceProviderIdentifier":"2108231" }""").asJSON)
// .param("ServiceProviderIdentifier","2108231"))

setUp(scn.inject(atOnce(1 user))).protocols(httpProtocol)

The error I am getting when i ran the above simulation is: 

13:38:52.555 [ERROR] i.g.a.ZincCompiler$ - C:\Users\uguduru\Desktop\Work\rapid-fire-master\user-files\simulations\ServiceGatewayRequest.scala:35: type mismatch;
 found   : String("{ \"ServiceProviderIdentifier\":\"2108231\" }")
 required: io.gatling.http.request.Body
13:38:52.559 [ERROR] i.g.a.ZincCompiler$ -                      .body("""{ "ServiceProviderIdentifier":"2108231" }""").asJSON)
13:38:52.560 [ERROR] i.g.a.ZincCompiler$ -                            ^
13:38:52.604 [ERROR] i.g.a.ZincCompiler$ - one error found

Nicolas Rémond

unread,
Oct 16, 2013, 2:13:30 PM10/16/13
to gat...@googlegroups.com
You can try the following : 

.body(BodyString("""{ "ServiceProviderIdentifier":"2108231" }""")).asJSON


--
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/groups/opt_out.

Stéphane Landelle

unread,
Oct 16, 2013, 2:19:34 PM10/16/13
to gat...@googlegroups.com
A bit more detailed: I'd say you're using Gatling 2 (which is a work in progress) with the Gatling 1 syntax. As mentioned on every page, the wiki is about Gatling 1, except for the page named Gatling 2: https://github.com/excilys/gatling/wiki/Gatling%202#wiki-bodies


2013/10/16 Nicolas Rémond <nicolas...@gmail.com>
Message has been deleted

uguduru

unread,
Oct 16, 2013, 2:38:48 PM10/16/13
to gat...@googlegroups.com
Hi Stephane,
    Thanks for the help. It worked.
Reply all
Reply to author
Forward
0 new messages