|
@@ -16,6 +16,7 @@ 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.apache.logging.log4j.ThreadContext;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import cn.com.qmth.examcloud.api.commons.security.bean.User;
|
|
@@ -51,12 +52,15 @@ public class WebSocketServerEndpoint {
|
|
|
|
|
|
@OnOpen
|
|
|
public void onOpen(Session session, @PathParam("path") String path) {
|
|
|
+ String sessionId = session.toString().substring(session.getClass().getName().length() + 1);
|
|
|
+ ThreadContext.put("TRACE_ID", sessionId);
|
|
|
|
|
|
if (WS_LOG.isDebugEnabled()) {
|
|
|
WS_LOG.debug("[onOpen]. path=" + path + "");
|
|
|
}
|
|
|
|
|
|
MessageOut out = new MessageOut();
|
|
|
+ out.setSessionId(sessionId);
|
|
|
out.setStatus(200);
|
|
|
out.setPath(path);
|
|
|
|
|
@@ -102,6 +106,8 @@ public class WebSocketServerEndpoint {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ ThreadContext.put("CALLER", user.getKey());
|
|
|
+
|
|
|
out.setStatusCode("200");
|
|
|
out.setStatusDesc("success");
|
|
|
sendText(session, path, out);
|
|
@@ -152,12 +158,18 @@ public class WebSocketServerEndpoint {
|
|
|
|
|
|
@OnClose
|
|
|
public void onClose(Session session, @PathParam("path") String path) {
|
|
|
+ String sessionId = session.toString().substring(session.getClass().getName().length() + 1);
|
|
|
+ ThreadContext.put("TRACE_ID", sessionId);
|
|
|
+
|
|
|
WS_LOG.debug("[onClose]. path=" + path);
|
|
|
SessionHolder.delSession(session);
|
|
|
}
|
|
|
|
|
|
@OnMessage
|
|
|
public void onMessage(Session session, @PathParam("path") String path, String message) {
|
|
|
+ String sessionId = session.toString().substring(session.getClass().getName().length() + 1);
|
|
|
+ ThreadContext.put("TRACE_ID", sessionId);
|
|
|
+
|
|
|
WS_LOG.debug("[onMessage]. path=" + path + ". message=" + message);
|
|
|
String key = SessionHolder.getKey(session);
|
|
|
String token = SessionHolder.getToken(session);
|
|
@@ -165,6 +177,7 @@ public class WebSocketServerEndpoint {
|
|
|
User user = getRedisClient().get(key, User.class);
|
|
|
|
|
|
MessageOut out = new MessageOut();
|
|
|
+ out.setSessionId(sessionId);
|
|
|
out.setStatus(200);
|
|
|
out.setPath(path);
|
|
|
|
|
@@ -242,6 +255,9 @@ public class WebSocketServerEndpoint {
|
|
|
|
|
|
@OnError
|
|
|
public void onError(Session session, @PathParam("path") String path, Throwable t) {
|
|
|
+ String sessionId = session.toString().substring(session.getClass().getName().length() + 1);
|
|
|
+ ThreadContext.put("TRACE_ID", sessionId);
|
|
|
+
|
|
|
WS_LOG.error("[onError]. path=" + path, t);
|
|
|
SessionHolder.delSession(session);
|
|
|
}
|