Daniel
03/20/2023, 4:48 PMio.ktor.client.plugins.auth.providers.AuthTokenHolder
is declared internal? I would like to utilize it in custom client AuthProvider
Tolga ÇAĞLAYAN
03/20/2023, 5:43 PMfun isTokenBlacklistedAdmin(token: Payload): Boolean {
val fetch = transaction {
AdminTokenTable.select {
AdminTokenTable.token eq token.toString()
}.firstOrNull()?.let {
AdminTokenList(
token = it[AdminTokenTable.token],
blackList = it[AdminTokenTable.blackList]
)
}
}
return when (
fetch?.blackList
) {
1 -> {
true
}
0 -> {
println("0")
false
}
else -> {
true
}
}
}
I have such a code block. While performing JWT validation, I want to check from the database whether the token is blacklisted. But how can I read the token from Payload? token.toString() doesn't work. I couldn't find any detailed information.Jilles van Gurp
03/21/2023, 7:55 AMjava.net.BindException: Can't assign requested address
at java.base/sun.nio.ch.Net.connect0(Native Method)
at java.base/sun.nio.ch.Net.connect(Net.java:579)
at java.base/sun.nio.ch.Net.connect(Net.java:586)
at java.base/sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:853)
at io.ktor.network.sockets.SocketImpl.connect$ktor_network(SocketImpl.kt:44)
at io.ktor.network.sockets.ConnectUtilsJvmKt.connect(ConnectUtilsJvm.kt:21)
at io.ktor.network.sockets.TcpSocketBuilder.connect(TcpSocketBuilder.kt:37)
at io.ktor.client.engine.cio.ConnectionFactory.connect(ConnectionFactory.kt:29)
at io.ktor.client.engine.cio.Endpoint$connect$2$connect$1.invokeSuspend(Endpoint.kt:156)
at io.ktor.client.engine.cio.Endpoint$connect$2$connect$1.invoke(Endpoint.kt)
at io.ktor.client.engine.cio.Endpoint$connect$2$connect$1.invoke(Endpoint.kt)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturnIgnoreTimeout(Undispatched.kt:100)
at kotlinx.coroutines.TimeoutKt.setupTimeout(Timeout.kt:146)
at kotlinx.coroutines.TimeoutKt.withTimeoutOrNull(Timeout.kt:103)
at io.ktor.client.engine.cio.Endpoint.connect(Endpoint.kt:164)
at io.ktor.client.engine.cio.Endpoint.makeDedicatedRequest(Endpoint.kt:98)
at io.ktor.client.engine.cio.Endpoint.execute(Endpoint.kt:62)
at io.ktor.client.engine.cio.CIOEngine.execute(CIOEngine.kt:84)
at io.ktor.client.engine.HttpClientEngine$executeWithinCallContext$2.invokeSuspend(HttpClientEngine.kt:99)
at ???(Coroutine boundary.?(?)
at io.ktor.client.engine.HttpClientEngine$DefaultImpls.executeWithinCallContext(HttpClientEngine.kt:100)
at io.ktor.client.engine.HttpClientEngine$install$1.invokeSuspend(HttpClientEngine.kt:70)
at io.ktor.client.plugins.HttpSend$DefaultSender.execute(HttpSend.kt:138)
at io.ktor.client.plugins.HttpRedirect$Plugin$install$1.invokeSuspend(HttpRedirect.kt:61)
at io.ktor.client.plugins.HttpCallValidator$Companion$install$3.invokeSuspend(HttpCallValidator.kt:147)
at io.ktor.client.plugins.HttpSend$Plugin$install$1.invokeSuspend(HttpSend.kt:104)
at io.ktor.client.plugins.DefaultTransformKt$defaultTransformers$1.invokeSuspend(DefaultTransform.kt:53)
at io.ktor.client.plugins.HttpCallValidator$Companion$install$1.invokeSuspend(HttpCallValidator.kt:126)
at io.ktor.client.plugins.HttpRequestLifecycle$Plugin$install$1.invokeSuspend(HttpRequestLifecycle.kt:35)
at io.ktor.client.HttpClient.execute$ktor_client_core(HttpClient.kt:191)
at io.ktor.client.statement.HttpStatement.executeUnsafe(HttpStatement.kt:108)
at io.ktor.client.statement.HttpStatement.execute(HttpStatement.kt:47)
at com.tryformation.api.graphql.FormationClient.executeRaw(FormationClient.kt:1037)
at com.tryformation.api.graphql.FormationClient.execute(FormationClient.kt:919)
at com.tryformation.graphqlapi.TestTeamAndClientCreator.createTeam$suspendImpl(APITest.kt:211)
at com.tryformation.graphqlapi.analytics.ArmyTestFixture.create(ArmyTestFixture.kt:272)
at com.tryformation.graphqlapi.analytics.ArmyTestFixture$armyWorkspace$2$1.invokeSuspend(ArmyTestFixture.kt:269)
at com.tryformation.graphqlapi.TestbeansKt$runTest$1.invokeSuspend(testbeans.kt:257)
Caused by: java.net.BindException: Can't assign requested address
at java.base/sun.nio.ch.Net.connect0(Native Method)
at java.base/sun.nio.ch.Net.connect(Net.java:579)
at java.base/sun.nio.ch.Net.connect(Net.java:586)
at java.base/sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:853)
at io.ktor.network.sockets.SocketImpl.connect$ktor_network(SocketImpl.kt:44)
at io.ktor.network.sockets.ConnectUtilsJvmKt.connect(ConnectUtilsJvm.kt:21)
at io.ktor.network.sockets.TcpSocketBuilder.connect(TcpSocketBuilder.kt:37)
at io.ktor.client.engine.cio.ConnectionFactory.connect(ConnectionFactory.kt:29)
at io.ktor.client.engine.cio.Endpoint$connect$2$connect$1.invokeSuspend(Endpoint.kt:156)
at io.ktor.client.engine.cio.Endpoint$connect$2$connect$1.invoke(Endpoint.kt)
at io.ktor.client.engine.cio.Endpoint$connect$2$connect$1.invoke(Endpoint.kt)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturnIgnoreTimeout(Undispatched.kt:100)
at kotlinx.coroutines.TimeoutKt.setupTimeout(Timeout.kt:146)
at kotlinx.coroutines.TimeoutKt.withTimeoutOrNull(Timeout.kt:103)
at io.ktor.client.engine.cio.Endpoint.connect(Endpoint.kt:164)
at io.ktor.client.engine.cio.Endpoint.makeDedicatedRequest(Endpoint.kt:98)
at io.ktor.client.engine.cio.Endpoint.execute(Endpoint.kt:62)
at io.ktor.client.engine.cio.CIOEngine.execute(CIOEngine.kt:84)
at io.ktor.client.engine.HttpClientEngine$executeWithinCallContext$2.invokeSuspend(HttpClientEngine.kt:99)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
Satyam Agarwal
03/21/2023, 12:40 PMjava.io.EOFException: Invalid chunk: content block of size <8192| multiple of 8> ended unexpectedly
at io.ktor.http.cio.ChunkedTransferEncodingKt.decodeChunked(ChunkedTransferEncoding.kt:93)
at io.ktor.http.cio.ChunkedTransferEncodingKt$decodeChunked$3.invokeSuspend(ChunkedTransferEncoding.kt)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
Suppressed: java.io.EOFException: Invalid chunk: content block of size 8192 ended unexpectedly
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at io.ktor.utils.io.ExceptionUtilsJvmKt$createConstructor$$inlined$safeCtor$3.invoke(ExceptionUtilsJvm.kt:103)
at io.ktor.utils.io.ExceptionUtilsJvmKt$createConstructor$$inlined$safeCtor$3.invoke(ExceptionUtilsJvm.kt:90)
at io.ktor.utils.io.ExceptionUtilsJvmKt.tryCopyException(ExceptionUtilsJvm.kt:66)
at io.ktor.utils.io.ByteBufferChannelKt.rethrowClosed(ByteBufferChannel.kt:2400)
at io.ktor.utils.io.ByteBufferChannelKt.access$rethrowClosed(ByteBufferChannel.kt:1)
at io.ktor.utils.io.ByteBufferChannel.setupStateForRead(ByteBufferChannel.kt:295)
at io.ktor.utils.io.ByteBufferChannel.copyDirect$ktor_io(ByteBufferChannel.kt:3377)
at io.ktor.utils.io.ByteBufferChannel$copyDirect$1.invokeSuspend(ByteBufferChannel.kt)
... 8 more
Caused by: [CIRCULAR REFERENCE: java.io.EOFException: Invalid chunk: content block of size 8192 ended unexpectedly]
Another stacktrace I see on the same issue
java.io.EOFException: Invalid chunk: content block of size 8192 ended unexpectedly
at io.ktor.http.cio.ChunkedTransferEncodingKt.decodeChunked(ChunkedTransferEncoding.kt:93)
at io.ktor.http.cio.ChunkedTransferEncodingKt$decodeChunked$3.invokeSuspend(ChunkedTransferEncoding.kt)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
Daniel
03/21/2023, 1:08 PMAdam S
03/22/2023, 8:39 AMEmbeddedServer should reference top level Application module extensionIntelliJ provides a quick-fix, but this prevents me from passing in any arguments to the configuration function. I want to configure the Ktor server using main args 🧵, but I can’t see how to do that without this warning. Any ideas?
Christian H.
03/22/2023, 12:17 PMuseEffectOnce {
scope.launch {
...
}
}
ReferenceError: Job is not defined at HttpClient (webpack-internal:///./kotlin/ktor-ktor-client-core-js-ir.js:599:24)
Dependency versions:
val kotlinVersion = "1.8.0"
val kotlinxCoroutinesVersion = "1.6.4"
val serializationVersion = "1.3.3"
val ktorVersion = "2.0.3"
val logbackVersion = "1.2.11"
val kotlinWrappersVersion = "1.0.0-pre.354"
using js(IR) compiler
Thanks for your help in advance!ribesg
03/22/2023, 1:15 PM<http://io.ktor.server.routing.post|io.ktor.server.routing.post>
if the reified type used is marked with @Resource
. Just had everything fail with 404 errors because I didn't manually import <http://io.ktor.server.resources.post|io.ktor.server.resources.post>
and my IDE saw nothing wrong with that.Austin Pederson
03/22/2023, 6:27 PMRequestValidation
plugin and I was curious if there was any way to either extend ValidationResult.Invalid
to include a Throwable, or a way to pass a throwable to StatusPages
using ValidationResult
. Currently I am just throwing an error in the install(RequestValidation) {}
block and always returning ValidationResult.Valid
but that feels like a gross workaroundbrabo-hi
03/22/2023, 7:39 PMOsman Saral
03/22/2023, 8:46 PMKirill Zhukov
03/22/2023, 11:01 PMDarwinClientEngine
declares Unconfined
dispatcher, but not sure this it’s actually being used for requests?Lev Teytelman
03/23/2023, 4:21 AM@Serializable
data class Tag(
val name: String,
@Serializable(with = TagStringSerializer::class)
val parent: Tag? = null,
val subTags: MutableSet<@Serializable(with = TagStringSerializer::class) Tag> = ConcurrentSet(),
val files: MutableSet<@Serializable(with = SavedFileStringSerializer::class) SavedFile> = ConcurrentSet()
)
@Serializable
data class SavedFile(
@Serializable(with = FileSerializer::class)
val file: File,
val tags: MutableSet<@Serializable(with = TagStringSerializer::class) Tag> = ConcurrentSet()
)
Of course, I don't want recursive Tags/SavedFiles in my serialization, as that would lead to infinite loops; I only serialize the names (all my custom serializers do is extract names).
When I use ApplicationCall#respond(savedFile)
, this works properly and sends {"file":"example","tags":["test"]}
.
However, when I do ApplicationCall#respond(savedFile.tags)
, I receive an array of default-serialized tags instead of just the names, as if it's ignoring the annotation in the set: [{"name":"test","subTags":[],"files":["example"]}]
.
Even stranger, when I do just Json.encodeToString(savedFile.tags)
, it works just fine and gives me a properly-encoded array ["test"]
.
Of course, I could just create a function like respondJson
and wrap a call to respondText(Json.encodeToString(
, but this seems hacky and non-ideal.
I'm just very confused as to why the two functions are behaving differently and how I can fix the serialization done within ApplicationCall#respond
.Arjan van Wieringen
03/23/2023, 10:26 AMBenedikt Kaiser
03/23/2023, 2:48 PMAbe Sol
03/23/2023, 9:14 PMOsman Saral
03/24/2023, 4:54 PM@Test
fun test() = testApplication {
externalServices {
hosts("<wss://test.com>") {
install(io.ktor.server.websocket.WebSockets) { }
routing {
webSocket("/test") {
send(Frame.Text("hello"))
}
}
}
}
val client = createClient {
install(WebSockets) {
contentConverter = KotlinxWebsocketSerializationConverter(
Json {
ignoreUnknownKeys = true
}
)
}
}
runBlocking {
client.wss(host = "<http://test.com|test.com>", path = "test") {
val string = Json.encodeToString(User("foo"))
// val string = """{"name":"foo"}"""
println(string)
send(Frame.Text(string))
}
}
}
On the runBlocking block; both lines prints {"name":"foo"}
but the`send` function throws java.util.concurrent.CancellationException: ArrayChannel was cancelled
error for the first string
, and it doesn't throw for the second.Piotr Krzemiński
03/25/2023, 5:38 PMNishant Aanjaney Jalan
03/26/2023, 12:17 AMdephinera
03/26/2023, 3:54 PMManuel Pérez Alcolea
03/26/2023, 7:15 PMByteReadChannel
, ByteWriteChannel
, what's the benefit of them? And what does the following mean?
Operations on this channel cannot be invoked concurrently.when is a
ByteWriteChannel
more convenient than this?
val url = URL(...)
val targetDir = Path.of(...)
withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
url.openStream().use { stream ->
Files.copy(stream, targetDir)
}
}
are they just meant to be used to read and write in chunks without blocking everything else in a thread, and to yield it to other coroutines?Konstantin Zolotov
03/26/2023, 7:36 PMException in thread "main" java.net.BindException: Can't assign requested address
at java.base/sun.nio.ch.DatagramChannelImpl.send0(Native Method)
at java.base/sun.nio.ch.DatagramChannelImpl.sendFromNativeBuffer(DatagramChannelImpl.java:587)
at java.base/sun.nio.ch.DatagramChannelImpl.send(DatagramChannelImpl.java:549)
at java.base/sun.nio.ch.DatagramChannelImpl.send(DatagramChannelImpl.java:532)
at io.ktor.network.sockets.DatagramSendChannel$send$2$1.invokeSuspend(DatagramSendChannel.kt:80)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
This is my code:
fun main() {
runBlocking {
val selectorManager = SelectorManager(<http://Dispatchers.IO|Dispatchers.IO>)
val socket = aSocket(selectorManager)
.udp()
.bind(InetSocketAddress("127.0.0.1", 4756))
launch(<http://Dispatchers.IO|Dispatchers.IO>) {
for (datagram in socket.incoming) {
val bytes = datagram.packet.readBytes()
val decoded = decode(bytes)
<http://logger.info|logger.info>("Received: $decoded from ${datagram.address}")
}
}
val packet = BytePacketBuilder().apply { request }.build() // Here I create the packet to send, just raw bytes, nothing related to the problem
val message = Datagram(
packet = packet,
address = InetSocketAddress("<http://router.bittorrent.com|router.bittorrent.com>", 6881)
)
socket.send(message)
}
}
No idea why this is happening, can any one help me please?dany giguere
03/26/2023, 7:38 PMinstall(RequestValidation) {
validate<Post> { post ->
if (post.title.length < 4)
ValidationResult.Invalid("A post ID should be greater than 0")
else ValidationResult.Valid
}
...
But eventually there will be a lot of validations in there. It would be nice if I could apply to my post routes, only the validation regarding the posts…Tung97 Hl
03/27/2023, 4:36 AMOsman Saral
03/27/2023, 3:39 PMDaniel
03/27/2023, 3:43 PMDaniel
03/28/2023, 10:29 AMjoelkmuraguri21
03/28/2023, 3:48 PMFred Friis
03/28/2023, 4:17 PMMarcus Cvjeticanin
03/28/2023, 5:41 PMMarcus Cvjeticanin
03/28/2023, 5:41 PMsimon.vergauwen
03/28/2023, 6:01 PMRyan Brink
03/28/2023, 6:29 PMArjan van Wieringen
03/28/2023, 8:27 PM