0
当前,当成功连接到端点时,我通过响应头将自定义令牌(称为访问令牌)传递回客户端。此标头设置正确,我可以通过分析HTTP响应来验证标头。握手后向STOMP客户端框架对象返回头部
然而,试图从头部没有设置框架对象的标题时(见JavaScript的下面):
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
}
);
我设置的响应头在服务器上进行如下:
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);
我剥去了一些代码,可以确认拦截器正在被调用。我认为这不是在连接函数被调用时将头部值传递回客户端的正确方法吗?我似乎无法找到任何有关如何完成此任务的文档。谢谢。