Shalaga44
09/05/2020, 1:42 AMfun main() {
embeddedServer(
Netty, watchPaths = listOf("jvmMain"), port = 8080,
module = Application::myModule
).start(wait = true)
}
fun Application.myModule() {
routing {
get("/") {
call.respondHtml(HttpStatusCode.OK, HTML::index)
}
static("/static") {
resources()
}
}
}
Chris Fillmore
09/06/2020, 3:35 AMfkrauthan
09/06/2020, 10:06 PMfkrauthan
09/07/2020, 2:36 AMandylamax
09/07/2020, 2:18 PMHexa
09/07/2020, 6:28 PMfkrauthan
09/08/2020, 4:42 AMgotoOla
09/08/2020, 1:17 PMstack_trace java.io.IOException: Connection reset by peer
at (Coroutine boundary.()
at io.ktor.client.engine.apache.ApacheEngine.execute(ApacheEngine.kt:23)
at io.ktor.client.engine.HttpClientEngine$install$1.invokeSuspend(HttpClientEngine.kt:49)
at io.ktor.client.features.HttpSend$DefaultSender.execute(HttpSend.kt:90)
at io.ktor.client.features.HttpSend$Feature$install$1.invokeSuspend(HttpSend.kt:62)
at io.ktor.client.HttpClient.execute(HttpClient.kt:141)
at io.ktor.client.call.HttpClientCallKt.call(HttpClientCall.kt:140)
at mycompany.clients.SearchClient.getSearch(SearchClient.kt:76)
at mycompany.services.SearchService$getPrerequisits$2.invokeSuspend(SearchService.kt:28)
at mycompany.endpoints.SearchEndpoints$createRoutes$1$1$2.invokeSuspend(ExportEndpoints.kt:61)
at mycompany.core.ktor.Router_extensionsKt$postAndReportMetrics$2.invokeSuspend(router_extensions.kt:57)
at io.ktor.routing.Routing.executeResult(Routing.kt:147)
at io.ktor.routing.Routing$Feature$install$1.invokeSuspend(Routing.kt:99)
at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$2.invokeSuspend(DefaultEnginePipeline.kt:118)
at io.ktor.server.netty.NettyApplicationCallHandler$handleRequest$1.invokeSuspend(NettyApplicationCallHandler.kt:36)
Caused by: java.io.IOException: Connection reset by peer
at sun.nio.ch.FileDispatcherImpl.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
at sun.nio.ch.IOUtil.read(IOUtil.java:197)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:377)
at org.apache.http.nio.reactor.ssl.SSLIOSession.receiveEncryptedData(SSLIOSession.java:444)
at org.apache.http.nio.reactor.ssl.SSLIOSession.isAppInputReady(SSLIOSession.java:499)
at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:120)
at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276)
at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:588)
at java.lang.Thread.run(Thread.java:748)
t tags logstash
t thread_name DefaultDispatcher-worker-7 @call-handler#3553
Gus
09/08/2020, 4:33 PMMockEngine
for testing. However, I'm finding myself duplicating the config (e.g., install(...)
) across the two clients because I couldn't find a way to define it once. Any pointers on how one may do that?Ivann Ruiz
09/08/2020, 7:44 PM1.4.0
is broken. I used version 1.3.2-1.4.0-rc
and it worked like a charm as suggested here. Had this issue since last week and after a few days finally found the cause haha thought I'd save others the time. For the record, my iOS app was throwing a Thread 1: signal SIGABRT
on the IDE and saw this in the logs Uncaught Kotlin exception: kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlinx.coroutines.ChildHandleNode@31dca08
.
Again it all works now after reverting the versions.fkrauthan
09/08/2020, 8:23 PMJohn O'Reilly
09/10/2020, 9:33 AMOleg Yukhnevich
09/10/2020, 11:07 AMConstantin Muraru
09/11/2020, 9:21 AMCallLogging
and DoubleReceive
):
install(DoubleReceive)
install(CallLogging) {
level = <http://Level.INFO|Level.INFO>
format { callFormatterAsCurlCommand(it) }
}
fun callFormatterAsCurlCommand(call: ApplicationCall): String {
val payload = runBlocking { call.receiveText() }
return payload
}
However, we receive the Request body has been already consumed
error, which is rather unexpected. Furthermore, the error is thrown by the DoubleReceive.kt
class itself.
The docs even say:
All the receive methods consume the whole payload sent by the client so an attempt to receive a request body twice will lead toerror unless you have DoubleReceive feature installed.RequestAlreadyConsumedException
https://ktor.io/servers/calls/requests.html#receiving-several-timesException:
io.ktor.request.RequestAlreadyConsumedException: Request body has been already consumed (received).
at io.ktor.features.DoubleReceive$Feature$install$1.invokeSuspend(DoubleReceive.kt:93) ~[ktor-server-core-jvm-1.4.0.jar:1.4.0]
at io.ktor.features.DoubleReceive$Feature$install$1.invoke(DoubleReceive.kt) ~[ktor-server-core-jvm-1.4.0.jar:1.4.0]
at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:323) ~[ktor-utils-jvm-1.4.0.jar:1.4.0]
Any tips gladly appreciated.LastExceed
09/11/2020, 12:54 PM.close()
and .dipose()
but the port is still in use afterwardsIvan Pavlov
09/12/2020, 4:45 AMkotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 15: Expected '[, kind: SEALED'
JSON input: {
"place":{
"type":"point",
"lon":22.0,
"lat":56.7
}
}
Routing looks like that:
post("/") {
val body = call.receive<AddVisitDataDto>()
call.respond(body.toString())
}
My model:
@kotlinx.serialization.Serializable
data class AddVisitDataDto(
val place: PlaceDto
)
@kotlinx.serialization.Serializable
sealed class PlaceDto {
@kotlinx.serialization.Serializable
@SerialName("external")
data class External(val externalId: String) : PlaceDto()
@kotlinx.serialization.Serializable
@SerialName("point")
data class Point(val lon: Double, val lat: Double) : PlaceDto()
}
When I change receiving to the following code it works fine:
val text = call.receiveText()
val body = Json.decodeFromString<AddVisitDataDto>(text)
I tried to add @Polymorphic
to place
property but it only changes error to
kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 15: Expected '[, kind: OPEN'
Am I doing something wrong?Avadhut
09/12/2020, 5:55 PMopen class SimpleJWT(val secret: String) {
private val algorithm = Algorithm.HMAC256(secret)
val verifier = JWT.require(algorithm).build()
fun sign(name: String): String = JWT.create().withClaim("name", name).sign(algorithm)
}
fun Application.module() {
val simpleJwt = SimpleJWT("my-super-secret-for-jwt")
install(Authentication) {
jwt {
verifier(simpleJwt.verifier)
validate {
UserIdPrincipal(it.payload.getClaim("name").asString())
}
}
}
// ...
}
keishi kubo
09/14/2020, 4:41 PMKris Wong
09/14/2020, 5:27 PMThiyagu
09/15/2020, 8:44 AMSlackbot
09/15/2020, 12:22 PMarnaud.giuliani
09/16/2020, 7:02 AMThomas
09/16/2020, 8:05 AMhhariri
09/16/2020, 12:45 PMJohn O'Reilly
09/16/2020, 12:53 PMdigest
auth for ktor client and server....REST api requests are working fine but getting 401 for websocket connection......for basic
auth I was able to use sendWithoutRequest = true
but that doesn't seem to be an option for digest
.....is there any way for it to use same auth in that case for ws/wss connections?Justin Moy
09/16/2020, 10:13 PM1.4
and I’m trying to read an arbitrary response back from the ktor http client and return it from my ktor server, but I’m having trouble as the type that could be returned back might change (e.g. I can’t pin it down to <http://httpClient.post|httpClient.post><SpecificType>()
) is there a way to return an arbitrary type? Also right now my code seems to not be passing forward the return type of the httpClient to the server. Code in thread ->John O'Reilly
09/17/2020, 1:50 PMOleg Yukhnevich
09/17/2020, 6:33 PMpascal_le_merrer
09/18/2020, 9:00 AMgotoOla
09/18/2020, 9:37 AMHttpClient(OkHttp) {
expectSuccess = false
}.config {
// These value exists in the java builder of OkHttp but I don't know how to configure them through the engine {} or config {} ktor api
callTimeout = 0
connectTimeout = 0
readTimeout = 0
writeTimeout = 0
pingInterval = 0
}
gotoOla
09/18/2020, 9:37 AMHttpClient(OkHttp) {
expectSuccess = false
}.config {
// These value exists in the java builder of OkHttp but I don't know how to configure them through the engine {} or config {} ktor api
callTimeout = 0
connectTimeout = 0
readTimeout = 0
writeTimeout = 0
pingInterval = 0
}
val client = HttpClient() {
install(HttpTimeout) {
// timeout config
requestTimeoutMillis = 1000
}
}
Looking back at it it was maybe a stupid question... I was used to the apache engine where you configured it in the enginerrva
09/21/2020, 10:09 AM