fix(接口测试): 修复接口调试偶发接收不到结果问题
https://github.com/metersphere/metersphere/issues/13725
This commit is contained in:
parent
e0761b9ac0
commit
1b3152f8aa
|
@ -1,6 +1,7 @@
|
|||
package io.metersphere.websocket.c.to.c;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import io.metersphere.utils.LoggerUtil;
|
||||
import io.metersphere.websocket.c.to.c.util.MsgDto;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -21,7 +22,11 @@ public class IndexWebSocket {
|
|||
@OnOpen
|
||||
public void openSession(@PathParam("reportId") String reportId, Session session) {
|
||||
WebSocketUtils.ONLINE_USER_SESSIONS.put(reportId, session);
|
||||
log.info("客户端: [" + reportId + "] : 连接成功!" + WebSocketUtils.ONLINE_USER_SESSIONS.size());
|
||||
RemoteEndpoint.Async async = session.getAsyncRemote();
|
||||
if (async != null) {
|
||||
async.sendText("CONN_SUCCEEDED");
|
||||
}
|
||||
LoggerUtil.info("客户端: [" + reportId + "] : 连接成功!" + WebSocketUtils.ONLINE_USER_SESSIONS.size());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,7 +34,7 @@ public class IndexWebSocket {
|
|||
*/
|
||||
@OnMessage
|
||||
public void onMessage(@PathParam("reportId") String reportId, String message) {
|
||||
log.info("服务器收到:[" + reportId + "] : " + message);
|
||||
LoggerUtil.info("服务器收到:[" + reportId + "] : " + message);
|
||||
MsgDto dto = JSON.parseObject(message, MsgDto.class);
|
||||
dto.setContent(dto.getContent());
|
||||
WebSocketUtils.sendMessageSingle(dto);
|
||||
|
@ -42,7 +47,7 @@ public class IndexWebSocket {
|
|||
public void onClose(@PathParam("reportId") String reportId, Session session) throws IOException {
|
||||
//当前的Session 移除
|
||||
WebSocketUtils.ONLINE_USER_SESSIONS.remove(reportId);
|
||||
log.info("[" + reportId + "] : 断开连接!" + WebSocketUtils.ONLINE_USER_SESSIONS.size());
|
||||
LoggerUtil.info("[" + reportId + "] : 断开连接!" + WebSocketUtils.ONLINE_USER_SESSIONS.size());
|
||||
//并且通知其他人当前用户已经断开连接了
|
||||
session.close();
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ export default {
|
|||
watch: {
|
||||
reportId() {
|
||||
// 开启链接
|
||||
this.socketSyncResult();
|
||||
this.socketSync();
|
||||
},
|
||||
isStop() {
|
||||
if (!this.isStop && this.websocket && this.websocket.close instanceof Function) {
|
||||
|
@ -45,7 +45,7 @@ export default {
|
|||
}
|
||||
},
|
||||
methods: {
|
||||
socketSyncResult() {
|
||||
socketSync() {
|
||||
let protocol = "ws://";
|
||||
if (window.location.protocol === 'https:') {
|
||||
protocol = "wss://";
|
||||
|
@ -53,10 +53,18 @@ export default {
|
|||
const uri = protocol + window.location.host + "/ws/" + this.reportId;
|
||||
this.websocket = new WebSocket(uri);
|
||||
this.websocket.onmessage = this.onMessages;
|
||||
// 开始执行
|
||||
this.websocket.onopen = this.run();
|
||||
this.websocket.onerror = this.onError;
|
||||
},
|
||||
onError(){
|
||||
this.$emit('runRefresh', "");
|
||||
this.$error("The connection is abnormal, please check the environment configuration");
|
||||
},
|
||||
onMessages(e) {
|
||||
// 确认连接建立成功,开始执行
|
||||
if(e && e.data === "CONN_SUCCEEDED"){
|
||||
this.run();
|
||||
}
|
||||
|
||||
if (e.data && e.data.startsWith("result_")) {
|
||||
try {
|
||||
let data = e.data.substring(7);
|
||||
|
|
Loading…
Reference in New Issue