Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does sockJS add a '/info' to a given websocket url path

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

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

    stompClient.connect({}, ...

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

When using this with Spring MVC and have url pattern mappings to DispatcherServlet like < url-pattern >*.do</url-pattern>, this will return a 404 error. it is blocked because of the "/info" string added by sockJS to the given url.

Spring web.xml servlet mapping code:

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

Does any know what sockJS is trying there and why?

like image 368
Lihkinisak Avatar asked Jan 28 '16 02:01

Lihkinisak


Video Answer


1 Answers

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

In that case, I guess you need to adapt your servlet mapping not only for this endpoint, but also for other requests that might come in: HTTP UPGRADE requests for websocket, all other requests for HTTP-based transports supported by SockJS.

like image 200
Brian Clozel Avatar answered Sep 27 '22 21:09

Brian Clozel