fix 修复 WebFluxUtils 读取空 body 报 null 问题
parent
bf89a9d416
commit
75e175f7f3
|
|
@ -1,5 +1,6 @@
|
||||||
package com.ruoyi.gateway.utils;
|
package com.ruoyi.gateway.utils;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
import com.ruoyi.common.core.utils.JsonUtils;
|
import com.ruoyi.common.core.utils.JsonUtils;
|
||||||
import com.ruoyi.common.core.utils.StringUtils;
|
import com.ruoyi.common.core.utils.StringUtils;
|
||||||
|
|
@ -79,7 +80,11 @@ public class WebFluxUtils {
|
||||||
* @return body
|
* @return body
|
||||||
*/
|
*/
|
||||||
public static String resolveBodyFromCacheRequest(ServerWebExchange exchange) {
|
public static String resolveBodyFromCacheRequest(ServerWebExchange exchange) {
|
||||||
DataBuffer buffer = (DataBuffer) exchange.getAttributes().get(ServerWebExchangeUtils.CACHED_REQUEST_BODY_ATTR);
|
Object obj = exchange.getAttributes().get(ServerWebExchangeUtils.CACHED_REQUEST_BODY_ATTR);
|
||||||
|
if (ObjectUtil.isNull(obj)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
DataBuffer buffer = (DataBuffer) obj;
|
||||||
CharBuffer charBuffer = StandardCharsets.UTF_8.decode(buffer.asByteBuffer());
|
CharBuffer charBuffer = StandardCharsets.UTF_8.decode(buffer.asByteBuffer());
|
||||||
return charBuffer.toString();
|
return charBuffer.toString();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue