Decoding Base64 Response throwing MalformedInputException Exception

I am trying to invoke RestApi from Gatling which return PDF as response. From POSTMAN its working fine and getting response as 200 with PDF but when running through Gatling getting below error as :


java.nio.charset.MalformedInputException: Input length = 1
at java.nio.charset.CoderResult.throwException(
at org.asynchttpclient.netty.util.Utf8ByteBufCharsetDecoder.decodeSingleNioBuffer(
at org.asynchttpclient.netty.util.Utf8ByteBufCharsetDecoder.decode(
at org.asynchttpclient.netty.util.Utf8ByteBufCharsetDecoder.decodeUtf8(
at org.asynchttpclient.netty.util.ByteBufUtils.byteBuf2String(
at io.gatling.commons.util.Bytes$.byteArrayToString(Bytes.scala:48)
at io.gatling.http.response.ByteArrayResponseBody.string$lzycompute(ResponseBody.scala:97)
at io.gatling.http.response.ByteArrayResponseBody.string(ResponseBody.scala:97)
at scenarios.ITGScenario$$anonfun$1$$anon$1.(ITGScenario.scala:40)
at scenarios.ITGScenario$$anonfun$1.applyOrElse(ITGScenario.scala:39)
at scenarios.ITGScenario$$anonfun$1.applyOrElse(ITGScenario.scala:37)


Code :

override val scenarioBuilder = scenario(“Invoices”)
.header(“VendorID”, “vendor1234”)
.header(“Content-Type”, “application/json”)
.transformResponse {
case response if response.isReceived =>
new ResponseWrapper(response)

{ override val body = new ByteArrayResponseBody(Base64.getDecoder.decode(response.body.string), StandardCharsets.UTF_8) }



Implementation using Base64 Encoding.
Tried solution mentioned in other threads in group and online available but no luck :frowning:


First, it looks like you’re using an old Gatling version that’s no longer supported. Please upgrade to Gatling 3.0.3.
If issue still happens after upgrading, please report again and provide a reproducer we can run on our side.

Thank you Stéphane. Updating Gatling worked.

For someone looking for how this worked for us other than updating Gatling, we actually had to encode the byte input stream that was being sent by our API: