StringResponseBody parameter type ( Seq[io.netty.buffer.ByteBuf] ? ) compilation error

I’m trying to do the exact same response transformation as is done is this message, but I run into a compilation error.

My code:

`

.exec(http(“extract userid”)
.get(“/ebridge/api/relation/heart-beat?sequence=1”)
.headers(headers_0)
.check(status.is(200))
.transformResponse {
case response if response.isReceived =>
new ResponseWrapper(response) {
override val body = StringResponseBody(response.body.string.replace(“)]}',”, “”), response.charset)
}
}
.check(jsonPath(“$.userId”).saveAs(“userId”)).silent)

`

My compilation error:

`

nb4753@VWS30639 C:\data\bin\gatling-charts-highcharts-bundle-2.2.2\bin

gatling.bat
GATLING_HOME is set to “C:\data\bin\gatling-charts-highcharts-bundle-2.2.2”
JAVA = ““C:\Program Files\Java\jdk1.8.0_25\bin\java.exe””
[ERROR] i.g.c.ZincCompiler$ - C:\data\source\lnp-statistiek\bb\src\main\java\nl\dnb\eline\bb\BBBaseActions.scala:157: type mismatch;
found : String
required: Seq[io.netty.buffer.ByteBuf]
[ERROR] i.g.c.ZincCompiler$ - override val body = StringResponseBody(response.body.string.replace(“)]}',”, “”), response.charset)
[ERROR] i.g.c.ZincCompiler$ - ^
[ERROR] i.g.c.ZincCompiler$ - one error found
[ERROR] i.g.c.ZincCompiler$ - Compilation crashed

`

Anybody any clue about this? My tests are blocked since this CSRF ‘header’ is added to our responses… :frowning:

As can be seen below, I’m using Gatling 2.2.2 with jdk1.8.0_25.

When I downgrade to Gatling 2.1.7 this does compile…

However, at runtime it doesn’t really work. The transformation appears to transform the string, but the body isn’t changed relative to the check.

Code:

`

.exec(http(“extract userid”)
.get("/ebridge/api/relation/heart-beat?sequence=1")
.headers(headers_0)
.transformResponse {
case response : io.gatling.http.response.Response if response.isReceived =>
new ResponseWrapper(response) {
val stripped = response.body.string.replace(")]}’,", “”)
println("### " + stripped)
override val body = StringResponseBody(stripped, response.charset)
}
}
.check(status.is(200))
.check(jsonPath("$.userId").saveAs(“userId”)).silent)

`

Runtime: (note the println() shows the correct value, but the jsonPath check encounters the “)]}” still. I’d assumed the ResponseWrapper modifies the body before the check inspects it, but it doesn’t?

`

This piece of code was for Gatling 2.2.
This is internal classes hacking, so it can of course break when upgrading, and you’re expected to go check Gatling’s code to get it right.
Have you tried doing that? https://github.com/gatling/gatling/blob/750f7a7b4b54c38484cc5839ba307086656cfb6d/gatling-http/src/main/scala/io/gatling/http/response/ResponseBody.scala#L60-L86

Stéphane,

Thansk for you reply.

I tried to find an example of how this new API should be applied, but -as a non seasoned scala developer- I didn’t succeed, I guess. To be honest, I also fail to grasp the new usage from the link you send.

Also, there appears to be a test in the Gatling codebase that does exactly what I’m trying.
https://github.com/gatling/gatling/blob/8b5a4d21de44d2511681500534f6b3b6d986ced4/gatling-http/src/test/scala/io/gatling/http/HttpCompileTest.scala#L256-L258

(If I’m looking at a 2.1.7 version of the test, could you point me to the 2.2.2 version of the test?)

Thanks for you help,
Nol

Your link is master/2.2.3-SNAPSHOT

So, do I understand correctly that this will be supported again in 2.2.3? That would be great.
Or should I continue my quest getting this to work in 2.2.2?
And if it will be 2.2.3, have you got a timeline?

So, do I understand correctly that this will be supported again in 2.2.3?
That would be great.
Or should I continue my quest getting this to work in 2.2.2?

It works the same way in 2.2.2, just play "spot the difference" with your
version :slight_smile:

And if it will be 2.2.3, have you got a timeline?

Probably next week.

*Stéphane Landelle*
*GatlingCorp CEO*
slandelle@gatling.io

I’m having the same problem currently. Was this issue ever fixed/supported?

Shane,

Yes, only recently I really had to upgrade, and after looking at this over and over I spotted the difference:

override val body = StringResponseBody(stripped, response.charset)

should be

override val body = new StringResponseBody(stripped, response.charset)

(spot the ‘new’…)

That is how it is in the tests as wel, but took me ages to find…:

https://github.com/gatling/gatling/blob/8b5a4d21de44d2511681500534f6b3b6d986ced4/gatling-http/src/test/scala/io/gatling/http/HttpCompileTest.scala#L256-L258

Nol

Thanks for that. Do you know if it’s possible to do something like this?

.transformResponse {
case response: Response if response.isReceived =>
new ResponseWrapper(response) {
val b1 = new StringResponseBody(response.body.string.replaceAll("\"","""), response.charset)
val b2 = new StringResponseBody(b1.string.replaceAll(""{","{"), response.charset)
override val body = new StringResponseBody(b2.string.replaceAll("}"","}"), response.charset)
}
}

It’s compiling and all but when I run it gives me an Error that looks like this.
1 (100.0%)yntaxException: Illegal repetition near index 0

"{
^