https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
ktor
  • h

    Halil Ozercan

    03/26/2020, 1:45 PM
    Hey everyone, I’m using websockets from ktor server and client in a side project. Recently, I discovered that my client agents are disconnecting due to an internet connectivity issue and not realizing they’ve lost the connection, meanwile the server is well aware of disconnection. I’ve been using DefaultWebSocketImpl which means ping-pong should have caught this issue. After some digging, it turns out that ping-pong mechanism actually is not enabled by default on client sockets. Although client WebSockets feature takes
    pingInterval
    and
    maxFrameSize
    as constructor parameters,
    install(WebSockets)
    does not have a configuration option. So, I’m now stuck, not able to turn on a feature that already exists. Furthermore,
    maxFrameSize
    is passed to
    DefaultWebSocketSession
    as
    return DefaultWebSocketSession(this, pingInterval, maxFrameSize)
    it turns out, third parameter is actually
    timeoutMillis
    not related to frameSize at all. I’ve made necessary changes to client WebSockets feature to actually take configuration and added
    timeoutMillis
    . Do you think I should make a pull request? It is a really small change and backward compatible.
    m
    e
    • 3
    • 6
  • p

    Paulius Ruminas

    03/26/2020, 6:35 PM
    Hi, we have this sealed class:
    @Serializable
    sealed class PaymentResult {
        @Serializable
        object Authorised : PaymentResult()
        @Serializable
        data class Error(val refusalReason: String) : PaymentResult()
        @Serializable
        data class Refused(val refusalReason: String, val refusalReasonCode: String) : PaymentResult()
    }
    we have installed json content negotiation:
    install(ContentNegotiation) {
        json(json)
    }
    we respond with:
    call.respond(PaymentResult.Authorised)
    currently it returns:
    {}
    is it possible to use polymorphic serializer for responses?
    s
    • 2
    • 1
  • s

    Sam Garfinkel

    03/26/2020, 7:48 PM
    Minor complaint, but there aren’t any first-class helpers for creating asynchronous instances of client requests? I know you can easily do
    async { request { } }
    but still would nice to eliminate the boilerplate.
    l
    d
    • 3
    • 3
  • g

    Gabriel Feo

    03/26/2020, 10:22 PM
    I'm getting these errors by running a Ktor project in a Docker container. Can anyone help?
    Mar 26, 2020 9:58:28 PM io.grpc.internal.ManagedChannelImpl$1 uncaughtException
    SEVERE: [Channel<1>: (<http://firestore.googleapis.com:443|firestore.googleapis.com:443>)] Uncaught exception in the SynchronizationContext. Panic!
    java.lang.IllegalStateException: Could not find policy 'pick_first'. Make sure its implementation is either registered to LoadBalancerRegistry or included in META-INF/services/io.grpc.LoadBalancerProvider from your jar files.
    
    2020-03-26 22:08:04.961 [nioEventLoopGroup-4-1] ERROR Application - Unhandled exception caught for CoroutineName(call-handler)
    com.google.api.gax.rpc.InternalException: io.grpc.StatusRuntimeException: INTERNAL: Panic! This is a bug!
    • 1
    • 1
  • n

    napperley

    03/27/2020, 1:48 AM
    Is there someone from the Ktor team that would be able to assist me in tracking down memory leaks ( https://kotlinlang.slack.com/archives/C3SGXARS6/p1585269741051100 ) in a Kotlin Native program (targets linuxX64)?
    • 1
    • 2
  • d

    Darmaheev

    03/27/2020, 9:06 AM
    Hello, help me please!!)) I try build my lib with ktor 1.3.2, but get error: Could not resolve all files for configuration ‘:androidCompileClasspath’. Could not find io.ktor:ktor-client-android:1.3.2. In maven repositories
    mavenLocal()
    maven { url "<https://kotlin.bintray.com/kotlinx>" }
    mavenCentral()
    e
    • 2
    • 6
  • m

    mbonnin

    03/29/2020, 11:58 AM
    I just upgraded from ktor 1.2.6 to 1.3.2 and my httpClient hangs on MacOSX. I'm using a manual dispatcher like described in https://github.com/Kotlin/kotlinx.coroutines/issues/470#issuecomment-440080970. Any idea what I'm doing wrong ?
    actual fun macOSMain() {
        GlobalScope.launch(mainDispatcher) {
            val response = HttpClient {
            }.get<HttpResponse>("<https://google.com/>") {
            }
            println("response status is: ${response.status}")
        }
        CFRunLoopRun()
    }
    Full repo at: https://github.com/martinbonnin/kmpCli/blob/ktor-hangs
    • 1
    • 1
  • r

    Rodrigo Silva

    03/30/2020, 5:09 PM
    How a set a default timezone in ktor ?
    v
    • 2
    • 3
  • b

    bmarinovic

    03/30/2020, 8:42 PM
    Hi, is it possible to enforce required/optional fields in JSON serialization? It seems that kotlinx.serialization does the job of enforcing that fields should be required if no defaults are provided, but I was wondering if I can make some optional by saying it’s nullable with e.g.
    String?
    or
    Optional<String>
    ?
    s
    • 2
    • 3
  • r

    Rodrigo Silva

    03/31/2020, 1:24 AM
    hi all. I'm using kotlinx serialization, but i'm getting this error:
    d
    • 2
    • 7
  • k

    Kurt Renzo Acosta

    03/31/2020, 9:45 AM
    Hello guys! Is there a counterpart for OkHttp's interceptor in the common code? I'm trying to implement an authentication interceptor for refreshing oauth tokens. I've been using OkHttp but it's only for Android. I created a
    defaultRequest
    block and set up the Authorization header there but I can't seem to find anything to "intercept" it if it needs to be refreshed. Thanks in advance!
    • 1
    • 1
  • b

    bitkid

    03/31/2020, 12:20 PM
    Has anyone seen this exception? I basically get it on every request (ktor 1.3.2 running in docker in an openshift environment) but everything seems to work fine (i see the output as DEBUG)
    2020-03-31 12:14:53.832 [nioEventLoopGroup-4-2] DEBUG Application - 200 OK: GET - /api/repositories/1/matrices/1/data
    2020-03-31 12:15:07.621 [nioEventLoopGroup-3-2] DEBUG Application - I/O operation failed
    <http://java.io|java.io>.IOException: Connection reset by peer
    	at java.base/sun.nio.ch.FileDispatcherImpl.read0(Native Method)
    	at java.base/sun.nio.ch.SocketDispatcher.read(Unknown Source)
    	at java.base/sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source)
    	at java.base/sun.nio.ch.IOUtil.read(Unknown Source)
    	at java.base/sun.nio.ch.IOUtil.read(Unknown Source)
    	at java.base/sun.nio.ch.SocketChannelImpl.read(Unknown Source)
    	at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:251)
    	at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1133)
    	at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:350)
    	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:148)
    	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
    	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
    	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
    	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
    	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
    	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    	at java.base/java.lang.Thread.run(Unknown Source)
    m
    f
    • 3
    • 7
  • d

    diesieben07

    03/31/2020, 3:13 PM
    When using the
    ContentNegotiation
    feature with Jackson for JSON bodies Ktor responds with HTTP 500 if the client sends invalid JSON or JSON that does not match the data classes I am trying to receive. I would expect HTTP 400 instead. Is there a way to configure this?
    s
    m
    • 3
    • 9
  • d

    Dave Leeds

    03/31/2020, 5:18 PM
    I’m looking into configuring the
    Accept-Encoding
    header for my Ktor
    HttpClient
    . I found the
    ContentEncoding
    feature (https://github.com/ktorio/ktor/blob/master/ktor-client/ktor-client-features/ktor-client-encoding/common/src/ContentEncoding.kt) but I don’t see that
    compression
    package in my
    ktor-client-core-jvm
    jar. Is it published under a separate artifact? Or am I just looking for it in the wrong place?
    • 1
    • 1
  • r

    Robert Jaros

    03/31/2020, 8:52 PM
    Why is Ktor client sending
    Accept: application/xml;application/json
    header when I call:
    <http://httpClient.post|httpClient.post>(serviceUrl) {
                    contentType(ContentType.Application.Json)
                    accept(ContentType.Application.Xml)
                    body = MyClass(...)
                }
    Does such header even conform to HTTP standard?
    d
    • 2
    • 5
  • d

    Dariusz Kuc

    03/31/2020, 11:22 PM
    Hello! Does anyone have some nice example of Ktor HTTP Client websockets usage that works with flow instead of raw channels?
    e
    • 2
    • 3
  • m

    Marc Knaup

    04/02/2020, 2:05 PM
    Is it normal that
    Job.cancel()
    throws a
    CancellationException
    itself? Or is this a bug in Ktor?
    java.util.concurrent.CancellationException: Job was cancelled
        at io.ktor.client.engine.UtilsKt$attachToUserJob$cleanupHandler$1.invoke(Utils.kt:77)
        at io.ktor.client.engine.UtilsKt$attachToUserJob$cleanupHandler$1.invoke(Unknown Source:2)
        …
        at kotlinx.coroutines.JobSupport.cancel(JobSupport.kt:614)
        at kotlinx.coroutines.Job$DefaultImpls.cancel$default(Job.kt:164)
    e
    l
    o
    • 4
    • 10
  • g

    Gunslingor

    04/03/2020, 3:20 PM
    Simple question: How does one schedule a task in Ktor? Code seems to indicate it is capable but docs are missing... "as soon as you have to reverse engineer someone else's library to use it you should question whether you should be using it for anything meaningful", says me, lol. Here is how spring does it:
    @Scheduled(fixedRate = 60000)
    r
    c
    • 3
    • 40
  • c

    crummy

    04/04/2020, 9:30 AM
    hmm, it worked when I imported
    ktor-client-gson
    instead. I guess that's because I needed an implementation?
    d
    • 2
    • 1
  • b

    bitkid

    04/06/2020, 11:21 AM
    hey! i saw that ktor implements features for authentication. is there also a framework for authorization? i have a server in our organisation which basically can do RBAC and ABAC and handles access to resources. so in each call to my ktor app i have to make a http request to that server and check for authorization. how would i handle that? any suggestions? add an interceptor after the autentication pipeline? do it directly in my routes?
    m
    • 2
    • 3
  • p

    Pacane

    04/06/2020, 12:42 PM
    Hi, is there a way to bind to a dynamic port with ktor instead of a fixed port?
    👍🏻 2
    e
    • 2
    • 5
  • c

    crummy

    04/07/2020, 1:34 AM
    This is only ktor-adjacent, but I'm looking at ktor's application.conf setup and would like to re-use this functionality for my own configuration classes. I've discovered I can call
    HoconApplicationConfig(ConfigFactory.load()).property("apiKey")
    , but this gets cumbersome - is there a way to define a class (or data class) and have its values automatically instantiated from application.conf values?
    • 1
    • 1
  • m

    Mark Gilchrist

    04/07/2020, 5:00 PM
    hey is there a prefered/recommended library to use for sending emails?
    ➕ 1
    r
    • 2
    • 5
  • h

    hdarritchon

    04/07/2020, 11:54 PM
    Hi, I’m trying to handle a response from a ReST API with Ktor Client. This API has several types of response depending if it is a success or an error. I’m trying to handle this with a Sealed class. But I fail to do it. I tried using Gson/Jackson and Json. I saw the polymorphic (https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/polymorphism.md) documentation but I have an issue because one of the attributes of the API is ‘type’ and it’s the classDiscriminator by default and I tried to change it with JsonConfiguration but with no success. I am quite stuck. Any help doing this ? Do you a tutorial, some information ? Thanks. If it is needed I can give access to the code in github (https://github.com/herveDarritchon/icndb). Everything is in the Application.kt file (https://raw.githubusercontent.com/herveDarritchon/icndb/master/src/Application.kt)
    j
    • 2
    • 1
  • m

    Magno Junior

    04/08/2020, 9:36 AM
    hello ladies and gentlemen, what do you suggest for validations? I am checking this one: https://github.com/valiktor/valiktor/releases/tag/0.11.0 (@rodolpho.couto thanks). There is also the hibernate validation, but it is not exactly what I am looking for... but I would like to know what else people are using.
    👍 1
    j
    • 2
    • 4
  • b

    bitkid

    04/08/2020, 5:24 PM
    hey! i have a question about oauth2. i basically used the code here https://ktor.io/servers/features/authentication/oauth.html . what happens when i pass a invalid scope (just an example) i basically create an endless loop. the callback tries to send an error reponse back to the /oauth endpoint, the endpoint sees "not authenticated" redirects back to my oauth provider it tries to send the error response .. any ideas how to fix it?
    • 1
    • 2
  • j

    John Peña

    04/09/2020, 8:28 PM
    it does actually appear this would be the problem as we're using the netty engine and the trace ID is set in a thread local
    f
    • 2
    • 1
  • t

    Timur Atakishiev

    04/10/2020, 4:49 AM
    Hi guys, I have a question regarding Roting feature. I am new in ktor, and trying to use different approaches, for instance for every individual entity I have separate package for controller, service etc.. And I am registrating every controller in my RoutingModule like thils
    fun Application.routingModule() {
        val courtEndpoint by KodeinModule.kodein.instance<CourtEndpointImpl>()
        val userEndpoint by KodeinModule.kodein.instance<UserEndpointImpl>()
        val registrationEndpoint by KodeinModule.kodein.instance<RegistrationEndpointImpl>()
        val companyEndpoint by KodeinModule.kodein.instance<CompanyEndpointImpl>()
        val matchEndpoint by KodeinModule.kodein.instance<MatchEndpointImpl>()
    
        install(Routing) {
            court(courtEndpoint)
            user(userEndpoint)
            registration(registrationEndpoint)
            company(companyEndpoint)
            match(matchEndpoint)
        }
    }
    Lets say I will have a lot of entities which means I will registrate every routing in that module and I think it will be look not clear as it could be. Is it any approach, to avoid the situation with registration my routes in install section? Thank you
    h
    • 2
    • 1
  • t

    Timur Atakishiev

    04/10/2020, 8:34 AM
    Is it any good tutorial on cookie session authentication that really works?
    h
    • 2
    • 1
  • i

    imvtr

    04/11/2020, 1:09 AM
    Hello Guys, how are you? I'm trying ktor as my api framework for a persona project. Can i use more than one module on application? I want to split responsabilities
    h
    • 2
    • 1
Powered by Linen
Title
i

imvtr

04/11/2020, 1:09 AM
Hello Guys, how are you? I'm trying ktor as my api framework for a persona project. Can i use more than one module on application? I want to split responsabilities
h

hhariri

04/12/2020, 7:59 PM
Yes. You can use as many modules as you like.
View count: 4