Why sockJS appends '/ info' to the given websocket url path

I want to open the websocket port using the path "webapp / socket.do". When I use SockJS and try to initiate a call by code

var socket = new SockJS('/webapp/socket.do'); stompClient = Stomp.over(socket); stompClient.connect({}, ... 

SockJS will add "/ info" to the end of this path by default. I want to know why? Can this be changed or prevented?

When using this with Spring MVC and url pattern mappings in DispatcherServlet, like < url-pattern >*.do</url-pattern> , it will return a 404 error. It is blocked due to the "/ info" line added by sockJS to the specified URL to the address.

Spring servlet mapping code web.xml:

 <servlet-mapping> <servlet-name>dispatch-servlet</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> 

Does anyone know what sockJS is trying to do and why?

+5
source share
1 answer

This is part of the SockJS protocol and is required. This endpoint is implemented by the server and transfers server capabilities such as supported protocols. See the relevant part of the SockJS protocol .

In this case, I think you need to configure the servlet display not only for this endpoint, but also for other requests that may arise: HTTP UPGRADE requests for websocket, all other requests for HTTP-based transports supported by SockJS .

+4
source

Source: https://habr.com/ru/post/1241680/


All Articles