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
  • c

    cvmocanu

    09/21/2018, 12:31 PM
    Hello, I'm trying to convert a servlet-api filter to ktor. The relevant code is:
    if (AngularForwardingSelector.shouldForward(requestURI)) {
                val requestDispatcher = request.getRequestDispatcher(forwardToUrl)
                requestDispatcher.forward(request, response)
            } else {
                chain.doFilter(request, response)
            }
    Trying the conversion, I have 2 questions: - does ktor have around intercerptors? If not, is there a way to stop pipeline from continuing in a before interceptor? - does kotlin have something similar to request dispatcher (for internal forwarding)? I tried looking into interceptors, but the documentation is slim, and I can't figure it out how to make it work.
    o
    • 2
    • 7
  • h

    Hamza

    09/22/2018, 5:56 AM
    hi, can someone help me understand how web sockets work?
    o
    • 2
    • 11
  • r

    rharter

    09/22/2018, 8:19 PM
    This is probably a silly question, but just to make sure I'm not missing something, the library is pronounced Kay-Tor, right? Just want to make sure it's not something like c'tor
    j
    o
    • 3
    • 7
  • o

    oshai

    09/22/2018, 9:09 PM
    Is there a reason netty dependency is
    4.1.24
    ? latest is
    4.1.29
    o
    • 2
    • 11
  • c

    cvmocanu

    09/23/2018, 12:07 PM
    Is it true that ``call.receive`` doesn't work with generics because of erasure? I have trouble with this:
    call.receive<List<Variable>>
    It looks like the JacksonConverter ends up doing something like ``objectmapper.readValue(reader, List::class.java)``, which will obviously won't work. It my suspicions are true, this is a big design issue in the Ktor API. Jackson accepts a ``TypeReference`` instead of a ``Class`` precisely to suport this use case. I guess my question is what are my options? - writing my own converter is impossible, since I can't pass a TypeReference to call.receive - changing the REST API is unacceptable Is reading the request body as String and using Jackson manually my only option?
    o
    n
    +3
    • 6
    • 14
  • v

    vngantk

    09/23/2018, 12:23 PM
    I am new to Ktor. Does Ktor support Kotlin JS for client?
    e
    s
    e
    • 4
    • 6
  • n

    Nikky

    09/23/2018, 1:24 PM
    so sktor-client-cio was buggy, okHttp works better, except now apparently my application never leaves the main coroutine scope at the end
    e
    u
    • 3
    • 4
  • a

    AdrianTodt

    09/23/2018, 9:13 PM
    any better way to require a session to be present than this?
    get("/") { _ ->
        val session = call.sessions.get<DashSession>() ?: return@get call.respondRedirect("/login")
        /* code */
    }
    📝 1
    ✅ 1
    d
    • 2
    • 1
  • o

    octylFractal

    09/23/2018, 9:40 PM
    another option: you might be able to extract that to an extension method on
    ApplicationCall
    and use that:
    fun ApplicationCall.requireSession(): DashSession? {
      val session = sessions.get<DashSession>()
      if (session == null) respondRedirect("/login")
      return session
    }
    use it like this:
    val session = call.requireSession() ?: return@get
    d
    • 2
    • 1
  • n

    Nikky

    09/25/2018, 9:37 PM
    i tried for the last few hours with ktor-client and apache engine but this file is just having
    [
    and
    ]
    in the redirects, making apache httpclient itself barf and trying to handle itmyself by encoding the characters in a RedirectFeature seems to only result in double encoding of the url and gets me a error xml
    <https://files.forgecdn.net/files/2574/880/BiblioCraft[v2.4.5][MC1.12.2].jar>
    e
    • 2
    • 3
  • h

    Hamza

    09/26/2018, 2:45 AM
    im following the sample on websockets (https://github.com/ktorio/ktor-samples/blob/master/app/chat/src/ChatApplication.kt) and there is this code block:
    intercept(ApplicationCallPipeline.Features) {
                if (call.sessions.get<ChatSession>() == null) {
                    call.sessions.set(ChatSession(nextNonce()))
                }
            }
    although, the class?
    ApplicationCallPipeline.Features
    is not found (But
    ApplicationCallPipeline
    is. I am lead to believe that i am missing some dependency which contains this, but i am not entirely sure which one. here are my ependencies:
    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
        compile "io.ktor:ktor-server-netty:$ktor_version"
        compile "ch.qos.logback:logback-classic:$logback_version"
        compile "io.ktor:ktor-server-core:$ktor_version"
        compile "io.ktor:ktor-server-host-common:$ktor_version"
        compile "io.ktor:ktor-websockets:$ktor_version"
        compile "io.ktor:ktor-jackson:$ktor_version"
    o
    • 2
    • 8
  • k

    kluck

    09/26/2018, 1:06 PM
    Hi, I'm having trouble with https and my CSS: I basically used what's shown in kotr-samples
    head {
        styleLink(url(MainCss))
    }
    And for my style definition:
    @Location("/styles/main.css")
    object MainCss
    
    fun Route.styles() {
        get<MainCss> {
            call.respond(call.resolveResource("app.css")!!)
        }
    }
    This works correctly without SSL, but when I start using https, the browser wouldn't load my css, as it's presented using basic http (here's my response):
    <head>
        <link rel="Stylesheet" type="text/css" href="<http://my.domain.com/styles/main.css>">
    </head>
    Any idea what I should modify to make it https friendly?
    c
    d
    • 3
    • 6
  • g

    gotoOla

    09/26/2018, 1:48 PM
    Hey! Running into a silly problem. I want to set the Content-Type to application/json but I don’t want to use the serialization of jackson or gson. When I set the content-type in the request itself I get a UnsafeHeaderException and it states that it should be set from the engine
    d
    • 2
    • 12
  • r

    rocketraman

    09/27/2018, 4:27 PM
    I guess ktor is not compatible with coroutines 0.27.0?
    Exception in thread "main" java.lang.NoSuchMethodError: kotlinx.coroutines.experimental.ExecutorsKt.asCoroutineDispatcher(Ljava/util/concurrent/Executor;)Lkotlinx/coroutines/experimental/CoroutineDispatcher;
    in
    JettyApplicationEngine:kt.13
    d
    e
    e
    • 4
    • 8
  • d

    Dias

    09/27/2018, 9:23 PM
    Hiya, 2 beginner questions: 1. What’s the best way to run ktor server in production? I just need simple microservice running in docker in kubernetes. Do I just use embeddedServer() ? I don’t really know the difference between embedded vs non-embedded server, I missed whole “java ee embedded tomcat” thing and don’t know what “embedded” is supposed to mean. I am asking this question mainly because almost all ktor samples are starting engines directly without calling embeddedServer(). 2. I expected easy way of reading .conf files, I thought that they automagically would load up to some global config file, but it doesn’t seem to be the case. How was it intended to use and load .conf files?
    d
    m
    • 3
    • 10
  • d

    Dias

    09/27/2018, 9:24 PM
    (I read all of ktor.io, but many things are not clear to me still)
    d
    • 2
    • 3
  • d

    Dias

    09/28/2018, 5:54 PM
    or even from within ktor application, what should I consider when choosing server engine?
    o
    d
    • 3
    • 3
  • h

    Hullaballoonatic

    09/28/2018, 11:45 PM
    so i'm designing a writing a server application essentially purely to connect clients to a database. what ktor guide or example project is the best reference?
    o
    b
    m
    • 4
    • 4
  • z

    ZargorNET

    09/30/2018, 6:47 PM
    Hey. I'm new to Kotlin and Ktor. I'm trying to get my uploading function to work but it reads only the first 4096 bytes. I can't figure out what I'm doing wrong and Google doesn't help too. My code:
    val bytes = ByteArrayOutputStream()
    val multipart = call.receiveMultipart()
    multipart.forEachPart { part ->
         if (part is PartData.FileItem) {
              val stream = part.streamProvider()
              var data = stream.read()
              while (data != -1) {
                   bytes.write(data)
                   data = stream.read()
             }
             stream.close()
         }
         part.dispose()
    }
    e
    • 2
    • 5
  • j

    jvassbo

    10/01/2018, 10:47 AM
    How do one use the HttpClient MockEngine when JsonFeature is expected on the engine? Is there any way without having to do the (de)serializing manually? See example failing test. (On Ktor 0.9.4)
    -.kt
    e
    • 2
    • 12
  • m

    Marc Knaup

    10/01/2018, 9:45 PM
    But I could just offload the CPU bound work to a background thread and prevent the OTHER coroutines from being blocked, couldn't I?
    e
    • 2
    • 6
  • m

    mp

    10/01/2018, 10:12 PM
    (Intellij’s new built in profiler may be useful — I initially dismissed having it built in because there are so many profilers already, right? Wrong; it’s great having it always 1 click away.)
    👍 1
    m
    • 2
    • 4
  • m

    mp

    10/02/2018, 3:50 PM
    How long should I expect ktor's tests to run for? I'm just running
    ./gradlew check
    and it looks suspiciously like they're stuck. Does it maybe not support parallel builds? CPUs are idle, test counts aren't ticking upwards 🤔
    h
    s
    e
    • 4
    • 17
  • o

    otakusenpai

    10/04/2018, 12:31 AM
    Hello guys, After upgrading the ktor version in my project to 0.9.5 from 0.9.2, I am having dependency problems in intellij about ktor. Going through the Raw Sockets section in the docs doesnt help much more than stating to add io.ktor.ktor-network to the dependencies, hrough i didnt check the examples. Can you tell me which dependencies to include for version 0.9.5? My code is included in a text file.
    m
    • 2
    • 17
  • o

    otakusenpai

    10/04/2018, 2:31 AM
    Is it even possible to read ASCII data from ktor raw sockets?
    • 1
    • 2
  • o

    otakusenpai

    10/04/2018, 6:46 AM
    Can anyone please help me with my issue?
    h
    • 2
    • 1
  • m

    mp

    10/04/2018, 10:58 AM
    Sure, the new CallId support might tie in nicely to opentracing. Either way, that still leaves the question of how best to wrangle contexts, etc
    f
    • 2
    • 4
  • b

    bdawg.io

    10/05/2018, 4:13 AM
    There's no more
    experimental
    in the package name. If you've successfully migrated off of the deprecated APIs available in the latest coroutines release, it'll just be a dependency update, removal of enabling coroutines as experimental in your Gradle project, and migrating off of the
    experimental
    path
    h
    • 2
    • 1
  • y

    yatsinar

    10/05/2018, 2:31 PM
    • 1
    • 2
  • j

    jkbbwr

    10/06/2018, 3:35 AM
    So the two things im missing before im sold on ktor is the ability to do work after the request has finished. And SSE
    e
    d
    • 3
    • 4
Powered by Linen
Title
j

jkbbwr

10/06/2018, 3:35 AM
So the two things im missing before im sold on ktor is the ability to do work after the request has finished. And SSE
e

elizarov

10/06/2018, 4:26 AM
GlobalScope.launch { ... }
gives you that and SSE is trivial to implement.
j

jkbbwr

10/06/2018, 5:49 AM
Im assuming globalscope.launch is the context for coroutines, and im assuming that I could hold a coroutine channel inside an sse handler and feed it data?
e

elizarov

10/06/2018, 7:35 AM
To implement SSE you don’t let let request terminate. You keep responding indefinitely.
d

Deactivated User

10/08/2018, 11:11 AM
You can implement SSE like this, though websockets are more widely used and supported: https://github.com/ktorio/ktor-samples/blob/e9bbc563fa9bda5fda9f1fb1c41b20bb85beea70/other/sse/src/SseApplication.kt
➕ 1
View count: 6