OpenLiberty / open-liberty

Open Liberty is a highly composable, fast to start, dynamic application server runtime environment
https://openliberty.io
Eclipse Public License 2.0
1.14k stars 587 forks source link

Spring Boot 3.x WebSocket Upgrade Issue #26880

Open SkipperQ93 opened 10 months ago

SkipperQ93 commented 10 months ago

Describe the bug
I have set up a simple websocket application(https://github.com/spring-guides/gs-messaging-stomp-websocket) and deployed on both tomcat 10 and OpenLiberty. When I try to connect WebSocket, stomp gives an error that it is unable to connect. I tried logging and this what I get:

[INFO] 2023-11-09T10:52:20.026+03:00 TRACE 75603 --- [cutor-thread-55] o.s.b.w.s.f.OrderedRequestContextFilter  : Bound request context to thread: io.openliberty.webcontainer60.srt.SRTServletRequest60@7b4ebd98
[INFO] 2023-11-09T10:52:20.027+03:00 TRACE 75603 --- [cutor-thread-55] o.s.web.servlet.DispatcherServlet        : GET "/messaging-stomp-websocket-complete-0.0.1-SNAPSHOT/gs-guide-websocket", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
[INFO] 2023-11-09T10:52:20.028+03:00 TRACE 75603 --- [cutor-thread-55] o.s.w.s.s.s.WebSocketHandlerMapping      : Mapped to HandlerExecutionChain with [org.springframework.web.socket.server.support.WebSocketHttpRequestHandler@32f306a6] and 1 interceptors
[INFO] 2023-11-09T10:52:20.028+03:00 DEBUG 75603 --- [cutor-thread-55] o.s.w.s.s.s.WebSocketHttpRequestHandler  : GET /messaging-stomp-websocket-complete-0.0.1-SNAPSHOT/gs-guide-websocket
[INFO] 2023-11-09T10:52:20.028+03:00 TRACE 75603 --- [cutor-thread-55] o.s.w.s.s.s.DefaultHandshakeHandler      : Processing request http://127.0.0.1:9080/messaging-stomp-websocket-complete-0.0.1-SNAPSHOT/gs-guide-websocket with headers=[Host:"127.0.0.1:9080", Connection:"Upgrade", Pragma:"no-cache", Cache-Control:"no-cache", User-Agent:"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36", Upgrade:"websocket", Origin:"http://127.0.0.1:9080", Sec-WebSocket-Version:"13", Accept-Encoding:"gzip, deflate, br", Accept-Language:"en-GB,en-US;q=0.9,en;q=0.8,zh-CN;q=0.7,zh;q=0.6", Sec-WebSocket-Key:"0FtR8JZo29SN0n/XsrkiMw==", Sec-WebSocket-Extensions:"permessage-deflate; client_max_window_bits", Sec-WebSocket-Protocol:"v12.stomp, v11.stomp, v10.stomp"]
[INFO] 2023-11-09T10:52:20.028+03:00 TRACE 75603 --- [cutor-thread-55] o.s.w.s.s.s.DefaultHandshakeHandler      : Upgrading to WebSocket, subProtocol=v12.stomp, extensions=[]
[INFO] 2023-11-09T10:52:20.030+03:00 TRACE 75603 --- [cutor-thread-55] o.s.web.servlet.DispatcherServlet        : No view rendering, null ModelAndView returned.
[INFO] 2023-11-09T10:52:20.030+03:00 DEBUG 75603 --- [cutor-thread-55] o.s.web.servlet.DispatcherServlet        : Completed 200 OK, headers={masked}
[INFO] 2023-11-09T10:52:20.031+03:00 TRACE 75603 --- [cutor-thread-55] o.s.b.w.s.f.OrderedRequestContextFilter  : Cleared thread-bound request context: io.openliberty.webcontainer60.srt.SRTServletRequest60@7b4ebd98
[INFO] 2023-11-09T10:52:20.031+03:00 DEBUG 75603 --- [cutor-thread-55] s.w.s.h.LoggingWebSocketHandlerDecorator : New StandardWebSocketSession[id=10270901-5537-0be4-90f9-47a6ff87f92a, uri=ws://127.0.0.1:9080/messaging-stomp-websocket-complete-0.0.1-SNAPSHOT/gs-guide-websocket]

Now When I try connecting on tomcat 10, the logs are like:

2023-11-09T10:53:40.407+03:00 TRACE 75791 --- [nio-8080-exec-5] o.s.b.w.s.f.OrderedRequestContextFilter  : Bound request context to thread: org.apache.catalina.connector.RequestFacade@398b49c7
2023-11-09T10:53:40.407+03:00 TRACE 75791 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet        : GET "/messaging-stomp-websocket-complete-0.0.1-SNAPSHOT/gs-guide-websocket", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
2023-11-09T10:53:40.407+03:00 TRACE 75791 --- [nio-8080-exec-5] o.s.w.s.s.s.WebSocketHandlerMapping      : Mapped to HandlerExecutionChain with [org.springframework.web.socket.server.support.WebSocketHttpRequestHandler@5e1d03d7] and 1 interceptors
2023-11-09T10:53:40.409+03:00 DEBUG 75791 --- [nio-8080-exec-5] o.s.w.s.s.s.WebSocketHttpRequestHandler  : GET /messaging-stomp-websocket-complete-0.0.1-SNAPSHOT/gs-guide-websocket
2023-11-09T10:53:40.415+03:00 TRACE 75791 --- [nio-8080-exec-5] o.s.w.s.s.s.DefaultHandshakeHandler      : Processing request http://127.0.0.1:8080/messaging-stomp-websocket-complete-0.0.1-SNAPSHOT/gs-guide-websocket with headers=[host:"127.0.0.1:8080", connection:"Upgrade", pragma:"no-cache", cache-control:"no-cache", user-agent:"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36", upgrade:"websocket", origin:"http://127.0.0.1:8080", sec-websocket-version:"13", accept-encoding:"gzip, deflate, br", accept-language:"en-GB,en-US;q=0.9,en;q=0.8,zh-CN;q=0.7,zh;q=0.6", sec-websocket-key:"H+H+rhUXJhSsCy9loXglpA==", sec-websocket-extensions:"permessage-deflate; client_max_window_bits", sec-websocket-protocol:"v12.stomp, v11.stomp, v10.stomp"]
2023-11-09T10:53:40.416+03:00 TRACE 75791 --- [nio-8080-exec-5] o.s.w.s.s.s.DefaultHandshakeHandler      : Upgrading to WebSocket, subProtocol=v12.stomp, extensions=[]
2023-11-09T10:53:40.434+03:00 TRACE 75791 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet        : No view rendering, null ModelAndView returned.
2023-11-09T10:53:40.434+03:00 DEBUG 75791 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet        : Completed 101 SWITCHING_PROTOCOLS, headers={masked}
2023-11-09T10:53:40.434+03:00 TRACE 75791 --- [nio-8080-exec-5] o.s.b.w.s.f.OrderedRequestContextFilter  : Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@398b49c7
2023-11-09T10:53:40.444+03:00 DEBUG 75791 --- [nio-8080-exec-5] s.w.s.h.LoggingWebSocketHandlerDecorator : New StandardWebSocketSession[id=9db22df1-2433-183a-3079-9dcfb5b96862, uri=ws://127.0.0.1:8080/messaging-stomp-websocket-complete-0.0.1-SNAPSHOT/gs-guide-websocket]

The only difference I see here is that with OpenLiberty, the request does not upgrade to websocket with status code 101. Instead it is responding with 200 status code.

Is there something wrong that I am doing here. Any help would be really appreciated.

Steps to Reproduce
1) Clone https://github.com/spring-guides/gs-messaging-stomp-websocket 2) Deploy on OpenLiberty. 3) Click "Connect"

Expected behavior
The websocket connection to switch protocol (101 code) and connection should be established.

Diagnostic information:

volosied commented 10 months ago

Hi, thanks for reporting this. I'll take a look and get back to you soon.

volosied commented 10 months ago

This is more involved than I thought it would. It doesn't look like the websocket endpoint is picked up?

I'm also encountering a differnet exception when I deploy it on OL:


2023-11-10T15:53:58.011-05:00  WARN 76558 --- [cutor-thread-26] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotWritableException: No converter for [class java.util.LinkedHashMap] with preset Content-Type 'text/html;charset=UTF-8']
[ERROR   ] Error Page Exception: 
                                                                                                               0-0

                                                                                                               Error Page Exception
                                                                                                               com.ibm.ws.webcontainer.webapp.WebAppErrorReport: SRVE0295E: Error reported: 500

2023-11-10T15:55:55.779-05:00  WARN 76558 --- [ecutor-thread-9] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotWritableException: No converter for [class java.util.LinkedHashMap] with preset Content-Type 'text/html;charset=UTF-8']
volosied commented 10 months ago

Hmm. Restarted the application and it went away? I just getting: "Firefox can’t establish a connection to the server at ws://localhost:8080/gs-guide-websocket. "

The websocket trace doesn't show the endpoint was started. Did websockets work with previous springboot features? Our code hasn't changed much between 1.1, 2.0, and 2.1.

There may be some missing integration step with our websocket implementation if springBoot changed.

Otherwise, I'm not getting a 200 response at all? I enabled the app via

<springBootApplication location='/path/to/gs-messaging-stomp-websocket/complete/build/libs/messaging-stomp-websocket-0.0.1-SNAPSHOT.jar'/>
SkipperQ93 commented 9 months ago

The same war package when tested on tomcat works fine. There is no code change at all.