Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
WebSocket configuration is pretty basic
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableSimpleBroker("/some_topic");
registry.setApplicationDestinationPrefixes("/app");
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/ws").setAllowedOrigins("*").withSockJS();
Once the browser starts. it attempts to establish web-socket connection to
ws://localhost:53100/ws
First call goes well with Status Code "101 Switching Protocols"
but the second call reports "Error during WebSocket handshake: Unexpected response code: 500"
and from there on Chrome keeps reporting it every 10+ seconds.
In the application log I see following lines every time browser reports a 500.
Any help, pointers will be greatly appreciated.
[AbstractErrorWebExceptionHandler]: [28b2eda4] 500 Server Error for HTTP GET "/ws"
java.lang.ClassCastException: class org.apache.catalina.connector.ResponseFacade cannot be cast to class reactor.netty.http.server.HttpServerResponse (org.apache.catalina.connector.ResponseFacade and reactor.netty.http.server.HttpServerResponse are in unnamed module of loader 'app')
at org.springframework.web.reactive.socket.server.upgrade.ReactorNettyRequestUpgradeStrategy.upgrade(ReactorNettyRequestUpgradeStrategy.java:163) ~[spring-webflux-5.3.21.jar:5.3.21]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
*__checkpoint ? org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
*__checkpoint ? org.springframework.security.web.server.authorization.AuthorizationWebFilter [DefaultWebFilterChain]
I was expecting the browser to establish the connection to the endpoint.
Tried using Chrome and Edge. Chrome DevTools does not report specific error status but only
WebSocket connection to 'ws://localhost:53100/ws' failed: client.js: 281
I also encountered a similar problem:
Gateway The default usage is based on Netty Container of RequestUpgradeStrategy and WebSocketClient Result in an error , Statement Tomcat The container corresponds to Bean To cover it can solve this problem
Here is my solution:
add follow beans to container
@Bean
@Primary
WebSocketClient tomcatWebSocketClient() {
return new TomcatWebSocketClient();
@Bean
@Primary
public RequestUpgradeStrategy requestUpgradeStrategy() {
return new TomcatRequestUpgradeStrategy();
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.