we just tried to migrate one of our projects from Spring 4.0.7.RELEASE to 4.1.1.RELEASE. After that we gain the following error.
java.lang.IllegalStateException: Multiple protocol handlers configured and no protocol was negotiated. Consider configuring a default SubProtocolHandler.
at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.findProtocolHandler(SubProtocolWebSocketHandler.java:294)
at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.clearSession(SubProtocolWebSocketHandler.java:433)
at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.afterConnectionClosed(SubProtocolWebSocketHandler.java:423)
at org.springframework.web.socket.handler.WebSocketHandlerDecorator.afterConnectionClosed(WebSocketHandlerDecorator.java:85)
at org.springframework.web.socket.handler.LoggingWebSocketHandlerDecorator.afterConnectionClosed(LoggingWebSocketHandlerDecorator.java:71)
at org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator.afterConnectionClosed(ExceptionWebSocketHandlerDecorator.java:91)
at org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.close(AbstractSockJsSession.java:291)
at org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator.tryCloseWithError(ExceptionWebSocketHandlerDecorator.java:60)
at org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator.afterConnectionEstablished(ExceptionWebSocketHandlerDecorator.java:50)
at org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.delegateConnectionEstablished(AbstractSockJsSession.java:207)
at org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession.initializeDelegateSession(WebSocketServerSockJsSession.java:159)
at org.springframework.web.socket.sockjs.transport.handler.SockJsWebSocketHandler.afterConnectionEstablished(SockJsWebSocketHandler.java:87)
at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter.onOpen(StandardWebSocketHandlerAdapter.java:101)
at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler.init(WsHttpUpgradeHandler.java:129)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:633)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1721)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1679)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
We did not change anything on the configuration (and can't find any hint that we have to change anything).
Here is the server-side configuration for our WebSockets. (It is in fact the same as in the Spring documentation).
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfiguration extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void registerStompEndpoints(final StompEndpointRegistry registry) {
registry.addEndpoint("/tyresearch").withSockJS();
registry.addEndpoint("/tyresearch/changeConfiguration").withSockJS();
registry.addEndpoint("/tyresearch/detailView").withSockJS();
}
@Override
public void configureMessageBroker(final MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic");
config.setApplicationDestinationPrefixes("/app");
}
}
Further we have for each of the Endpoints described before a method like the following:
@MessageMapping("/tyresearch")
public void startTyreSearch(@Payload final TyreSearchRequestContainerDto message, final Principal user, final StompHeaderAccessor) {
....
}
Client side call from JavaScript looks something like the following:
var socket = new $wnd.SockJS('/server/api/rest/tyresearch');
var stompClient = $wnd.Stomp.over(socket);
stompClient.connect({}, function(frame) {
console.log('Connected: ' + frame);
});
Does someone have an idea, what change is making us trouble here and how to solve this problem?
Thank you very much.
First of it is really a bug
. Thank you for pointing it out!
We raised an issue (https://jira.spring.io/browse/SPR-12403) and it will be fixed the next week.
Before that, can't you overcome the malty mapping for stomp endpoints with just the single one?
UPDATE
i got an error which told me that the protocols stomp 1.0, 1.1 and 1.2 are already mapped
Since we really have an issue here and you need to overcome it somehow, I'd suggest you to try to override bean:
@Bean
public WebSocketHandler subProtocolWebSocketHandler() {
return new SubProtocolWebSocketHandler(clientInboundChannel(), clientOutboundChannel());
}
with your custom implementation, where addProtocolHandler
will have an empty body, because you say that you already define STOMP
as default one. Having that the Framework won't be able to add more SubProtocolHandler
s.