当前位置:网站首页>WebSocket Session is null
WebSocket Session is null
2022-07-31 03:02:00 【Gerard pique, thanks】
WebSocket Session为null
引入HttpSessionWSHelper类
/** * @program: * @description: 获取session * @author: Xzj * @create: 2021-01-20 15:05 **/
package com.pm.common.socket;
import javax.servlet.http.HttpSession;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;
public class HttpSessionWSHelper extends ServerEndpointConfig.Configurator {
@Override
public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
System.out.println("调用modifyHandshake方法...");
HttpSession session = (HttpSession) request.getHttpSession();//session有可能为空
if (session!=null){
System.out.println("获取到session id:"+session.getId());
sec.getUserProperties().put(HttpSession.class.getName(),session);
}else{
System.out.println("modifyHandshake 获取到null session");
}
}
}
WebSocketused in service class
在@ServerEndpoint(value = “/websocket/{name}”)中加入configurator = HttpSessionWSHelper.class
@Slf4j
@Component
@ServerEndpoint(value = "/websocket/{name}",configurator = HttpSessionWSHelper.class)
public class WebSocket {
}
SpringBoot_WebSocket_JavaPush messages in the background
边栏推荐
- 图解lower_bound&upper_bound
- 全流程调度——MySQL与Sqoop
- The whole process scheduling, MySQL and Sqoop
- AI software development process in medical imaging field
- 跨专业考研难度大?“上岸”成功率低?这份实用攻略请收下!
- 点云DBSCAN聚类(MATLAB,非内置函数)
- LeetCode简单题之两个数组间的距离值
- The application of AI in the whole process of medical imaging equipment
- 4. Sensitive word filtering (prefix tree)
- execsnoop 工具
猜你喜欢

php 网站的多语言设置(IP地址区分国内国外)

STM32问题合集

Classic linked list OJ strong training problem - fast and slow double pointer efficient solution

你们程序员为什么不靠自己的项目谋生?而必须为其他人打工?

Graphical lower_bound & upper_bound

JS 函数 this上下文 运行时点语法 圆括号 数组 IIFE 定时器 延时器 self.备份上下文 call apply

CentOS7下mysql5.7.37的安装【完美方案】

学习DAVID数据库(1)

Crypto Firms Offer Offer To Theft Hackers: Keep A Little, Give The Rest

CefSharp入门-winform
随机推荐
TCP/IP four-layer model
[Android] Room - Alternative to SQLite
LeetCode Daily Question 2022/7/25-2022/7/31
Project (5) - Small target detection tph-yolov5
【CocosCreator 3.5】CocosCreator 获取网络状态
How to build a private yum source
golang GUI for nuxui — HelloWorld
C primer plus学习笔记 —— 8、结构体
The modification is not properly placed in the sandbox, causing Apple compatibility issues
接口测试关键技术
Thesis framework of the opening report
【Android】Room —— SQLite的替代品
Crypto Firms Offer Offer To Theft Hackers: Keep A Little, Give The Rest
6、显示评论和回复
4. Sensitive word filtering (prefix tree)
Modbus on AT32 MCUs
php 网站的多语言设置(IP地址区分国内国外)
Compile Hudi
execsnoop 工具
Mysql 45讲学习笔记(二十四)MYSQL主从一致