Custom bodyProcessor

I’m trying to write my own bodyProcessor, but I’m having some trouble getting the code to compile. I’m building my HttpRequest like this:

val request: HttpRequestBuilder = http(“scholingsactiviteitRequest”)
.post(endpoint)
.body(ElFileBody(GET_SCHOLINGSACTIVITEIT_BODY))
.processRequestBody(processBody)

Then, processBody is set up like this:

def processBody: Body => StringBody =
(body: Body) => {
val v = body match {
case b: ElBody => b.asStream.map(signIt _)
}
}

def signIt(in: InputStreamBody): String = {
“something in string here”
}

However, when compiling I get the following error:
value map is not a member of io.gatling.core.session.Expression[java.io.InputStream]
case b: ElBody => b.asStream.map(signIt _)

What am I missing here?

ElBody#asStream returns an Expression[InputStream] while your signIt takes an InputStreamBody.

I was trying to mimic the gzip method. That one takes an Inputstream, but it seems as though an expression is passed.

Is there any way to take the Inputstream out of the Expression[Inputstream] ?

If I redefine my methods as this:

def processBody: Body => StringBody =
(body: Body) => {
val v = body match {
case b: ElBody => b.asStream.map(signIt _)
}
}

def signIt(in: InputStream): String = {
“”
}

I get the error:
value map is not a member of io.gatling.core.session.Expression[java.io.InputStream]
case b: ElBody => b.asStream.map(signIt _)

What am I missing? This code seems similar to the code in Bodyprocessor.gzip and GzipHelper.gzip(in: InputStream)

For anyone who will stumble upon the same issue. Somehow this is resolved by putting the inputparameter in a separte file.

I adapted HttpRequestBuilder to:

request: HttpRequestBuilder = http(“scholingsactiviteitRequest”)
.post(endpoint)
.body(ElFileBody(GET_SCHOLINGSACTIVITEIT_BODY))
.headers(headers)
.processRequestBody(SignProcessors.processBody)

where SignProcessors is an object in a separate file. I don’t know why this works, but it does.

In your previous email, you probably had messed up with the imports, breaking some implicit conversion, and you most likely incidentally fixed this in your latest version.