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

 ̄綄美尐妖づ 提交于 2019-12-10 12:59:39

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/35052020/why-does-sockjs-add-a-info-to-a-given-websocket-url-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!