jeggy
06/07/2021, 5:29 PMclass XmlConverter : ContentConverter {
override suspend fun convertForReceive(context: PipelineContext<ApplicationReceiveRequest, ApplicationCall>): Any? {
val request = context.subject
val channel = request.value as? ByteReadChannel ?: return null
val inputStream = channel.toInputStream()
val reader = inputStream.reader(context.call.request.contentCharset() ?: Charsets.UTF_8)
val type = request.type
return convertForReceive(type.javaObjectType, reader::readText)
}
}
Does anyone know why the .toInputStream()
throws this exception?
java.lang.IllegalStateException: Using blocking primitives on this dispatcher is not allowed. Consider using async channel instead or use blocking primitives in withContext(<http://Dispatchers.IO|Dispatchers.IO>) instead.
io.ktor.utils.io.jvm.javaio.BlockingKt.ensureParkingAllowed(Blocking.kt:302)
io.ktor.utils.io.jvm.javaio.BlockingKt.access$ensureParkingAllowed(Blocking.kt:1)
io.ktor.utils.io.jvm.javaio.InputAdapter.<init>(Blocking.kt:30)
io.ktor.utils.io.jvm.javaio.BlockingKt.toInputStream(Blocking.kt:20)
io.ktor.utils.io.jvm.javaio.BlockingKt.toInputStream$default(Blocking.kt:20)
com.apurebase.concur.server.XmlConverter.convertForReceive(XmlConverter.kt:28)
This happened after I upgraded from kotlin 1.3 and ktor 1.1.3 to the latest versions.Rustam Siniukov
06/07/2021, 5:47 PMInputStream
in the first place? You can do val text = channel.readRemaining().readText(charset)
. This is a no-blocking calljeggy
06/07/2021, 8:49 PM