I'm building webchat with Spring boot and Angular. To do this, I use Websockets with client-side SockJS and Webstomp, and server-side Spring.
The problem is I obtain this error on the console in runtime :
DEPRECATED: undefined is not a recognized STOMP version. In next major client version, this will close the connection.
I checked on google and figure out this thread on the github stomp project : https://github.com/JSteunou/webstomp-client/issues/75
This is a problem of protocol compatibility with SockJS and Webstomp.
So, I added options parameter in the following code (even if the protocol parameter is not allowed for over method?)
var socket = new SockJS("http://localhost:8086/ws");
var options = {debug: false, protocols: webstomp.VERSIONS.supportedProtocols()};
var stompClient = webstomp.over(socket, options);
And the error message disappeared. But in the request headers there is still no header Sec-Websocket-Procotol to define which protocol use and I think I will have issues in the future.
What can I do to make my code works ?
Client-side (Angular)
connectWebSocketRoom() {
var socket = new SockJS("http://localhost:8086/ws");
var options = {debug: false, protocols: webstomp.VERSIONS.supportedProtocols()};
var stompClient = webstomp.over(socket, options);
// var stompClient2 = webstomp.client(socket, ['v10.stomp', 'v11.stomp', 'v12.stomp']);
stompClient.connect({}, function(frame) {
console.log("test disconnect");
stompClient.disconnect();
});
}
Server-side (Spring)
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/ws").setAllowedOrigins("*").withSockJS();
}
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.setApplicationDestinationPrefixes("/rooms");
config.enableSimpleBroker("/topic", "/queue");
}
}
Headers of requests and responses :
Request
Host: localhost:8086
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0
Accept: */*
Accept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Sec-WebSocket-Version: 13
Origin: http://localhost:4200
Sec-WebSocket-Extensions: permessage-deflate
Sec-WebSocket-Key: SjoHYGkjTrPsDan0XmfgNg==
Connection: keep-alive, Upgrade
Cookie: access_token=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJwaWVycmhvIiwicm9sZXMiOlsiUk9MRV9BRE1JTiIsIldSSVRFX0FDQ0VTUyIsIkRFTEVURV9BQ0NFU1MiLCJSRUFEX0FDQ0VTUyJdLCJpYXQiOjE1NjgxMjg1NzUsImV4cCI6MTU2ODEyODg3NX0.a4BNKm9qLbpEZFeMaI9seXSICWys3Exrumk9WyOqp6A
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
Response
HTTP/1.1 101
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Access-Control-Allow-Origin: http://localhost:4200
Access-Control-Allow-Credentials: true
Set-Cookie: access_token=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJwaWVycmhvIiwicm9sZXMiOlsiUk9MRV9BRE1JTiIsIlJFQURfQUNDRVNTIiwiV1JJVEVfQUNDRVNTIiwiREVMRVRFX0FDQ0VTUyJdLCJpYXQiOjE1NjgxMjg1NzYsImV4cCI6MTU2ODEyODg3Nn0.lD9wrYkztqWnihIqJodr3EpjMcMfBVUmbhxetBaGX5A; Max-Age=86400; Expires=Wed, 11-Sep-2019 15:16:16 GMT; Path=/; HttpOnly
Set-Cookie: access_token=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJwaWVycmhvIiwicm9sZXMiOlsiUk9MRV9BRE1JTiIsIlJFQURfQUNDRVNTIiwiV1JJVEVfQUNDRVNTIiwiREVMRVRFX0FDQ0VTUyJdLCJpYXQiOjE1NjgxMjg1NzYsImV4cCI6MTU2ODEyODg3Nn0.lD9wrYkztqWnihIqJodr3EpjMcMfBVUmbhxetBaGX5A; Max-Age=86400; Expires=Wed, 11-Sep-2019 15:16:16 GMT; Path=/; HttpOnly
Upgrade: websocket
Connection: upgrade
Sec-WebSocket-Accept: 9fahUc0KPDJ8vAUF2In5zZCGQTM=
Sec-WebSocket-Extensions: permessage-deflate
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Date: Tue, 10 Sep 2019 15:16:15 GMT