https://kotlinlang.org logo
#javalin
Title
# javalin
r

Robert Jaros

02/25/2020, 1:54 PM
wsBefore
gives access to a
WsHandler
object, but it doesn't have attributes (like
Context
available in
before
). Is there any way to create an interceptor/filter for websockets and pass custom data to websocket handlers (preferably to just put an attribute to
WsContext
)?
d

david-wg2

02/25/2020, 2:03 PM
i don’t think so, jetty destroys the original request pretty fast
you’ll have to make your own map to keep track of it, i think 🤔
r

Robert Jaros

02/25/2020, 2:12 PM
Can I define two
onConnect
handlers? Will both run? In the same order? Will both work on the same
WsContext
?
Copy code
app.wsBefore { ws ->
        ws.onConnect { ctx ->
            ctx.attribute("key", "testValue")
        }
    }
    <http://app.ws|app.ws>("/path") { ws ->
        ws.onConnect { ctx ->
            val v = ctx.attribute<String>("key")
            // will this work ?
        }
    }
d

david-wg2

02/25/2020, 2:21 PM
this will most likely work, but
onConnect
in a
wsBefore
and
onMessage
in a
ws
might not (since Jetty has probably killed the upgrade-request by then)
r

Robert Jaros

02/25/2020, 2:24 PM
I'm testing this now. onConnect should be enough for me.
Is
WsHandler
instance shared by all clients?
I see it is
Ok, I've managed to make it work Thx for help
t

tipsy

02/25/2020, 10:27 PM
Is
WsHandler
instance shared by all clients?
that's a strange way of thinking about
it's a bit like asking if a
Handler
in `get("/") { ... }`` is shared by all request to
/
there's no shared state between clients
7 Views