So I'm trying to adapt some javax.servlet.Filter t...
# ktor
j
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
It is available but not recommended because you loose portability
j
Yeah, I was afraid of that. Are there any known ways to work with javax Filters?
c
(call.request as ServletApplicationRequest).servletRequest
same for response
What filter do you need to adopt?
j
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
Ah, may be it is slightly more difficult because of routing...
j
How so?
c
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
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
The idea is to hide the underlying engine details, so you can run your app on any engine
j
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
for example, run on netty locally and deploy as war to Tomcat for prod
j
Yeah, that makes sense..
But are these servlet-classes engine-spesific?
c
Yes, of course
This is why you need to cast to adopt to javax.servlet
j
Oh shit, yeah I just checked the inheritance. My bad
c
You don't have these classes with no ktor-server-servlet dependency
j
Thanks, that actually clears things up a lot
c
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
I don't mind attempting a PR or issue, whatever is best for you. Is there anything in particular I should consider?
c
If you think of PR, a change should be backward-compatible so older configuration files should keep working
j
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
There is no limit, only two kinds are supported: pure HTTP and HTTPS
j
Yeah, it was more a question of "a metrics port", or "however many more ports you want"
c
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
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
This is no longer true. Either port or sslPort should be specified
j
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
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
Aaaah, okay yeah that makes a lot more sense
Thanks for being awesome Sergey! 😄 Keep rocking
c
irrelevant -> independent
So, if one deploy into a servlet container, you can't control connectors at all
j
Yeah
c
but you can add port routing anyway
j
That makes sense
c
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
I see