From 75e175f7f32d123a0bd7f8e3afe601e0a58de0be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Fri, 18 Nov 2022 23:46:54 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20WebFluxUtils=20?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E7=A9=BA=20body=20=E6=8A=A5=20null=20?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/ruoyi/gateway/utils/WebFluxUtils.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/utils/WebFluxUtils.java b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/utils/WebFluxUtils.java index 2d06873b..38a32523 100644 --- a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/utils/WebFluxUtils.java +++ b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/utils/WebFluxUtils.java @@ -1,5 +1,6 @@ package com.ruoyi.gateway.utils; +import cn.hutool.core.util.ObjectUtil; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.utils.JsonUtils; import com.ruoyi.common.core.utils.StringUtils; @@ -79,7 +80,11 @@ public class WebFluxUtils { * @return body */ 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()); return charBuffer.toString(); }