Open wulf0r opened 4 years ago
Having looked more into this I now think that forwarding websocket from Tomcat to Ktor is simply not implemented.
In order to run Ktor in a servlet container the Servlet io.ktor.server.servlet.ServletApplicationEngine
which is a io.ktor.server.servlet.KtorServlet
creates the ApplicationEngine
and forwards the normal HTTP Requests to it. However, Websocket in Servlet Containers works over a different API javax.websocket.*
and require a declared ServerEndpoint
that receives and processes the websocket message. As far as I can tell neither the Ktor Servlet nor the Ktor WebSockets feature provides a shim here and this is why this use case fails with 501 Not Implemented.
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.
KTOR 1.3.1 Server with WebSockets, Auth, Locations, Jackson, Servlet
In my application I defined a websocket route per the Websockets DSL:
When I connect to it via
ws://...
orwss://...
in standalone mode (KTOR from main) it works perfectly. When I deploy my app as WAR in Tomcat 9.0.8 and let KTOR run via Servlet and try to connect to the same websocket either securely or unsecure it gives a 501 HTTP Status with no further information.I turned on the tracing and found that the route works as expected:
the response I get is
I also tried to connect to a WebSocket that has no route defined and as expected I got a 404 error