Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从客户端出站通道访问websocket客户端入站通道拦截器中填充的STOMP getSessionAttributes()?_Java_Spring Websocket - Fatal编程技术网

Java 如何从客户端出站通道访问websocket客户端入站通道拦截器中填充的STOMP getSessionAttributes()?

Java 如何从客户端出站通道访问websocket客户端入站通道拦截器中填充的STOMP getSessionAttributes()?,java,spring-websocket,Java,Spring Websocket,我使用的是SpringWebSocket,我有两个拦截器 <websocket:client-inbound-channel> <websocket:executor core-pool-size="100" max-pool-size="200" keep-alive-seconds="600"/> <websocket:interceptors> <ref bean="myInterceptor"/> &

我使用的是SpringWebSocket,我有两个拦截器

<websocket:client-inbound-channel>
    <websocket:executor core-pool-size="100" max-pool-size="200" keep-alive-seconds="600"/>
    <websocket:interceptors>
        <ref bean="myInterceptor"/>
    </websocket:interceptors>
</websocket:client-inbound-channel>


<websocket:client-outbound-channel>
    <websocket:executor core-pool-size="100" max-pool-size="200" keep-alive-seconds="600"/>
    <websocket:interceptors>
        <ref bean="myOutInterceptor"/>
    </websocket:interceptors>
</websocket:client-outbound-channel>

我使用StompHeaderAccessor在两个拦截器的
preSend(message message,MessageChannel)
中包装消息

我正在使用以下命令访问入站拦截器中会话的属性:

...
StompHeaderAccessor sha = StompHeaderAccessor.wrap(message);
// ignore non-STOMP messages like heartbeat messages
if(sha.getCommand() == null) {
    return message;
}
String sessionId = sha.getSessionId();
Map<String, Object> sessionAttributes = sha.getSessionAttributes();
...
。。。
StompHeaderAccessor sha=StompHeaderAccessor.wrap(消息);
//忽略非跺脚消息,如心跳消息
if(sha.getCommand()==null){
返回消息;
}
字符串sessionId=sha.getSessionId();
Map sessionAttributes=sha.getSessionAttributes();
...
问题是,
sha.getSessionAttributes()返回数据,但当我调用
sha.getSessionAttributes()时在出站拦截器中返回null


如何从出站拦截器访问SessionAttribute?

这感觉像是一个解决办法。我就是这样解决的

我添加了一个bean,其作用类似于包含映射的存储库,键是会话ID,值是会话属性

在入站拦截器case SUBSCRIBE中,我将会话id与属性放在一起。并将其从地图中删除,以防取消订阅和断开连接

在出站拦截器case MESSAGE中,我从该bean获取了相关的sessionAttributes
sessionAttributes=theBean.getsessionandattributes().get(sessionId)
,而不是从MESSAGE对象
sessionAttributes=sha.getSessionAttributes()
获取它