I am testing Spring 4's different WebSocket approaches.
The most basic, works well, invoking the interceptor (I want to publish the HttpSession attributes):
<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>
Here is when the interceptor is invoked in org.springframework.web.socket.server.support.WebSocketHttpRequestHandler.handleRequest()
:
[...]
try {
Map<String, Object> attributes = new HashMap<String, Object>();
if (!chain.applyBeforeHandshake(request, response, attributes)) {
However when I use the SockJS handler, the interceptor is never called:
<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>
It seems that org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler
, unlike WebSocketHttpRequestHandler
, doesn't have a "interceptors" attribute.
Is this a Spring bug? Do you know any way to publish HttpSessionAttributes to SockJS websockets?