How to generalize StringBody and ByteArrayBody to a body?

Hi,

I’m trying to write a test which posts either string data or binary data to a url. If it’s string data I can use the feeder mechanism to replace some variables in the string.

This is what I’m trying to do

var body = StringBody("")
if (dataFormat == “a”) {
body = ByteArrayBody(someBytes)
} else {
body = StringBody(message)
}

val testHttp = http(“request_1”).post(messagesPath).header(contentType, headerJson).body(body)

But it fails because body has already been declared as one type and later I set it to another.

In Java I would just declare body as whatever the superclass of StringBody and ByteArrayBody is.

How do I do that in gatling?

Is there an API doc for StringBody and ByteArrayBody, and for the body() method? I haven’t been able to find it if there is.

val body =
if (dataFormat == “a”) {
ByteArrayBody(someBytes)
} else {
StringBody(message)
}

Thanks!

After much trial and error, I came up with this:
var body:Body = StringBody("") and it seems to work. Scala newbie.

I guessed the superclass of both was called Body, and I generated an error in order to determine the package Body and StringBody were in because I couldn’t find it online.

Could someone point me to the documentation for these classes? Intellij doesn’t help me with this either.

No offense but this is very ugly and you should go with my version.