|
@@ -25,7 +25,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|
|
*/
|
|
|
@ServerEndpoint(path = "/wss/action/{token}", port = "${ws.port}", corsOrigins = "*", corsAllowCredentials = "true")
|
|
|
@Slf4j
|
|
|
-public class actionSocket {
|
|
|
+public class ActionSocket {
|
|
|
|
|
|
@Value("${main.url}")
|
|
|
private String mainUrl;
|
|
@@ -39,22 +39,22 @@ public class actionSocket {
|
|
|
resData.set("msg", "验证成功");
|
|
|
session.setSubprotocols("stomp");
|
|
|
String url = mainUrl + "api/sso/user/checkToken";
|
|
|
- actionSocket.log.info("验证token的url:{}", url);
|
|
|
+ ActionSocket.log.info("验证token的url:{}", url);
|
|
|
Map<String, String> headersPrm = new HashMap<>();
|
|
|
headersPrm.put("token", token);
|
|
|
com.alibaba.fastjson.JSONObject res = OkHttpUtils.httpPostJson(url, "", headersPrm);
|
|
|
if (!token.equals("xx-xx-xx-token")) {
|
|
|
if (null != res) {
|
|
|
- actionSocket.log.info("登录态校验接口返回:{}", res.toJSONString());
|
|
|
+ ActionSocket.log.info("登录态校验接口返回:{}", res.toJSONString());
|
|
|
int code = -10;
|
|
|
if (res.containsKey("code")) {
|
|
|
code = (int) res.get("code");
|
|
|
if (code != 0) {
|
|
|
- actionSocket.log.info("Authentication failed!");
|
|
|
+ ActionSocket.log.info("Authentication failed!");
|
|
|
session.close();
|
|
|
}
|
|
|
} else {
|
|
|
- actionSocket.log.info("Authentication failed!");
|
|
|
+ ActionSocket.log.info("Authentication failed!");
|
|
|
session.close();
|
|
|
}
|
|
|
} else {
|
|
@@ -65,15 +65,15 @@ public class actionSocket {
|
|
|
|
|
|
@OnOpen
|
|
|
public void onOpen(Session session, HttpHeaders headers, @PathVariable Map pathMap) {
|
|
|
- actionSocket.log.info("new connection, sessionId-{},Host-{}", session.id(), headers.get("Host"));
|
|
|
+ ActionSocket.log.info("new connection, sessionId-{},Host-{}", session.id(), headers.get("Host"));
|
|
|
}
|
|
|
|
|
|
public void handleSessionMap(Session session) {
|
|
|
- actionSocket.socketSessionBizMap.keySet().stream().forEach(
|
|
|
+ ActionSocket.socketSessionBizMap.keySet().stream().forEach(
|
|
|
key -> {
|
|
|
if (key.contains(session.id().toString())) {
|
|
|
- actionSocket.socketSessionBizMap.get(key).interrupt();
|
|
|
- actionSocket.socketSessionBizMap.remove(key);
|
|
|
+ ActionSocket.socketSessionBizMap.get(key).interrupt();
|
|
|
+ ActionSocket.socketSessionBizMap.remove(key);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -83,7 +83,7 @@ public class actionSocket {
|
|
|
|
|
|
@OnClose
|
|
|
public void onClose(Session session) throws IOException, InterruptedException {
|
|
|
- actionSocket.log.info("one connection closed");
|
|
|
+ ActionSocket.log.info("one connection closed");
|
|
|
handleSessionMap(session);
|
|
|
}
|
|
|
|
|
@@ -95,7 +95,7 @@ public class actionSocket {
|
|
|
|
|
|
@OnMessage
|
|
|
public void onMessage(Session session, String message) throws InterruptedException {
|
|
|
- actionSocket.log.info(message);
|
|
|
+ ActionSocket.log.info(message);
|
|
|
JSONObject res = JSONUtil.createObj();
|
|
|
JSONObject data = JSONUtil.parseObj(message);
|
|
|
String action = data.getStr("action");
|
|
@@ -107,41 +107,41 @@ public class actionSocket {
|
|
|
switch (action) {
|
|
|
case "componentBiz":
|
|
|
ComponentBizImpl componentBiz = new ComponentBizImpl();
|
|
|
- String componentBizCallId = componentBiz.getCallId();
|
|
|
- if (!actionSocket.socketSessionBizMap.containsKey("componentBiz-id" + data.getInt("id") + "session" + session.id())) {
|
|
|
+ String componentBizCallId = componentBiz.getCallId(a -> a.getCallId());
|
|
|
+ if (!ActionSocket.socketSessionBizMap.containsKey("componentBiz-id" + data.getInt("id") + "session" + session.id())) {
|
|
|
Thread componentBizTodo = componentBiz.todo(session, message, componentBizCallId);
|
|
|
- actionSocket.socketSessionBizMap.put("componentBiz-id" + data.getInt("id") + "session" + session.id(), componentBizTodo);
|
|
|
+ ActionSocket.socketSessionBizMap.put("componentBiz-id" + data.getInt("id") + "session" + session.id(), componentBizTodo);
|
|
|
componentBizTodo.start();
|
|
|
componentBiz.listenResult(this::sendMessage, componentBizCallId, new ParamContext("session", session));
|
|
|
}
|
|
|
break;
|
|
|
case "modelUploadBiz":
|
|
|
ModelUploadBizImpl modelUploadBiz = new ModelUploadBizImpl();
|
|
|
- String modelUploadBizCallId = modelUploadBiz.getCallId();
|
|
|
- if (!actionSocket.socketSessionBizMap.containsKey("modelUploadBiz-id" + data.getInt("id") + "session" + session.id())) {
|
|
|
+ String modelUploadBizCallId = modelUploadBiz.getCallId(a -> a.getCallId());
|
|
|
+ if (!ActionSocket.socketSessionBizMap.containsKey("modelUploadBiz-id" + data.getInt("id") + "session" + session.id())) {
|
|
|
Thread modelUploadBizTodo = modelUploadBiz.todo(session, message, modelUploadBizCallId);
|
|
|
- actionSocket.socketSessionBizMap.put("modelUploadBiz-id" + data.getInt("id") + "session" + session.id(), modelUploadBizTodo);
|
|
|
+ ActionSocket.socketSessionBizMap.put("modelUploadBiz-id" + data.getInt("id") + "session" + session.id(), modelUploadBizTodo);
|
|
|
modelUploadBizTodo.start();
|
|
|
modelUploadBiz.listenResult(this::sendMessage, modelUploadBizCallId, new ParamContext("session", session));
|
|
|
|
|
|
}
|
|
|
break;
|
|
|
case "createImgBiz":
|
|
|
- if (!actionSocket.socketSessionBizMap.containsKey("createImgBiz-id" + data.getInt("id") + "session" + session.id())) {
|
|
|
+ if (!ActionSocket.socketSessionBizMap.containsKey("createImgBiz-id" + data.getInt("id") + "session" + session.id())) {
|
|
|
CreateImgBizImpl createImgBiz = new CreateImgBizImpl();
|
|
|
- String createImgBizCallId = createImgBiz.getCallId();
|
|
|
+ String createImgBizCallId = createImgBiz.getCallId(a -> a.getCallId());
|
|
|
Thread createImgBizTodo = createImgBiz.todo(session, message, createImgBizCallId);
|
|
|
- actionSocket.socketSessionBizMap.put("createImgBiz-id" + data.getInt("id") + "session" + session.id(), createImgBizTodo);
|
|
|
+ ActionSocket.socketSessionBizMap.put("createImgBiz-id" + data.getInt("id") + "session" + session.id(), createImgBizTodo);
|
|
|
createImgBizTodo.start();
|
|
|
createImgBiz.listenResult(this::sendMessage, createImgBizCallId, new ParamContext("session", session));
|
|
|
}
|
|
|
break;
|
|
|
case "componentCreateImgBiz":
|
|
|
- if (!actionSocket.socketSessionBizMap.containsKey("componentCreateImgBiz-id" + data.getInt("id") + "session" + session.id())) {
|
|
|
+ if (!ActionSocket.socketSessionBizMap.containsKey("componentCreateImgBiz-id" + data.getInt("id") + "session" + session.id())) {
|
|
|
ComponentCreateImgBizImpl componentCreateImgBiz = new ComponentCreateImgBizImpl();
|
|
|
- String componentCreateImgBizCallId = componentCreateImgBiz.getCallId();
|
|
|
+ String componentCreateImgBizCallId = componentCreateImgBiz.getCallId(a -> a.getCallId());
|
|
|
Thread componentCreateImgBizTodo = componentCreateImgBiz.todo(session, message, componentCreateImgBizCallId);
|
|
|
- actionSocket.socketSessionBizMap.put("componentCreateImgBiz-id" + data.getInt("id") + "session" + session.id(), componentCreateImgBizTodo);
|
|
|
+ ActionSocket.socketSessionBizMap.put("componentCreateImgBiz-id" + data.getInt("id") + "session" + session.id(), componentCreateImgBizTodo);
|
|
|
componentCreateImgBizTodo.start();
|
|
|
componentCreateImgBiz.listenResult(this::sendMessage, componentCreateImgBizCallId, new ParamContext("session", session));
|
|
|
}
|
|
@@ -183,13 +183,13 @@ public class actionSocket {
|
|
|
IdleStateEvent idleStateEvent = (IdleStateEvent) evt;
|
|
|
switch (idleStateEvent.state()) {
|
|
|
case READER_IDLE:
|
|
|
- actionSocket.log.info("read idle");
|
|
|
+ ActionSocket.log.info("read idle");
|
|
|
break;
|
|
|
case WRITER_IDLE:
|
|
|
- actionSocket.log.info("write idle");
|
|
|
+ ActionSocket.log.info("write idle");
|
|
|
break;
|
|
|
case ALL_IDLE:
|
|
|
- actionSocket.log.info("all idle");
|
|
|
+ ActionSocket.log.info("all idle");
|
|
|
break;
|
|
|
default:
|
|
|
break;
|