18339543638 пре 3 година
родитељ
комит
7e72723549

+ 1 - 1
nb-common/ws-common/src/main/java/com/nb/common/websocket/msg/handler/IMsgRequestHandler.java

@@ -40,7 +40,7 @@ public interface IMsgRequestHandler {
      * @param topicWrapper 主题
      * @return void
      */
-    void handler(MessagingRequest message, ChannelContext channelContext, TopicWrapper topicWrapper) throws JsonProcessingException;
+    void handler(MessagingRequest message, ChannelContext channelContext, TopicWrapper topicWrapper);
 
     /**
      * 描述: 获取序列化方式

+ 16 - 4
nb-im/src/main/java/com/nb/im/ws/PubMsgRequestHandler.java

@@ -11,6 +11,7 @@ import com.nb.common.websocket.PubResponse;
 import com.nb.common.websocket.TopicMessage;
 import com.nb.common.websocket.filter.PubMsgFilter;
 import com.nb.common.websocket.handler.TopicWrapper;
+import com.nb.common.websocket.msg.MessageResponse;
 import com.nb.common.websocket.msg.MessagingRequest;
 import com.nb.common.websocket.msg.handler.IMsgRequestHandler;
 import com.nb.im.entity.ImMsgEntity;
@@ -58,15 +59,26 @@ public class PubMsgRequestHandler implements IMsgRequestHandler {
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public void handler(MessagingRequest message, ChannelContext channelContext, TopicWrapper topicWrapper) throws JsonProcessingException {
+    public void handler(MessagingRequest message, ChannelContext channelContext, TopicWrapper topicWrapper) {
         String param = topicWrapper.getParam();
         if(CollectionUtil.isNotEmpty(msgFilters)){
             boolean result = msgFilters.stream()
                     .allMatch(filter -> filter.doFilter(channelContext, message));
             if(result){
-                PubMsgInfo pubMsgInfo = objectMapper.readerFor(PubMsgInfo.class).readValue(String.valueOf(message.getPayload()));
-                pubMsgInfo.setOperationType(MsgEnum.NORMAL);
-                imUtils.send(param,topicWrapper,pubMsgInfo,channelContext,false);
+                try {
+                    PubMsgInfo pubMsgInfo = objectMapper.readerFor(PubMsgInfo.class).readValue(String.valueOf(message.getPayload()));
+                    pubMsgInfo.setOperationType(MsgEnum.NORMAL);
+                    imUtils.send(param,topicWrapper,pubMsgInfo,channelContext,false);
+                }catch (Exception e){
+                    log.error("PubMsgRequestHandler.handler msg confront error,",e);
+                    Tio.send(channelContext, WsResponse.fromText(JSONUtil.toJsonStr(
+                            MessageResponse.of("im","im-result",
+                                    param,
+                                    PubResponse.fail(message.getKey(),"解析错误,发送失败"),
+                                    message.getKey())
+
+                    ), WsPacket.CHARSET_NAME));
+                }
             }
         }
     }