I am using Spring boot and Undertow for my websockets server and it seems it doesn't properly implement the servlet specification because I'm getting following error when upgrading the request to WS:
2022-09-20 09:53:11,349 ERROR [http-nio-8025-exec-1] o.a.c.c.C.[.[.[.[dispatcherServlet]: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.socket.server.HandshakeFailureException: Uncaught failure for request http://localhost:8025/v2/ticker; nested exception is java.lang.IllegalArgumentException: No 'javax.websocket.server.ServerContainer' ServletContext attribute. Are you running in a Servlet container that supports JSR-356?] with root cause
java.lang.IllegalArgumentException: No 'javax.websocket.server.ServerContainer' ServletContext attribute. Are you running in a Servlet container that supports JSR-356?
at org.springframework.util.Assert.notNull(Assert.java:201)
at org.springframework.web.socket.server.standard.AbstractStandardUpgradeStrategy.getContainer(AbstractStandardUpgradeStrategy.java:71)
at org.springframework.web.socket.server.standard.UndertowRequestUpgradeStrategy.getContainer(UndertowRequestUpgradeStrategy.java:92)
...
My dependencies are:
implementation 'org.springframework.boot:spring-boot-starter-undertow'
implementation ('org.springframework.boot:spring-boot-starter-websocket') {
exclude group : 'org.springframework.boot', module : 'spring-boot-starter-tomcat'
exclude group : 'org.apache.tomcat.embed', module : 'tomcat-embed-websocket'
}
Note: this happens only when I try to authenticate my requests and set HandshakeHandler using UndertowRequestUpgradeStrategy
// WebSocketConfigurer
registry.addHandler(...)
.setHandshakeHandler(new DefaultHandshakeHandler(new UndertowRequestUpgradeStrategy()))