|
@@ -44,13 +44,17 @@ public class WebSocketServer {
|
|
|
@OnOpen
|
|
|
public void onOpen(Session session, EndpointConfig config){
|
|
|
HttpSession httpSession = (HttpSession) config.getUserProperties().get(HttpSession.class.getName());
|
|
|
- key = String.valueOf(httpSession.getAttribute(USER_ID));
|
|
|
- this.session = session;
|
|
|
- System.out.println("当前登录用户id:" + key);
|
|
|
- atomicInteger.incrementAndGet();
|
|
|
- System.out.println("建立连接成功 onOpen 线程数量:"+atomicInteger.get()+" sessionID:"+ key);
|
|
|
- System.out.println("当前socket连接数量:" + webSocketMap.size());
|
|
|
- webSocketMap.put(key,this);
|
|
|
+ Object attribute = httpSession.getAttribute(USER_ID);
|
|
|
+ if (attribute != null) {
|
|
|
+ key = String.valueOf(attribute);
|
|
|
+ this.session = session;
|
|
|
+ System.out.println("当前登录用户id:" + key);
|
|
|
+ atomicInteger.incrementAndGet();
|
|
|
+ System.out.println("建立连接成功 onOpen 线程数量:"+atomicInteger.get()+" sessionID:"+ key);
|
|
|
+ System.out.println("当前socket连接数量:" + webSocketMap.size());
|
|
|
+ webSocketMap.put(key,this);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|