0
votes

I'm new to Gatling, working on writing my first scenario. I can't get RawFileBody to work. I direct all traffic through fiddler so I can see what's going on and the file content isn't being outputted to the request body. Using StringBody works fine but I prefer not using it for very large JSON payloads.

I've checked that the file is in the "...\gatling\gatling-charts-highcharts-bundle-2.1.4\user-files\bodies" directory, I've tried using an absolute path, I've tried adding asJSON. I've set log levels to trace and haven't seen any errors or warnings, but the request body is still empty. Here's the relevant part of the script (ignore any small mistakes as I've had to remove lots of proprietary code):

import io.gatling.core.scenario.Simulation
import io.gatling.core.Predef._
import io.gatling.http.Predef._

import java.util.UUID

class Scenario1 extends Simulation {

  val uri1 = "http://somehost"

  val httpProtocol = http
    .baseURL("http://somehost")
    .proxy(Proxy("localhost", 8888).httpsPort(8888))
    .inferHtmlResources()
    .acceptHeader("application/json")
    .contentTypeHeader("application/json")

  val header = Map("Some" -> "proprietary-header")

  object Foo {
    val bar = exec(http("bar")
      .post(uri1 + "/app/myservice")
      .headers(header)
      .body(RawFileBody("my_request.txt")))
  }

  val scn = scenario("scenario1").exec(Foo.bar)

  setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}

Any ideas?

1
I'm using Gatling 2.0.3 and was unable to get RawFileBody to ever find my file if I used a non-absolute path - however it would at least tell me this fact at the end of the simulation report, and log it at ERROR during the run. I was able to successfully send the contents of the file as the body if I used an absolute path e.g. "/home/millhouse/blah/blah/user-files/foo/bar/my_request.txt"millhouse
It seems to be an issue with directing gatling through fiddler. If the proxy configuration is removed it works appropriately. There's another thread running about it on the gatling user group: groups.google.com/forum/#!topic/gatling/TMdxbZIE6yMjoniba
Try using ELFileBody instead of RawFileBody. Solved the same problem in my case.Landon Kuhn

1 Answers

0
votes

You have baseURL set in http part and then you add it again in .post part. Post uses baseURL by default and adds whatever you specify to it. So you seem to be calling http://somehosthttp://somehost/app/myservice. Other than that you should be fine, but do add .asJSON and do use absolute path just to be sure. Best of luck.