我正在测试 Spring 4 的不同 WebSocket 方法。
最基本的,运行良好,调用拦截器(我想发布 HttpSession 属性):
<websocket:handlers>
<websocket:mapping path="/simpleChatHandler" handler="simpleChatHandler"/>
<websocket:handshake-interceptors>
<bean class="org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor"/>
</websocket:handshake-interceptors>
</websocket:handlers>
这是在调用拦截器时org.springframework.web.socket.server.support.WebSocketHttpRequestHandler.handleRequest()
:
[...]
try {
Map<String, Object> attributes = new HashMap<String, Object>();
if (!chain.applyBeforeHandshake(request, response, attributes)) {
但是,当我使用 SockJS 处理程序时,永远不会调用拦截器:
<websocket:handlers>
<websocket:mapping path="/simpleChatHandlerSockJS" handler="simpleChatHandler"/>
<websocket:handshake-interceptors>
<bean class="org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor"/>
</websocket:handshake-interceptors>
<websocket:sockjs/>
</websocket:handlers>
org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler
与 不同,它似乎WebSocketHttpRequestHandler
没有“拦截器”属性。
这是春天的错误吗?您知道将 HttpSessionAttributes 发布到 SockJS websockets 的任何方法吗?