|
|
|
@ -1,6 +1,5 @@
|
|
|
|
|
package com.supervision.chat.client.dto;
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import com.supervision.chat.client.dto.chat.ChatResDTO;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
@ -15,6 +14,8 @@ import org.springframework.util.StreamUtils;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @description 这个转换类写的很粗糙,只进行了解析处理,后续有需要再继续处理
|
|
|
|
@ -49,11 +50,20 @@ public class ChatResConverter implements HttpMessageConverter {
|
|
|
|
|
// 去除 "data:" 前缀
|
|
|
|
|
if (body.startsWith("data:")) {
|
|
|
|
|
body = body.substring(5).trim();
|
|
|
|
|
}else {
|
|
|
|
|
// 去除 ping....data: 前缀
|
|
|
|
|
String regex = "ping\\s+.*?data:";
|
|
|
|
|
Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
|
|
|
|
|
Matcher matcher = pattern.matcher(body);
|
|
|
|
|
// 使用空字符串替换匹配的部分
|
|
|
|
|
body = matcher.replaceFirst("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// regx ping..*data:{}
|
|
|
|
|
// 将去除前缀后的内容解析为 ResponseData 对象
|
|
|
|
|
try {
|
|
|
|
|
return objectMapper.readValue(body, ChatResDTO.class);
|
|
|
|
|
} catch (JsonProcessingException e) {
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("ChatResConverter:read error: {}", e.getMessage(), e);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|