https://kotlinlang.org logo
Docs
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
  • s

    S.

    03/29/2022, 6:48 PM
    what exactly does call.respond() do? does it end the current pipeline or should I use it with an explicit return call?
    a
    • 2
    • 8
  • s

    Sebastien Leclerc Lavallee

    03/29/2022, 10:08 PM
    Hey guys! I’m currently developing an API using Ktor and I need to inspect all incoming call for a specific header and return a HTTP 400 error if it’s not present. My understanding is that I could use an intercept for that purpose but I’m a bit confused where I should define and use it. This is how my project is setup:
    fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
    
    fun Application.module() {
      registerRoutes()
    }
    
    fun Application.registerRoutes() {
      routing {
        route("/") {
          get {
            call.respondText("Hello world!")
          }
        }
      }
    }
    What would be the best way? Where should I put it? Thanks!
    a
    • 2
    • 2
  • h

    Hexa

    03/29/2022, 10:41 PM
    Anyone got example of intercepting outgoing Http client request before it is sent out?
    a
    • 2
    • 1
  • j

    James Black

    03/30/2022, 1:22 AM
    I am using this version of ktor: 2.0.0-beta-1 and I don't understand how to solve this. Basically, my iOS app calls a shared view model in Kotlin which then calls a repository and that goes to my api. Nothing comes back from the call, but the exact same repository call and api call are made from my Android application and it works fine. It appears it might be a problem where it can't make an SSL connection to the backend, but how could that be wrong? HttpClient: REQUEST: https://mycompany/auth/login HttpClient: METHOD: HttpMethod(value=POST) 2022-03-29 20:03:43.811964-0500 iosApp[62440:11389473] [ServicesDaemonManager] interruptionHandler is called. -[FontServicesDaemonManager connection]_block_invoke 2022-03-29 20:07:41.407923-0500 iosApp[62440:11394220] [boringssl] boringssl_metrics_log_metric_block_invoke(151) Failed to log metrics 2022-03-29 20:07:41.425475-0500 iosApp[62440:11394116] Connection 1: received failure notification 2022-03-29 20:07:41.425979-0500 iosApp[62440:11394116] Connection 1: failed to connect 3:-9816, reason -1 2022-03-29 20:07:41.426024-0500 iosApp[62440:11394116] Connection 1: encountered error(3:-9816) 2022-03-29 20:07:41.428298-0500 iosApp[62440:11394116] Task <484C8CA5-611F-489B-AC11-8FCA4A7EBC66>.<1> HTTP load failed, 0/0 bytes (error code: -1200 [3:-9816])
    • 1
    • 1
  • t

    tim

    03/31/2022, 9:11 AM
    Has anyone encountered an issue using ktor-server:2.0.0-beta-1's CallLogging plugin on Linux? Essentially the jvm crashes when CallLogging calls `AnsiConsole.systemInstall()`(link). I think the issue might be related to https://github.com/fusesource/jansi/issues/204 (fixed in jansi 2.4.0) but haven't had a change to test yet. Current workaround is to just disable the call logging plugin on linux.
    e
    a
    • 3
    • 4
  • f

    functionaldude

    03/31/2022, 3:17 PM
    Hi! I’m encountering a very strange behaviour when using the Ktor JS client with
    JsonFeature
    . I have the following class structure:
    @Serializable
    sealed class Base {
    
      @Serializable
      class Child: Base()
    }
    When I do a post request with
    Child()
    as body, the class discriminator is missing (the body is just
    {}
    ). I figured out that `Child`’s serializer is used, if I use `Base`’s serializer then the class discriminator is there:
    val payload = Base.Child()
      val payloadString1 = kotlinxSerializer.encodeToString(Base.serializer(), payload) // payloadString1 = "{"@class": "com.example.Base.Child"}"
      val payloadString2 = kotlinxSerializer.encodeToString(Base.Child.serializer(), payload) // payloadString2 = "{}"
    The problem is, I can’t find a way to force the Ktor client to use the sealed class’s serializer. Is this a bug or the intended behaviour? And if this is the intended behaviour then how can I tell the Ktor client to use a different serializer?
    a
    n
    • 3
    • 2
  • p

    Pavel Petkevich

    04/01/2022, 7:28 AM
    Hi! Hopefully someone from you is already faced with ACL on the Ktor, unfortunately I wasn't be able to find ACL/roles control by Ktor out of the box. Some recommendations/tricks for ACL? 😄 Thx in advance 😉 PS: this old ticket on #ktor-github (https://github.com/ktorio/ktor/issues/807) I found, but maybe already exist some better way..
    h
    t
    • 3
    • 6
  • m

    Michal Klimczak

    04/02/2022, 8:05 PM
    I can't inject my class with koin when using ktor in development mode. (2.0.0-beta-1)
    routing {
            val service by KoinJavaComponent.inject<PageService>(PageService::class.java)
    ...
    Exception:
    class com.xyz.PageService cannot be cast to class com.xyz.PageService (com.xyz.PageService is in unnamed module of loader 'app'; com.xyz.PageService is in unnamed module of loader io.ktor.server.engine.OverridingClassLoader$ChildURLClassLoader @55a88417)
    Also it's injected fine at app startup, but fails with this exception when it's done in the
    routing
    lambda. Works fine when I disable development mode, too. Any ideas?
    s
    • 2
    • 2
  • s

    ste

    04/03/2022, 7:32 PM
    Hi, is there an update regarding
    br
    (Brotli) support in
    ktor-client-encoding
    ? The only thing I could find is https://github.com/ktorio/ktor/issues/408, but this is closed and the YouTrack link is broken
    a
    • 2
    • 6
  • f

    Filip Lastic

    04/04/2022, 7:43 AM
    Hello. I have question about integration-testing of ktor server. We have bigger ktor application which startup takes some time. For now, we use
    withTestApplication {}
    in our integration tests, but this causes that server has to start with each test. We started to have some performance issues, where test is executed in milliseconds, but server is starting for long time.. Do you have some experiences with starting server programatically, for example from
    gradle
    before running all tests? I found this solution https://stackoverflow.com/a/61246720 But not sure if it is correct approach.
    a
    • 2
    • 14
  • r

    Robert Jaros

    04/04/2022, 12:49 PM
    Is Ktor 1.6.8 compatible with Kotlin 1.6.20 ?
    e
    t
    j
    • 4
    • 3
  • s

    S.

    04/04/2022, 6:19 PM
    how do you test endpoints that return status codes like
    NotFound
    or
    BadRequest
    since they throw
    io.ktor.client.plugins.ClientRequestException
    ? so this below doesn't work, only way is to do the checks on the exception's message it seems
    val response = client.get("api/v1/words/x")
    response shouldHaveStatus HttpStatusCode.BadRequest
    response.bodyAsText() shouldBe INVALID_ID
    a
    • 2
    • 3
  • d

    dave08

    04/05/2022, 6:34 AM
    Wasn't Ktor 2 supposed to be released along with 1.6.20? Should we start migrated production code to it?
    e
    • 2
    • 2
  • h

    harry248

    04/05/2022, 6:39 AM
    Anyone got Ktor Client (2.0.0-beta1) to force a result from http cache using an
    only-if-cached
    cache control header? Ktor always responds with status code 504 even if there is a non-stale result in cache.
    a
    • 2
    • 8
  • d

    dodalovic

    04/05/2022, 7:50 PM
    Hi, guys, I'm trying to write some tests, dealing with json, and kotlinx.serialization, and I need to do:
    setBody(
                        Json.encodeToString(
                            CreateUpdateCustomer(
                                name = "name",
                                street = "street",
                                houseNumber = "houseNumber",
                                zip = "zip",
                                place = "place",
                                countryCode = "DE",
                                email = "<mailto:some@email.com|some@email.com>",
                                invoiceLanguage = "EN",
                            )
                        )
                    )
    to be able to do json Shouldn't it be just
    setBody(
                        CreateUpdateCustomer(
                                name = "name",
                                street = "street",
                                houseNumber = "houseNumber",
                                zip = "zip",
                                place = "place",
                                countryCode = "DE",
                                email = "<mailto:some@email.com|some@email.com>",
                                invoiceLanguage = "EN",
                            )
                    )
    a
    • 2
    • 2
  • t

    Tobias Gronbach

    04/05/2022, 10:35 PM
    Hi, I just managed to deploy my ktor-server-app to heroku. After a lot of struggle it finally worked 🙃. One thing however is not working. I hope somebody can help. I use jwt for authorization. I followed exactly this guide https://ktor.io/docs/jwt.html using RS256 (public/private) key pair. Everything worked on localhost but on Heroku public key cannot be found. (More in Thread)
    a
    • 2
    • 2
  • m

    Martin Gaens

    04/05/2022, 11:24 PM
    Hey guys! I'm using Ktor with FreeMarker and Exposed and I'm having this slight technical difficulty when using FreeMarker. The Exposed library produces objects which have properties on properties (by using foreign key references to other tables). Here's an example:
    routing {
        get("/") {
            call.respond(
                FreeMarkerContent(
                    "index.ftl",
                    mapOf(
                        "apartments" to transaction { Apartment.all().toList() }
                    )
                 )
             )
        }
    }
    The transaction produces a
    List
    of `Apartment`s. Now, the problem is, that the
    Apartment
    object holds a property called
    Address
    but this property is from a different table. So, in order to access the `Address`' name, we have to call
    address.name
    . This is the FreeMarker code:
    <ol>
        <#list apartments as apartment>
            <li>${apartment.address.name} ${apartment.apartmentNumber} ${apartment.room}</li>
        </#list>
    </ol>
    And this is the error it produces:
    freemarker.core._TemplateModelException: An error has occurred when reading existing sub-variable "address"; see cause exception! The type of the containing value was: extended_hash+string (com.gitlab.djsushi.data.table.Apartment wrapped into f.e.b.StringModel)
    r
    • 2
    • 9
  • r

    ribesg

    04/06/2022, 11:46 AM
    Is there a “road to no longer experimental” task/issue I can follow for Ktor Locations?
    a
    d
    • 3
    • 6
  • j

    Jorge Bo

    04/06/2022, 4:16 PM
    Hi , i have created a custom serializer to deserialize httpClient.get<Map<String, Market>(url) calls and then register it under json. What i can't figure out is how to set the generic types to the contextual mapping. As it is right now it does not allows me to register other contextual serializers for Map class. Any idea?
    json {
    serializersModule = SerializersModule {
        contextual(Map::class) { MarketMapSerializer }
    }
    }
    
    object MarketMapSerializer :
        JsonTransformingSerializer<Map<String, Market>>(MapSerializer(String.serializer(), Market.serializer())) {
        override fun transformDeserialize(element: JsonElement): JsonElement {
            return JsonObject(element.jsonObject.filterNot { (k, _) ->
                k == "token"
            })
        }
    }
    a
    • 2
    • 3
  • t

    Todd

    04/06/2022, 9:34 PM
    Does anyone know if there is a way to have a ktor client that has some base configuration/plugins and then use the same underlying client but apply different configurations on top of this? Essentially I want to be able to use the same client in order to not spin up new threads, but I want slightly different configurations depending on the endpoints I’m hitting.
    s
    a
    • 3
    • 2
  • s

    sendoav

    04/07/2022, 8:52 PM
    Hi all! I'm using Ktor in a KMM project. I have a singleton HttpClient and singleton HttpClientEngine for that client. Calls from Android side goes well but in the iOS side after making any request with that client the connection seems to be closed automatically, the server tells me that the client has sent a TCP FIN packet, but I'm not closing anything, at least not intentionally. The complete message from the server is "Connection id "0HMGOM971DIK1" sending FIN because: "The client closed the connection.". Do I need to configure anything in the iOS engine?
    c
    a
    • 3
    • 6
  • j

    James Black

    04/08/2022, 5:15 AM
    Unable to start a ktor server with this error. Exception in thread "main" io.ktor.server.engine.internal.ReloadingException: Module function cannot be found for the fully qualified name 'com.blackfox.myoutfitpicker.ApplicationKt.module' at io.ktor.server.engine.internal.CallableUtilsKt.executeModuleFunction(CallableUtils.kt:27) I am following the instructions at https://ktor.io/docs/eap/creating-http-apis.html#order_routes
    import io.ktor.server.application.*
    import com.blackfox.myoutfitpicker.plugins.configureRouting
    import com.blackfox.myoutfitpicker.plugins.configureSerialization
    
    fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
    
    fun Application.module() {
        configureRouting()
        configureSerialization()
    }
    I have no idea what I am doing wrong.
    s
    a
    • 3
    • 5
  • t

    Timur Atakishiev

    04/08/2022, 6:39 AM
    Hello guys, I have a question regarding exception handling in ktor. As some of you know to handle REST exception, we generally use @ControllerAdvice and @ExceptionHandler in Spring MVC but these handler works if the request is handled by the DispatcherServlet. However, security-related exceptions occur before that as it is thrown by Filters. How does the exception handler work in ktor? Is it a single point exception handler
    try{
       smth
    } catch(Throwable t) {
       smth
    }
    that handles everything or it should be done separately for each case like in the spring security? Thanks
    a
    • 2
    • 2
  • h

    hhariri

    04/08/2022, 8:27 AM
    Ktor 2.0.0 RC1 released. Actual release to follow soon
    ❤️ 1
    🎉 26
    h
    a
    +3
    • 6
    • 8
  • d

    Dirk

    04/08/2022, 12:47 PM
    Hi all, I have a problem reading a cookie with the Ktor JS client. On the server side (also Ktor 2.0Beta1) a session is created, which should be stored in a cookie on the client side. My problem now is that I can't access the session cookie from the Ktor client. In the following code, the cookie is not accessible in the header or with the specialized function, although I can see in the browser's developer console that the server sends the cookie along in the header. The web page with the client comes from localhost:8080 and the query with the cookie is about the server localhost:9012 - that shouldn't be a problem or should it. Where is my error?
    val clientTopic = HttpClient {
        install(Logging)
        install(ContentNegotiation) {
            json()
        }
        install(HttpCookies) {
            storage = AcceptAllCookiesStorage() // default
        }
    
        defaultRequest {
            ...
        }
    }
    ....
            val response = clientTopic.get(href(ResourcesFormat(), ApiTopicMS.Topic.V1.Laden(onlineLinkID = onlineLinkID)))
    
            when (response.status) {
                HttpStatusCode.OK -> {
                    <http://console.info|console.info>("Cookies from server: ${response.setCookie()}")
                    val setCookieHeader = response.headers["Set-Cookie"]
                    <http://console.info|console.info>("Cookie from header: $setCookieHeader")
                    <http://console.info|console.info>(response.headers.names())
                    response.headers.forEach { s, strings ->
                        <http://console.info|console.info>("s: $strings")
                    }
                    response.body<TopicDTO>()
                }
                else -> {
                    console.error("Topic konnte nicht geladen werden. Status: ${response.status}")
                    null
                }
            }
    a
    • 2
    • 2
  • b

    brabo-hi

    04/08/2022, 2:13 PM
    Could not find io.ktor:ktor-serialization-kotlinx-json:2.0.0-RC.1
    a
    • 2
    • 8
  • j

    John O'Reilly

    04/08/2022, 4:00 PM
    Getting following build error for Compose for Web and Kotlin/JS modules after updating to
    2.0.0-rc-1
    - full stack trace in https://github.com/joreilly/PeopleInSpace/runs/5887877881?check_suite_focus=true
    IllegalArgumentException: Sequence has more than one element
    :plus1: 1
    k
    h
    • 3
    • 4
  • n

    Nathan Kleinschmidt

    04/09/2022, 7:50 PM
    Question about responses and serialization: I have this sealed class, and it contains success and error responses as member classes. Each inherit from from the base Response class:
    @Serializable
    sealed class Response(
     @Contextual
     val statusCode: HttpStatusCode = HttpStatusCode.OK
    ) {
     @Serializable
     data class SuccessResponse<T>(
      val data : T? = null,
      val message : String? = null
     ) : Response()
    
     @Serializable
     data class ErrorResponse<T>(
      val exception : T? = null,
      val message : String? = null
     ) : Response()
    }
    However it fails to serialize and I get runtime errors. If I attempt to convert the response to Json using
    call.respond(statusCode, Json.encodeToString(result))
    then I get:
    kotlinx.serialization.SerializationException: Class 'String' is not registered for polymorphic serialization in the scope of 'Any'.
    Mark the base class as 'sealed' or register the serializer explicitly.
    If I don’t and just attempt to call
    call.respond(statusCode, result)
    , then I get this error instead:
    kotlinx.serialization.SerializationException: Serializer for class 'ErrorResponse' is not found.
    Mark the class as @Serializable or provide the serializer explicitly.
    Not sure if this is an issue with how I am using serialization, or if this is even the recommended way of dealing with responses?
    g
    • 2
    • 12
  • m

    Martin Gaens

    04/09/2022, 8:28 PM
    Hello, is there a way to disable the logs from Thymeleaf? There's way too much information coming into my logs from Thymeleaf anytime a HTML response is being rendered. Here's an example of the stuff I'd like to get rid of:
    2022-04-09 23:21:46.270 [eventLoopGroupProxy-4-1] TRACE o.t.s.expression.AdditionExpression - [THYMELEAF][eventLoopGroupProxy-4-1] Evaluating addition expression: "'table-select-' + ${iter.index}"
    2022-04-09 23:21:46.270 [eventLoopGroupProxy-4-1] TRACE o.t.s.e.TextLiteralExpression - [THYMELEAF][eventLoopGroupProxy-4-1] Evaluating text literal: "'table-select-'"
    2022-04-09 23:21:46.270 [eventLoopGroupProxy-4-1] TRACE o.t.s.expression.VariableExpression - [THYMELEAF][eventLoopGroupProxy-4-1] Evaluating variable expression: "${iter.index}"
    2022-04-09 23:21:46.270 [eventLoopGroupProxy-4-1] TRACE o.t.s.e.OGNLVariableExpressionEvaluator - [THYMELEAF][eventLoopGroupProxy-4-1] OGNL expression: evaluating expression "iter.index" on target
    2022-04-09 23:21:46.270 [eventLoopGroupProxy-4-1] TRACE o.t.T.cache.EXPRESSION_CACHE - [THYMELEAF][eventLoopGroupProxy-4-1][EXPRESSION_CACHE][CACHE_HIT] Cache hit in cache "EXPRESSION_CACHE" for key "ognlsc|org.thymeleaf.engine.IterationStatusVar|index".
    j
    • 2
    • 2
  • j

    James Black

    04/10/2022, 6:41 AM
    I am trying to call my server endpoints and I keep getting this, if I call "/", "/hello" with or without the accept header. What does it mean to make the bundle as not supporting multiuse? This is my version of Ktor: 2.0.0-beta-1
    curl -H "Accept: application/json" -v 0.0.0.0:8080/hello
    *  Trying 0.0.0.0:8080...
    * Connected to 0.0.0.0 (127.0.0.1) port 8080 (#0)
    > GET /hello HTTP/1.1
    > Host: 0.0.0.0:8080
    > User-Agent: curl/7.79.1
    > Accept: application/json
    > 
    * Mark bundle as not supporting multiuse
    < HTTP/1.1 404 Not Found
    < Content-Length: 0
    < 
    * Connection #0 to host 0.0.0.0 left intact
    when I start the server and the first line here is the last line, until I make the curl call then it outputs the rest of the lines:
    01:34:22.888 [DefaultDispatcher-worker-1] INFO Application - Responding at <http://0.0.0.0:8080>
    01:34:30.926 [eventLoopGroupProxy-3-1] DEBUG io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true
    01:34:30.929 [eventLoopGroupProxy-3-1] DEBUG io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true
    01:34:30.930 [eventLoopGroupProxy-3-1] DEBUG io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@2383b23
    01:34:31.007 [eventLoopGroupProxy-3-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096
    01:34:31.007 [eventLoopGroupProxy-3-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8
    01:34:31.007 [eventLoopGroupProxy-3-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.chunkSize: 32
    This is my Application set up and with or without serialization same error:
    fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
    
    fun Application.module() {
        configureRouting()
        configureStatusPages()
        configureCallLogging()
    //    configureSerialization()
    }
    Status pages I was hoping would get called but it doesn't, so the 404 I am not certain where it is coming from.
    fun Application.configureStatusPages() {
        install(StatusPages) {
            exception<Throwable> { call, cause ->
                if(cause is RuntimeException) {
                    call.respondText(text = "403: $cause" , status = HttpStatusCode.Forbidden)
                } else {
                    call.respondText(text = "500: $cause" , status = HttpStatusCode.InternalServerError)
                }
            }
            status(HttpStatusCode.NotFound) { call, status ->
                call.respondText(text = "404: Page Not Found", status = status)
            }
        }
    }
    I was hoping to see the logging requests but this doesn't seem to help:
    fun Application.configureCallLogging() {
        install(CallLogging) {
            level = <http://Level.INFO|Level.INFO>
            format { call ->
                val status = call.response.status()
                val httpMethod = call.request.httpMethod.value
                val userAgent = call.request.headers["User-Agent"]
                "Status: $status, HTTP method: $httpMethod, User agent: $userAgent"
            }
        }
    }
    And at the moment the routing is very simple:
    fun Application.configureRouting() {
        install(Routing) {
            routing {
                get("/") {
                    val uri = call.request.uri
                    call.respondText("Request uri: $uri")
                }
    
                get("/hello") {
                    call.respondText("Hello")
                }
                get("/weather") {
                    call.respondText("current weather")
                }
            }
        }
    }
    a
    • 2
    • 5
Powered by Linen
Title
j

James Black

04/10/2022, 6:41 AM
I am trying to call my server endpoints and I keep getting this, if I call "/", "/hello" with or without the accept header. What does it mean to make the bundle as not supporting multiuse? This is my version of Ktor: 2.0.0-beta-1
curl -H "Accept: application/json" -v 0.0.0.0:8080/hello
*  Trying 0.0.0.0:8080...
* Connected to 0.0.0.0 (127.0.0.1) port 8080 (#0)
> GET /hello HTTP/1.1
> Host: 0.0.0.0:8080
> User-Agent: curl/7.79.1
> Accept: application/json
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 404 Not Found
< Content-Length: 0
< 
* Connection #0 to host 0.0.0.0 left intact
when I start the server and the first line here is the last line, until I make the curl call then it outputs the rest of the lines:
01:34:22.888 [DefaultDispatcher-worker-1] INFO Application - Responding at <http://0.0.0.0:8080>
01:34:30.926 [eventLoopGroupProxy-3-1] DEBUG io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true
01:34:30.929 [eventLoopGroupProxy-3-1] DEBUG io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true
01:34:30.930 [eventLoopGroupProxy-3-1] DEBUG io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@2383b23
01:34:31.007 [eventLoopGroupProxy-3-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096
01:34:31.007 [eventLoopGroupProxy-3-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8
01:34:31.007 [eventLoopGroupProxy-3-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.chunkSize: 32
This is my Application set up and with or without serialization same error:
fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)

fun Application.module() {
    configureRouting()
    configureStatusPages()
    configureCallLogging()
//    configureSerialization()
}
Status pages I was hoping would get called but it doesn't, so the 404 I am not certain where it is coming from.
fun Application.configureStatusPages() {
    install(StatusPages) {
        exception<Throwable> { call, cause ->
            if(cause is RuntimeException) {
                call.respondText(text = "403: $cause" , status = HttpStatusCode.Forbidden)
            } else {
                call.respondText(text = "500: $cause" , status = HttpStatusCode.InternalServerError)
            }
        }
        status(HttpStatusCode.NotFound) { call, status ->
            call.respondText(text = "404: Page Not Found", status = status)
        }
    }
}
I was hoping to see the logging requests but this doesn't seem to help:
fun Application.configureCallLogging() {
    install(CallLogging) {
        level = <http://Level.INFO|Level.INFO>
        format { call ->
            val status = call.response.status()
            val httpMethod = call.request.httpMethod.value
            val userAgent = call.request.headers["User-Agent"]
            "Status: $status, HTTP method: $httpMethod, User agent: $userAgent"
        }
    }
}
And at the moment the routing is very simple:
fun Application.configureRouting() {
    install(Routing) {
        routing {
            get("/") {
                val uri = call.request.uri
                call.respondText("Request uri: $uri")
            }

            get("/hello") {
                call.respondText("Hello")
            }
            get("/weather") {
                call.respondText("current weather")
            }
        }
    }
}
a

Aleksei Tirman [JB]

04/10/2022, 10:35 AM
Could you please try to change a server port and make a request again? If this doesn’t help, please share your project to troubleshoot this issue.
j

James Black

04/10/2022, 8:22 PM
My server part of my project is at: https://github.com/jblack975/MyOutfitPicker/tree/master/server I changed it to this:
ktor {
    deployment {
        port = 8060
    }
    application {
        modules = [ com.blackfox.myoutfitpicker.ApplicationKt.module ]
    }
}
and I had this in the log, but I get the same error.
15:18:30.997 [DefaultDispatcher-worker-1] INFO Application - Responding at <http://0.0.0.0:8060>
15:18:38.588 [eventLoopGroupProxy-3-1] DEBUG io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true
This is the output:
curl -v 0.0.0.0:8060/   
*  Trying 0.0.0.0:8060...
* Connected to 0.0.0.0 (127.0.0.1) port 8060 (#0)
> GET / HTTP/1.1
> Host: 0.0.0.0:8060
> User-Agent: curl/7.79.1
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 404 Not Found
< Content-Length: 0
a

Aleksei Tirman [JB]

04/11/2022, 12:29 PM
When I run a server application I get the following compilation errors:
e: /Users/Aleksei.Tirman/projects/MyOutfitPicker/server/src/main/kotlin/com/blackfox/myoutfitpicker/plugins/Routing.kt: (4, 36): Unresolved reference: api
e: /Users/Aleksei.Tirman/projects/MyOutfitPicker/server/src/main/kotlin/com/blackfox/myoutfitpicker/plugins/Routing.kt: (36, 19): Unresolved reference: WeatherApi
e: /Users/Aleksei.Tirman/projects/MyOutfitPicker/server/src/main/kotlin/com/blackfox/myoutfitpicker/plugins/Routing.kt: (37, 9): Overload resolution ambiguity:
j

James Black

04/11/2022, 5:23 PM
I removed the parts that are causing an issue, as building the entire application may be problematic. I am staying on the beta1 version as when I briefly tried to switch to 2.0.0 it had an error and I would rather not troubleshoot that right now. If you want we can meet on google hangout and I can work with you to figure this out, as I am off this week so I can meet at any time. Thanks I no longer get the 404 but it also isn't returning what I expected.
* Trying 0.0.0.0:8080...
* Connected to 0.0.0.0 (127.0.0.1) port 8080 (#0)
> GET /hello HTTP/1.1
> Host: 0.0.0.0:8080
> User-Agent: curl/7.79.1
> Accept: application/json
> 
* Empty reply from server
This is now my router.
routing {
    get("/") {
        val uri = call.request.uri
        call.respondText("Request uri: $uri")
    }

    get("/hello") {
        call.respondText("Hello")
    }
    get("/weather") {
        call.respondText("current weather")
            //currentWeather()
    }
}
I changed to ktor 2.0.0 and changed my routing to get rid of the "routing {" element and now it works. Thanks
install(Routing) {
    get("/") {
        val uri = call.request.uri
        call.respondText("Request uri: $uri")
    }
View count: 5