Jakub Gwóźdź
09/06/2022, 9:44 AMtestApplication { … }
, but I have a method that is simply
suspend fun readPartsContents(call: ApplicationCall): List<UploadedContent> = call
.receiveMultipart()
.readAllParts()
.flatMap(::processPart)
and I’d like to mock that call
in my unit test. But I can’t since .receiveMultipart()
is unmockable extension function…hhariri
09/07/2022, 5:47 AMAyfri
09/08/2022, 7:46 AMapplication.conf
file ? I have the ktor
plugin but it shows very little syntax highlighting and no real code completion ? (just the words I already used in the file)Hamza GATTAL
09/08/2022, 3:24 PMDefaultRequest
plugin work with WebSockets
.Ivan Đorđević
09/08/2022, 5:33 PM@JvmName("postTyped")
public inline fun <reified R : Any> <http://Route.post|Route.post>(
crossinline body: suspend PipelineContext<Unit, ApplicationCall>.(R) -> Unit
): Route = post {
body(call.receive())
}
?
I realize there's receiveNullable
but there's no way to do it via route declaration, only in the body of the route itself 😕
EDIT: Nvm I realize I'm just stupid, I could just make properties inside the route model nullable instead to achieve the same effect :DFrancesco Di Sciascio
09/09/2022, 8:16 AMFrancesco Di Sciascio
09/09/2022, 8:18 AMroute("/sCap"){
val dao: DAOFacade = DAOFacadeImpl()
get{
val codiceParam = call.request.queryParameters["codice"]
val listSCap = dao.allSCapFiltered(codiceParam)
if(listSCap.isEmpty())
call.respondText("Nessun elemento trovato", status = HttpStatusCode.NotFound)
else
call.respond(listSCap)
}
...
}
and in the DAO:
override suspend fun allSCapFiltered(codice: String?): List<SCap> {
return if(codice.isNullOrEmpty()){
DatabaseFactory.dbQuery {
S_Cap.selectAll().map(::resultRowToSCap)
}
} else {
DatabaseFactory.dbQuery {
S_Cap
.select { S_Cap.codice like "%$codice%" }
.map(::resultRowToSCap)
}
}
}
is there a way to manage all the parameters expected dynamically, based on properties of data class?
data class SCap(val idcap: Int?,
val regione: String?,
val prov: String?,
val comune: String?,
val cap: Int?,
val codice: String?
)
Thanks everyone for suggestions!Lucas León
09/10/2022, 5:08 AMHamza GATTAL
09/10/2022, 2:29 PMaarjav
09/10/2022, 6:21 PMzt
09/12/2022, 1:09 AMwriteShort
but that's for signed intRaphael TEYSSANDIER
09/12/2022, 2:10 PMBen Kosten
09/12/2022, 3:11 PMByteReadChannel
and copying those bytes over and Writing to another ByteWriteChannel
The proxy should tunnel connections from client A to server B via proxy server C like so:
A <---> C <---> B
currently, I have something like the following:
//some boilerplate to open correct channels and establish socket connections
val clientReadChannel = clientSocket.openReadChannel()
val clientWriteChannel = clientSocket.openWriteChannel(true)
val serverReadChannel = serverSocket.openReadChannel()
val serverWriteChannel = serverSocket.openWriteChannel(true)
launch(<http://Dispatchers.IO|Dispatchers.IO>) {
clientReadChannel.copyTo(serverWriteChannel)
}
launch(<http://Dispatchers.IO|Dispatchers.IO>) {
serverReadChannel.copyTo(clientWriteChannel)
}
zt
09/12/2022, 11:10 PMval selectorManager = SelectorManager(Dispatchers.Main)
val socketPath = "/tmp/.X11-unix/X2"
val tcp = aSocket(selectorManager).tcp()
val clientConnection = try {
tcp.connect(UnixSocketAddress(socketPath))
} catch (e: Exception) {
selectorManager.close()
println(e.message)
exitProcess(1)
}
val readChannel = clientConnection.openReadChannel()
val sendChannel = clientConnection.openWriteChannel()
val authName = ""
val authData = ""
fun BytePacketBuilder.writePadding(bytes: Int) {
repeat((4 - bytes % 4) % 4) { writeByte(0) }
}
sendChannel.writePacket {
writeUByte(102u)
writeByte(0)
writeUShort(11u)
writeUShort(0u)
writeUShort(authName.length.toUShort())
writeUShort(authData.length.toUShort())
writeByte(0)
writeText(authName)
writePadding(authName.length)
writeText(authData)
writePadding(authData.length)
}
sendChannel.flush()
println(readChannel.readByte())
It just suspends at the readByte callnapperley
09/13/2022, 1:50 AM// ...
static("/") {
staticRootFolder = File("files")
file("index.html")
default("index.html")
static("assets") {
files("css")
files("js")
}
}
For some reason all the missing imports cannot be completed. The main exception to this is File
.zt
09/13/2022, 2:42 AMval vendor = buildString {
repeat(lengthOfVendor) {
append(readChannel.readByte().toInt().toChar())
}
}
Satyam Agarwal
09/13/2022, 9:46 AMJorge Bo
09/13/2022, 7:41 PM"i.k.u.i.c.TooLongLineException: Line is longer than limit\n\tat i.k.u.i.ByteBufferChannel$readUTF8LineToUtf8Suspend$2.invokeSuspend(ByteBufferChannel.kt:2094)\n\tat i.k.u.i.ByteBufferChannel$readUTF8LineToUtf8Suspend$2.invoke(ByteBufferChannel.kt)\n\tat i.k.u.i.ByteBufferChannel$readUTF8LineToUtf8Suspend$2.invoke(ByteBufferChannel.kt)\n\tat i.k.u.i.ByteBufferChannel.lookAheadSuspend$suspendImpl(ByteBufferChannel.kt:1826)\n\tat i.k.u.i.ByteBufferChannel.lookAheadSuspend(ByteBufferChannel.kt)\n\tat i.k.u.i.ByteBufferChannel.readUTF8LineToUtf8Suspend(ByteBufferChannel.kt:2076)\n\tat i.k.u.i.ByteBufferChannel.readUTF8LineToAscii(ByteBufferChannel.kt:2011)\n\tat i.k.u.i.ByteBufferChannel.readUTF8LineTo$suspendImpl(ByteBufferChannel.kt:2113)\n\tat i.k.u.i.ByteBufferChannel.readUTF8LineTo(ByteBufferChannel.kt)\n\tat i.k.u.i.ByteBufferChannel.readUTF8Line$suspendImpl(ByteBufferChannel.kt:2117)\n\tat i.k.u.i.ByteBufferChannel.readUTF8Line(ByteBufferChannel.kt)\n\t
Emil Kantis
09/14/2022, 10:05 AMwhile (true)
loop until a connection appears.PHondogo
09/14/2022, 11:00 AMTrevor Stone
09/15/2022, 2:21 AMINFO ktor.application - Application auto-reloaded in 0.008 seconds.
the above prints and everything in the console, but the actually responses aren't changing. I'm using coretto 17martmists
09/15/2022, 2:18 PMjoney
09/16/2022, 9:33 AMContentNegotiation
plugin:
I need access to the serialised body (as TextContent
) in order to calculate a header value: The api I’m using expects a signature header which needs the body content for calculating the signature value 🙃.
Snipped of what I’m trying to do in HttpRequestPipeline.Send
phase: private val HttpRequestBuilder.bodyAsText get() = (body as? TextContent)?.text
(Prior to send the body is not available as text)
Problem: I cannot set headers anymore after the body had been serialised, is that correct? Do you know a workaround?Alberto Quario
09/16/2022, 3:37 PMclient.request(url) {
HttpMethod.Get
accept(ContentType.Application.Json)
contentType(ContentType.Application.Json)
timeout { requestTimeoutMillis = 60 * 1000
connectTimeoutMillis = 5 * 1000
socketTimeoutMillis = 60 * 1000 }
}
Using ktor 2.0.3 we never had any problems, with version 2.1.0 and 2.1.1 sometimes the call fails with:
org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited message body (expected: 41,606; received: 26,090)
Same code with the old ktor version started to work again correctly.
Anyone having the same problem? Any hint on how to fix it?
Thanks!mytrile
09/17/2022, 7:07 AMAyfri
09/17/2022, 12:29 PMprettyPrint
, so
[
]
I get an error io.ktor.serialization.JsonConvertException: Illegal input
, which doesn't occur when using only kotlinx.serialization
Norbi
09/18/2022, 6:14 PMrefreshToken
property if there is no refresh token (in case of _client_credentials_ flow)?
Thanks.zt
09/19/2022, 2:42 AMhhariri
09/19/2022, 10:32 AMPartho Paul
09/19/2022, 3:11 PMfun main(args: Array<String>): Unit = runBlocking(Dispatchers.Default) {
embeddedServer(
Netty,
) { module() }.awaitShutdown()
}
fun Application.module(testing: Boolean = false) {
configureMonitoring()
configureRouting()
configureSerialization()
configureHTTP()
configureKoin()
statusPage()
}
But I’m not sure where to pass the args from conf file. I know I can use fun main(args: Array<String>): Unit = EngineMain.main(args)
instead of embeddedServer but I’m not sure I can add custom shutdown hook to it. Can someone please help me for this?Partho Paul
09/19/2022, 3:11 PMfun main(args: Array<String>): Unit = runBlocking(Dispatchers.Default) {
embeddedServer(
Netty,
) { module() }.awaitShutdown()
}
fun Application.module(testing: Boolean = false) {
configureMonitoring()
configureRouting()
configureSerialization()
configureHTTP()
configureKoin()
statusPage()
}
But I’m not sure where to pass the args from conf file. I know I can use fun main(args: Array<String>): Unit = EngineMain.main(args)
instead of embeddedServer but I’m not sure I can add custom shutdown hook to it. Can someone please help me for this?August Lilleaas
09/19/2022, 5:46 PMPartho Paul
09/20/2022, 4:51 AMEngineMain.main(args)
implementation, I’m able to read the config via environment.config.property(key).getString()
. Using the same for embeddedServer is not working and is throwing io.ktor.server.config.ApplicationConfigurationException: Property ktor.api.customkey not found
August Lilleaas
09/20/2022, 6:40 AMPartho Paul
09/20/2022, 9:29 AMval environment = applicationEngineEnvironment {
this.parentCoroutineContext = coroutineContext + parentCoroutineContext
this.log = KtorSimpleLogger("ktor.application")
this.connectors.addAll(connectors)
this.config = HoconApplicationConfig(ConfigFactory.load())
}
embeddedServer(factory, environment, configure).apply { start() }