域名替换fixed_最终版本
This commit is contained in:
@@ -6,6 +6,8 @@ import com.accompany.common.utils.EnvComponent;
|
||||
import com.accompany.core.vo.BaseResponseVO;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -34,15 +36,15 @@ public class ResponseDataHandler implements ResponseBodyAdvice {
|
||||
@Override
|
||||
public Object beforeBodyWrite(Object body, MethodParameter methodParameter, MediaType mediaType, Class selectedConverterType,
|
||||
ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse) {
|
||||
if (envComponent.getDevOrNativeEnv()) {
|
||||
return body;
|
||||
}
|
||||
if (body == null) {
|
||||
if (envComponent.getDevOrNativeEnv() || body == null) {
|
||||
return body;
|
||||
}
|
||||
try {
|
||||
// 2. 安全获取真实类(处理代理和null)
|
||||
Class<?> targetClass = getTargetClass(body);
|
||||
|
||||
String uri = serverHttpRequest.getURI().getPath();
|
||||
if (body instanceof BusiResult) {
|
||||
if (BusiResult.class.isAssignableFrom(targetClass)) {
|
||||
BusiResult result = (BusiResult) body;
|
||||
Object data = result.getData();
|
||||
if (null != data) {
|
||||
@@ -54,7 +56,7 @@ public class ResponseDataHandler implements ResponseBodyAdvice {
|
||||
result.setData(JSONObject.parseObject(json, Object.class));
|
||||
return result;
|
||||
}
|
||||
} else if (body instanceof BaseResponseVO) {
|
||||
} else if (BaseResponseVO.class.isAssignableFrom(targetClass)) {
|
||||
BaseResponseVO result = (BaseResponseVO) body;
|
||||
Object data = result.getData();
|
||||
if (null != data) {
|
||||
@@ -90,4 +92,19 @@ public class ResponseDataHandler implements ResponseBodyAdvice {
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
// 辅助方法:获取真实类(处理代理)
|
||||
private Class<?> getTargetClass(Object obj) {
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
if (AopUtils.isAopProxy(obj)) { // Spring AOP 代理
|
||||
return AopUtils.getTargetClass(obj);
|
||||
}
|
||||
if (obj instanceof Advised) { // JDK 动态代理
|
||||
return ((Advised) obj).getTargetSource().getTargetClass();
|
||||
}
|
||||
return obj.getClass();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user