jean
12/01/2021, 1:11 PM@Serializable
data class MeasurementsEndpoint(
@SerialName("measurements")
val measurements: List<Measurement>,
@SerialName("measurementGroups")
val measurementGroups: Map<String, MeasurementGroup>,
)
the call is made like so http.get<MeasurementsEndpoint>(…)
nothing fancy here, but for some reason I get the error
kotlinx.serialization.MissingFieldException: Fields [measurements, measurementGroups] are required for type with serial name ‘no.beiningbogen.snute.sharedlibrary.library.model.endpoint.MeasurementsEndpoint’, but they were missingWhen I test my request locally I don’t get this error, it only happens when I run the request from android or iOS clients. Any idea what I’m doing wrong?
hhariri
12/01/2021, 3:09 PMAljoscha Grebe
12/01/2021, 10:57 PMsuspend fun main() {
val socket = aSocket(ActorSelectorManager(<http://Dispatchers.IO|Dispatchers.IO>)).udp().connect(InetSocketAddress("localhost", 1111))
val input = socket.openReadChannel()
input.readByte() // This line causes the exception
}
This code always throws the following exception:
Exception in thread "main" java.lang.IllegalStateException: Handler for READ is already registered
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at io.ktor.utils.io.ExceptionUtilsJvmKt$createConstructor$$inlined$safeCtor$1.invoke(ExceptionUtilsJvm.kt:103)
at io.ktor.utils.io.ExceptionUtilsJvmKt$createConstructor$$inlined$safeCtor$1.invoke(ExceptionUtilsJvm.kt:90)
at io.ktor.utils.io.ExceptionUtilsJvmKt.tryCopyException(ExceptionUtilsJvm.kt:66)
at io.ktor.utils.io.ByteBufferChannelKt.rethrowClosed(ByteBufferChannel.kt:2460)
at io.ktor.utils.io.ByteBufferChannelKt.access$rethrowClosed(ByteBufferChannel.kt:1)
at io.ktor.utils.io.ByteBufferChannel.setupStateForRead(ByteBufferChannel.kt:310)
at io.ktor.utils.io.ByteBufferChannel.readByte(ByteBufferChannel.kt:2540)
at com.example.TestKt.main(Test.kt:13) // Line with readByte()
at com.example.TestKt$main$2.invoke(Test.kt)
at com.example.TestKt$main$2.invoke(Test.kt)
at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt$createCoroutineUnintercepted$$inlined$createCoroutineFromSuspendFunction$IntrinsicsKt__IntrinsicsJvmKt$1.invokeSuspend(IntrinsicsJvm.kt:205)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlin.coroutines.ContinuationKt.startCoroutine(Continuation.kt:115)
at kotlin.coroutines.jvm.internal.RunSuspendKt.runSuspend(RunSuspend.kt:19)
at com.example.TestKt.main(Test.kt)
Caused by: java.lang.IllegalStateException: Handler for READ is already registered
at io.ktor.network.selector.InterestSuspensionsMap.addSuspension(InterestSuspensionsMap.kt:34)
at io.ktor.network.selector.SelectorManagerSupport.select(SelectorManagerSupport.kt:40)
at io.ktor.network.sockets.CIOReaderKt$attachForReadingImpl$1.invokeSuspend(CIOReader.kt:46)
at io.ktor.network.sockets.CIOReaderKt$attachForReadingImpl$1.invoke(CIOReader.kt)
at io.ktor.network.sockets.CIOReaderKt$attachForReadingImpl$1.invoke(CIOReader.kt)
at io.ktor.utils.io.CoroutinesKt$launchChannel$job$1.invokeSuspend(Coroutines.kt:132)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:367)
at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:30)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.startCoroutineImpl(Builders.common.kt:192)
at kotlinx.coroutines.BuildersKt.startCoroutineImpl(Unknown Source)
at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:134)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56)
at kotlinx.coroutines.BuildersKt.launch(Unknown Source)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47)
at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source)
at io.ktor.utils.io.CoroutinesKt.launchChannel(Coroutines.kt:123)
at io.ktor.utils.io.CoroutinesKt.writer(Coroutines.kt:77)
at io.ktor.network.sockets.CIOReaderKt.attachForReadingImpl(CIOReader.kt:27)
at io.ktor.network.sockets.NIOSocketImpl$attachForReading$1.invoke(NIOSocketImpl.kt:43)
at io.ktor.network.sockets.NIOSocketImpl$attachForReading$1.invoke(NIOSocketImpl.kt:41)
at io.ktor.network.sockets.NIOSocketImpl.attachFor(NIOSocketImpl.kt:80)
at io.ktor.network.sockets.NIOSocketImpl.attachForReading(NIOSocketImpl.kt:41)
at io.ktor.network.sockets.SocketsKt.openReadChannel(Sockets.kt:108)
at com.example.TestKt.main(Test.kt:11) // Line with .openReadChannel()
... 7 more
Edit: The only dependency I have n the example project is ktor-network:1.6.6phldavies
12/02/2021, 12:38 PMMockEngine.create
doesn’t return MockEngine
? At the moment we’re doing MockEngine.create { … } as MockEngine
- will it be expected in the future that MockEngine.create
might not return MockEngine
?martmists
12/02/2021, 4:50 PMmaxmello
12/03/2021, 11:06 AMio.ktor:ktor-client-okhttp
but need to support Android 4.2+, so I included OkHttp in version 3.12.0
as documented by OkHttp to support Android 4. Will bis cause problems when using Ktor together with OkHttp? Is compatibility between versions documented somewhere?martmists
12/03/2021, 1:22 PMa(...) {
attributes["download"] = "..."
}
is what you're looking for I thinkAlexandre Brown
12/04/2021, 3:35 PMSlackbot
12/05/2021, 4:01 PMEmirhan Emmez
12/06/2021, 10:19 AMwithTestApplication {
handleRequest(HttpMethod.Get, "/hello").apply {
assertEquals(HttpStatusCode.OK, response.status())
}
}
Alex Styl
12/06/2021, 12:18 PMStatusPages
plugin correctly. I am trying to redirect the user to “/” if they try to navigate to a page that does not exist (say they go to “/invalid”, then the browser should redirect to “/” instead).
I was under the impression that I would have to use StatusPages for this like so:
install(StatusPages) {
status(HttpStatusCode.NotFound) {
call.respondRedirect("/")
}
but when I navigate to “/invalid” the browser displays a blank page and the console shows a 404 for “/invalid”. I set a breakpoint to the call but it is never triggered.
Isn’t this what StatusPages are meant to handle? Would I need to use something else for this scenario? (I am thinking that maybe i could use just routing with wildcards)Trevor Stone
12/06/2021, 10:27 PMLandry Norris
12/06/2021, 10:58 PMRaymond Boswel
12/07/2021, 7:16 AM<http://log.info|log.info>("RouteTypeMap size: ")
<http://log.info|log.info>(RouteBuilder.routeTypeMap.size.toString())
embeddedServer(
Netty
, port = 11111
) {
<http://log.info|log.info>("RouteTypeMap size in configuration block: ")
<http://log.info|log.info>(RouteBuilder.routeTypeMap.size.toString())
Log:
RouteTypeMap size:
870
RouteTypeMap size in configuration block:
0
My knowledge of kotlin isn't deep enough to really have a a clue as to why this is happening 😅Emirhan Emmez
12/07/2021, 10:27 AMhandleRequest(<http://HttpMethod.Post|HttpMethod.Post>, "/login") {
addHeader(HttpHeaders.ContentType, ContentType.Application.Json.toString())
addHeader(HttpHeaders.Accept, ContentType.Application.Json.toString())
//setBody("{\"username\": \"emirhan\", \"password\": \"1234\"}")
setBody(listOf("username" to "emirhan", "password" to "1234").toString())
}
i'm receiving:
io.ktor.features.CannotTransformContentToTypeException: Cannot transform this request's content to com.emirhan.model.UserRequest
My data class UserRequest is like:
@Serializable
data class UserRequest(
val username: String,
var password: String
)
In route im receiving body like:
val userRequest = call.receive<UserRequest>()
Júlio Santos
12/07/2021, 7:10 PMPeter
12/08/2021, 4:16 PMAlex Styl
12/08/2021, 6:56 PMfun Application.configureRouting() {
routing {
static("/vid") {
files("videos")
}
get("/download/*") {
val file = File("./files/hello.txt")
call.respondFile(file)
}
get("/") {
call.respondHtml {
body {
a(href = "/download/hello.txt") {
attributes["download"] = ""
+"Download"
}
video {
loop = true
controls = true
source {
src = "/vid/vid.mp4"
type = "video/mp4"
}
}
}
}
}
}
}
Alex Styl
12/09/2021, 1:19 PM@font-face {
src: url("/fonts/Urbanist.ttf");
font-family: urbanist;
}
So far I got:
call.respondCss {
fontFace {
fontFamily = "urbanist"
}
}
but I cannot find a way to populate the src value.
(also, please let me know if this is not the right place to ask this)smallshen
12/10/2021, 4:19 AMVasily Scherbakov
12/10/2021, 8:13 PMAlex Styl
12/11/2021, 4:25 PMThomas
12/11/2021, 5:16 PMdefaultRequest
was moved from features package to plugins package. However, now attributes
in the defaultRequest
block is unresolved. I think this is a bug as it was there previously. How to fix this?Tomasz Krakowiak
12/12/2021, 1:09 PMDamiano Giusti
12/13/2021, 2:34 PMnative-mt
oneFunkyMuse
12/14/2021, 7:39 AMAlex Styl
12/14/2021, 10:59 AMNabil
12/14/2021, 1:45 PMx86_64
but not macos arm64
https://mvnrepository.com/artifact/io.ktor/ktor-client-curl-macosx64 ✅ https://mvnrepository.com/artifact/io.ktor/ktor-client-curl-macosarm64 ❌
For the context: we use libcurl as a Ktor client engine for macos in Realm-Kotlin and we're in the process of adding support for macosArm64
Mark Alvaro
12/15/2021, 12:59 AMrunBlocking
, but I doubt that’s a performant or even suggested approach, and it won’t work for JS or common).
As far as working with the service using Kotlin goes, whether in my common, JVM, JS, or whatever source set, I had no issues. The problem I have is consuming the service from Java code of course adds the Continuation argument, which isn’t something I want to impose on consumers of these services. I’ve seen a few threads in this channel about this issue, but I’m still wondering if there is any documentation or examples on how to make consuming the suspend function from Java sources more friendly. I saw mention of transforming to Futures or RxJava Singles or some other equivalent type, which is totally fine, but I’m not sure where to look for examples on how to even achieve that. I also know I can create a JVM-specific implementation that uses runBlocking
, but again I’m pretty sure that should be avoided. Am I correct that using runBlocking
would actually be worse than making the service using a RestEasy blocking client, due to coroutines not wanting to be blocked? Or would the performance be similar to a traditional blocking client, and I’d just be giving up benefits from using coroutines? Any pointers or links to guides would be appreciated!Bruno Medeiros
12/15/2021, 1:57 AMktor-server-core-macosx64
2.0.0-eap-272
instead of 2.0.0-eap-283
? Are we having any problems with the building mechanism, or is this discontinued?
• How can I install ktor-server-content-negotiation
? I can’t see this published for any platform, but without it I don’t know how to install the json serializerBruno Medeiros
12/15/2021, 1:57 AMktor-server-core-macosx64
2.0.0-eap-272
instead of 2.0.0-eap-283
? Are we having any problems with the building mechanism, or is this discontinued?
• How can I install ktor-server-content-negotiation
? I can’t see this published for any platform, but without it I don’t know how to install the json serializerAleksei Tirman [JB]
12/15/2021, 7:19 AMWhy is the latest version for@e5lktor-server-core-macosx64
instead of2.0.0-eap-272
? Are we having any problems with the building mechanism, or is this discontinued?2.0.0-eap-283
How can I installIt's available for the JVM. You can use? I can’t see this published for any platform, but without it I don’t know how to install the json serializerktor-server-content-negotiation
io.ktor:ktor-server-content-negotiation:$ktorVersion
and io.ktor:ktor-serialization-kotlinx-json:$ktorVersion
artifacts. Please read the docs for more information.Bruno Medeiros
12/15/2021, 7:22 AMAleksei Tirman [JB]
12/15/2021, 10:30 AMBruno Medeiros
12/15/2021, 10:31 AMe5l
12/15/2021, 10:49 AMBruno Medeiros
12/15/2021, 10:49 AMRustam Siniukov
12/15/2021, 2:01 PM