https://kotlinlang.org logo
#ktor
Title
# ktor
j

Jørund Amsen

11/22/2019, 11:28 AM
So I'm trying to adapt some javax.servlet.Filter to be used in a interceptor. However it uses thing such as ServletRequest/Response. Are these available somehow? Or does ktor build on someting different?
c

cy

11/22/2019, 11:30 AM
It is available but not recommended because you loose portability
j

Jørund Amsen

11/22/2019, 11:31 AM
Yeah, I was afraid of that. Are there any known ways to work with javax Filters?
c

cy

11/22/2019, 11:31 AM
(call.request as ServletApplicationRequest).servletRequest
same for response
What filter do you need to adopt?
j

Jørund Amsen

11/22/2019, 11:32 AM
In this case it's an internally made logging and access filter. We've mostly used Spring for now, and a lot of former work would be unusable with Ktor
c

cy

11/22/2019, 11:32 AM
Ah, may be it is slightly more difficult because of routing...
j

Jørund Amsen

11/22/2019, 11:32 AM
How so?
c

cy

11/22/2019, 11:36 AM
Right, routing wraps application calls to provide
route
property so the original call is hidden
However, it you intercept before routing, the code above should work well. Otherwise, you need more tricks
j

Jørund Amsen

11/22/2019, 11:38 AM
Yeah, that was my intention at least. I'll see if I can get it to work. Still way out on a limb when it comes to my understanding of Ktor. Thanks for the quick respons!
c

cy

11/22/2019, 11:38 AM
The idea is to hide the underlying engine details, so you can run your app on any engine
j

Jørund Amsen

11/22/2019, 11:38 AM
Oh, one more thing, while I have you here, heh. https://kotlinlang.slack.com/archives/C0A974TJ9/p1573808069261300 Could I possibly open an issue on this? Multiple connectors support, that is
c

cy

11/22/2019, 11:39 AM
for example, run on netty locally and deploy as war to Tomcat for prod
j

Jørund Amsen

11/22/2019, 11:39 AM
Yeah, that makes sense..
But are these servlet-classes engine-spesific?
c

cy

11/22/2019, 11:40 AM
Yes, of course
This is why you need to cast to adopt to javax.servlet
j

Jørund Amsen

11/22/2019, 11:40 AM
Oh shit, yeah I just checked the inheritance. My bad
c

cy

11/22/2019, 11:40 AM
You don't have these classes with no ktor-server-servlet dependency
j

Jørund Amsen

11/22/2019, 11:41 AM
Thanks, that actually clears things up a lot
c

cy

11/22/2019, 11:42 AM
Regarding connectors.. I see no reason for not supporting multiple connectors in config. We just provided two for plain and TLS/SSL since it is the most useful case
j

Jørund Amsen

11/22/2019, 11:43 AM
I don't mind attempting a PR or issue, whatever is best for you. Is there anything in particular I should consider?
c

cy

11/22/2019, 11:44 AM
If you think of PR, a change should be backward-compatible so older configuration files should keep working
j

Jørund Amsen

11/22/2019, 11:45 AM
Yep. Would a "unlimited" amount of connectors be allowed, or are there specific types of connectors, similar to TLS(or metrics?) that should be allowed?
c

cy

11/22/2019, 12:00 PM
There is no limit, only two kinds are supported: pure HTTP and HTTPS
j

Jørund Amsen

11/22/2019, 12:00 PM
Yeah, it was more a question of "a metrics port", or "however many more ports you want"
c

cy

11/22/2019, 12:02 PM
Of course you may configure a dedicated connector for the specific purpose such as administration
However, you need to configure your routing to filter by port, otherwise all ports will behave the same
j

Jørund Amsen

11/22/2019, 12:04 PM
Yep, I kind of already adapted the EngineMain in our app to do something similar. From what I understand, the port under
deployment{}
seems to be the default if I don't use any
port(){}
Is that correct?
c

cy

11/22/2019, 12:09 PM
This is no longer true. Either port or sslPort should be specified
j

Jørund Amsen

11/22/2019, 12:09 PM
Oh, is this a recent change?
Oh, no I mean
When I just do a normal routing
Similar to...
Copy code
fun Routing.metrics() {
    port(8181) {
        get("/prometheus") {
            call.respondText { prometheusMeterRegistry.scrape() }
        }
    }
In this case, I spesify the port. However, if I don't spesify the port here, it defaults to the port in
Copy code
deployment {
    port = 8080
}
So it seems there is a "default" connector, however many connectors I have
Does that make sense?
c

cy

11/22/2019, 12:12 PM
These are irrelevant. The
port
function just adds a filter node
If no
port()
in routing then no filter applied so all ports are handled
j

Jørund Amsen

11/22/2019, 12:13 PM
Aaaah, okay yeah that makes a lot more sense
Thanks for being awesome Sergey! 😄 Keep rocking
c

cy

11/22/2019, 12:13 PM
irrelevant -> independent
So, if one deploy into a servlet container, you can't control connectors at all
j

Jørund Amsen

11/22/2019, 12:14 PM
Yeah
c

cy

11/22/2019, 12:14 PM
but you can add port routing anyway
j

Jørund Amsen

11/22/2019, 12:14 PM
That makes sense
c

cy

11/22/2019, 12:15 PM
So, a routing is a decision tree. Every node of that tree may have a predicate
So when a call is started, it comes though the pipeline, then a routing is called (if installed, it's actually optional). If routing finds a node that matches, the corresponding handler is invoked
j

Jørund Amsen

11/22/2019, 12:20 PM
I see
11 Views