|
|
@@ -120,22 +120,7 @@ public class WebSocketProcess implements ApplicationContextAware {
|
|
|
sendMessage(webSocketVo.getSenderId(), JSONObject.from(webSocketVo).toJSONString());
|
|
|
sendMessage(webSocketVo.getReceiverId(), JSONObject.from(webSocketVo).toJSONString());
|
|
|
} catch (Exception e) {
|
|
|
- log.error("WebSocketProcess.onMessage()----error----Msg={}", e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 发送消息到指定客户端
|
|
|
- */
|
|
|
- public void sendMessageBySession(String id, String message, Session session) throws Exception {
|
|
|
- log.info("WebSocketProcess.sendMessage()--readySend--type8--id={},message={}", id, message);
|
|
|
- // 根据id,从map中获取存储的webSocket对象
|
|
|
- // 当客户端是Open状态时,才能发送消息
|
|
|
- if (session.isOpen()) {
|
|
|
- session.getBasicRemote().sendText(message);
|
|
|
- log.info("WebSocketProcess.sendMessage()---sendSuccess--type8--id={},message={}", id, message);
|
|
|
- } else {
|
|
|
- log.error("WebSocketProcess.sendMessage()---sendError--type8--websocket session:{} is closed ", id);
|
|
|
+ log.error("WebSocketProcess.onMessage()----Exception----Message={}", e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -143,19 +128,23 @@ public class WebSocketProcess implements ApplicationContextAware {
|
|
|
* 发送消息到指定客户端
|
|
|
*/
|
|
|
public void sendMessage(String id, String message) throws Exception {
|
|
|
- log.info("WebSocketProcess.sendMessage()--readySend----id={},message={}", id, message);
|
|
|
- // 根据id,从map中获取存储的webSocket对象
|
|
|
- WebSocketProcess webSocketProcess = concurrentHashMap.get(id);
|
|
|
- if (!ObjectUtils.isEmpty(webSocketProcess)) {
|
|
|
- // 当客户端是Open状态时,才能发送消息
|
|
|
- if (webSocketProcess.session.isOpen()) {
|
|
|
- webSocketProcess.session.getBasicRemote().sendText(message);
|
|
|
- log.info("WebSocketProcess.sendMessage()---sendSuccess---id={},message={}", id, message);
|
|
|
+ try {
|
|
|
+ log.info("WebSocketProcess.sendMessage()--readySend----id={},message={}", id, message);
|
|
|
+ // 根据id,从map中获取存储的webSocket对象
|
|
|
+ WebSocketProcess webSocketProcess = concurrentHashMap.get(id);
|
|
|
+ if (!ObjectUtils.isEmpty(webSocketProcess)) {
|
|
|
+ // 当客户端是Open状态时,才能发送消息
|
|
|
+ if (webSocketProcess.session.isOpen()) {
|
|
|
+ webSocketProcess.session.getBasicRemote().sendText(message);
|
|
|
+ log.info("WebSocketProcess.sendMessage()---sendSuccess---id={},message={}", id, message);
|
|
|
+ } else {
|
|
|
+ log.error("WebSocketProcess.sendMessage()---sendError----websocket session:{} is closed ", id);
|
|
|
+ }
|
|
|
} else {
|
|
|
- log.error("WebSocketProcess.sendMessage()---sendError----websocket session:{} is closed ", id);
|
|
|
+ log.error("WebSocketProcess.sendMessage()---sendError----websocket session:{} is not exit ", id);
|
|
|
}
|
|
|
- } else {
|
|
|
- log.error("WebSocketProcess.sendMessage()---sendError----websocket session:{} is not exit ", id);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("WebSocketProcess.sendMessage()---Exception----Message={}", e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -164,17 +153,20 @@ public class WebSocketProcess implements ApplicationContextAware {
|
|
|
* */
|
|
|
@OnOpen
|
|
|
public void onOpen(@PathParam("sendId") String id, Session session) {
|
|
|
- //每新建立一个连接,就把当前客户id为key,this为value存储到map中
|
|
|
- this.session = session;
|
|
|
- concurrentHashMap.put(id, this);
|
|
|
- log.info("WebSocketProcess.onOpen() Open a websocket. id={}", id);
|
|
|
-
|
|
|
- // 获取拉黑自己的用户信息
|
|
|
- LambdaQueryWrapper<LifeBlacklist> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(LifeBlacklist::getBlockedPhoneId, id);
|
|
|
- List<String> blackList = lifeBlacklistMapper.selectList(wrapper).stream().map(LifeBlacklist::getBlockerPhoneId).collect(Collectors.toList());
|
|
|
- if (CollectionUtil.isNotEmpty(blackList))
|
|
|
- baseRedisService.setSaveOrOverwriteScriptList("blackList_" + id, blackList);
|
|
|
+ try {
|
|
|
+ //每新建立一个连接,就把当前客户id为key,this为value存储到map中
|
|
|
+ this.session = session;
|
|
|
+ concurrentHashMap.put(id, this);
|
|
|
+ log.info("WebSocketProcess.onOpen() Open a websocket. id={}", id);
|
|
|
+
|
|
|
+ // 获取拉黑自己的用户信息
|
|
|
+ LambdaQueryWrapper<LifeBlacklist> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(LifeBlacklist::getBlockedPhoneId, id);
|
|
|
+ List<String> blackList = lifeBlacklistMapper.selectList(wrapper).stream().map(LifeBlacklist::getBlockerPhoneId).collect(Collectors.toList());
|
|
|
+ if (CollectionUtil.isNotEmpty(blackList)) baseRedisService.setSaveOrOverwriteScriptList("blackList_" + id, blackList);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("WebSocketProcess.onOpen()----Exception----Message={}", e.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -183,10 +175,14 @@ public class WebSocketProcess implements ApplicationContextAware {
|
|
|
**/
|
|
|
@OnClose
|
|
|
public void onClose(Session session, @PathParam("sendId") String id) {
|
|
|
- //客户端连接关闭时,移除map中存储的键值对
|
|
|
- concurrentHashMap.remove(id);
|
|
|
- log.info("WebSocketProcess.onClose() close a websocket, concurrentHashMap remove sessionId= {}", id);
|
|
|
- if (baseRedisService.hasKey("blackList_" + id)) baseRedisService.delete("blackList_" + id);
|
|
|
+ try {
|
|
|
+ //客户端连接关闭时,移除map中存储的键值对
|
|
|
+ concurrentHashMap.remove(id);
|
|
|
+ log.info("WebSocketProcess.onClose() close a websocket, concurrentHashMap remove sessionId= {}", id);
|
|
|
+ if (baseRedisService.hasKey("blackList_" + id)) baseRedisService.delete("blackList_" + id);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("WebSocketProcess.onClose()----Exception----Message={}", e.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -194,25 +190,34 @@ public class WebSocketProcess implements ApplicationContextAware {
|
|
|
*/
|
|
|
@OnError
|
|
|
public void onError(@PathParam("sendId") String id, Throwable error) {
|
|
|
- log.error("WebSocketProcess.onError() Error,id={}, Msg=", id, error);
|
|
|
+ try {
|
|
|
+ log.error("WebSocketProcess.onError() Error,id={}, Msg=", id, error);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("WebSocketProcess.onError()----Exception----Message={}", e.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 验证消息合规性
|
|
|
*/
|
|
|
private boolean checkCompliance(WebSocketVo websocketVo) throws Exception {
|
|
|
- List<String> servicesList = Lists.newArrayList();
|
|
|
- TextModerationResultVO textModerationResultVO = null;
|
|
|
- if ("1".equals(websocketVo.getType())) {
|
|
|
- servicesList.add(TextReviewServiceEnum.AD_COMPLIANCE_DETECTION_PRO.getService());
|
|
|
- servicesList.add(TextReviewServiceEnum.CHAT_DETECTION_PRO.getService());
|
|
|
- textModerationResultVO = textModerationUtil.invokeFunction(websocketVo.getText(), servicesList);
|
|
|
-
|
|
|
- } else if ("2".equals(websocketVo.getType())) {
|
|
|
- servicesList.add(ImageReviewServiceEnum.TONALITY_IMPROVE.getService());
|
|
|
- textModerationResultVO = textModerationUtil.invokeFunction(websocketVo.getText(), servicesList);
|
|
|
+ try {
|
|
|
+ List<String> servicesList = Lists.newArrayList();
|
|
|
+ TextModerationResultVO textModerationResultVO = null;
|
|
|
+ if ("1".equals(websocketVo.getType())) {
|
|
|
+ servicesList.add(TextReviewServiceEnum.AD_COMPLIANCE_DETECTION_PRO.getService());
|
|
|
+ servicesList.add(TextReviewServiceEnum.CHAT_DETECTION_PRO.getService());
|
|
|
+ textModerationResultVO = textModerationUtil.invokeFunction(websocketVo.getText(), servicesList);
|
|
|
+
|
|
|
+ } else if ("2".equals(websocketVo.getType())) {
|
|
|
+ servicesList.add(ImageReviewServiceEnum.TONALITY_IMPROVE.getService());
|
|
|
+ textModerationResultVO = textModerationUtil.invokeFunction(websocketVo.getText(), servicesList);
|
|
|
+ }
|
|
|
+ return !(null != textModerationResultVO && "high".equals(textModerationResultVO.getRiskLevel()));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("WebSocketProcess.checkCompliance()----Exception----Message={}", e.getMessage());
|
|
|
+ return true;
|
|
|
}
|
|
|
- return !(null != textModerationResultVO && "high".equals(textModerationResultVO.getRiskLevel()));
|
|
|
}
|
|
|
|
|
|
/**
|