|
@@ -17,7 +17,6 @@ import javax.websocket.server.ServerEndpoint;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import cn.com.qmth.examcloud.api.commons.security.bean.User;
|
|
@@ -25,6 +24,7 @@ import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
|
|
|
import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
|
|
|
import cn.com.qmth.examcloud.commons.util.JsonUtil;
|
|
|
import cn.com.qmth.examcloud.web.redis.RedisClient;
|
|
|
+import cn.com.qmth.examcloud.web.support.SpringContextHolder;
|
|
|
|
|
|
/**
|
|
|
* websocket ServerEndpoint
|
|
@@ -39,8 +39,15 @@ public class WebSocketServerEndpoint {
|
|
|
|
|
|
private static final ExamCloudLog WS_LOG = ExamCloudLogFactory.getLog("WS");
|
|
|
|
|
|
- @Autowired
|
|
|
- RedisClient redisClient;
|
|
|
+ private static RedisClient redisClient;
|
|
|
+
|
|
|
+ private static RedisClient getRedisClient() {
|
|
|
+ if (null != redisClient) {
|
|
|
+ return redisClient;
|
|
|
+ }
|
|
|
+ redisClient = SpringContextHolder.getBean(RedisClient.class);
|
|
|
+ return redisClient;
|
|
|
+ }
|
|
|
|
|
|
@OnOpen
|
|
|
public void onOpen(Session session, @PathParam("path") String path) {
|
|
@@ -63,7 +70,7 @@ public class WebSocketServerEndpoint {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- User user = redisClient.get(key, User.class);
|
|
|
+ User user = getRedisClient().get(key, User.class);
|
|
|
|
|
|
if (null == user) {
|
|
|
WS_LOG.error("[onOpen-FAIL]. path=" + path + ". no login.");
|
|
@@ -117,7 +124,7 @@ public class WebSocketServerEndpoint {
|
|
|
String key = SessionHolder.getKey(session);
|
|
|
String token = SessionHolder.getToken(session);
|
|
|
|
|
|
- User user = redisClient.get(key, User.class);
|
|
|
+ User user = getRedisClient().get(key, User.class);
|
|
|
|
|
|
if (null == user) {
|
|
|
WS_LOG.error("[onMessage-FAIL]. path=" + path + ". no login.");
|