dimanche 5 avril 2015

Returning header to STOMP client frame object after handshake

Currently, when successfully connecting to an endpoint, I am passing a custom token (called access-token) back to the client via a response header. This header is being set correctly and I can verify the header by analyzing the HTTP response.


However, when trying to get the header from the frame object the header is not set (see the JavaScript below):



stompClient.connect(headers,
function(frame) {
console.log('=========================================');
console.log(frame.headers['access-token']);
console.log(frame);
console.log('=========================================');
stompClient.subscribe('/topic/test', function(stuff){
console.debug(stuff);
});
},
function(error) {
//error code
}
);


I am setting the response header as follows on the server:



public class HttpSessionHandshakeInterceptorImpl extends HttpSessionHandshakeInterceptor {
@Override
public boolean beforeHandshake(ServerHttpRequest request,
ServerHttpResponse response, WebSocketHandler wsHandler,
Map<String, Object> attributes) throws Exception {

response.getHeaders().set("access-token", token);

return super.beforeHandshake(request, response, wsHandler, attributes);


I stripped out some code and can confirm that the interceptor is being called. I take it that this is not the correct way to pass a header value back to the client when the connect function is called? I can't seem to find any documentation on how to accomplish this. Thanks.


Aucun commentaire:

Enregistrer un commentaire