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)
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?
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.
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
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