为什么 sockJS 向给定的 websocket url 路径添加“/info" [英] Why does sockJS add a '/info' to a given websocket url path

查看:253
本文介绍了为什么 sockJS 向给定的 websocket url 路径添加“/info"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用webapp/socket.do"路径打开一个websocket端口.当我使用 SockJS 并尝试通过代码发起调用时

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 默认会在给定路径的末尾添加一个/info".我想知道为什么?这可以改变或阻止吗?

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?

当将它与 Spring MVC 一起使用并具有到 DispatcherServlet 的 url 模式映射时,如 <url-pattern >*.do</url-pattern>,这将返回 404 错误.由于 sockJS 添加到给定 url 的/info"字符串,它被阻止.

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 映射代码:

Spring web.xml servlet mapping code:

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

有谁知道 sockJS 在那里尝试什么以及为什么?

Does any know what sockJS is trying there and why?

推荐答案

这是 SockJS 协议的一部分,并且是强制性的.此端点由服务器实现并传达服务器功能,例如支持的协议.请参阅SockJS 协议的相关部分.

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.

在这种情况下,我想您不仅需要针对此端点调整 servlet 映射,还需要针对可能出现的其他请求调整 servlet 映射:针对 websocket 的 HTTP UPGRADE 请求,针对 SockJS 支持的基于 HTTP 的传输.

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.

这篇关于为什么 sockJS 向给定的 websocket url 路径添加“/info"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆