From 9d9c5ced4cbd1d791ef03ec346b309b8297f8cce Mon Sep 17 00:00:00 2001 From: tanghc Date: Thu, 15 Aug 2019 18:07:30 +0800 Subject: [PATCH] =?UTF-8?q?gateway=E6=94=AF=E6=8C=81=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gateway/ServerWebExchangeUtil.java | 17 ++++++++++++++-- .../gateway/common/ServletFileUploadUtil.java | 20 ------------------- 2 files changed, 15 insertions(+), 22 deletions(-) delete mode 100644 sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/common/ServletFileUploadUtil.java diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/ServerWebExchangeUtil.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/ServerWebExchangeUtil.java index e5aa91ac..09848028 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/ServerWebExchangeUtil.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/ServerWebExchangeUtil.java @@ -2,7 +2,7 @@ package com.gitee.sop.gatewaycommon.gateway; import com.alibaba.fastjson.JSON; import com.gitee.sop.gatewaycommon.bean.SopConstants; -import com.gitee.sop.gatewaycommon.gateway.common.ServletFileUploadUtil; +import com.gitee.sop.gatewaycommon.gateway.common.FileUploadHttpServletRequest; import com.gitee.sop.gatewaycommon.param.ApiParam; import com.gitee.sop.gatewaycommon.util.RequestUtil; import org.apache.commons.lang3.StringUtils; @@ -14,6 +14,7 @@ import org.springframework.util.MultiValueMap; import org.springframework.web.server.ServerWebExchange; import javax.servlet.http.HttpServletRequest; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -69,7 +70,7 @@ public class ServerWebExchangeUtil { params = JSON.parseObject(cachedBody); } else if (StringUtils.containsIgnoreCase(contentTypeStr, "multipart")) { // 如果是文件上传请求 - HttpServletRequest fileUploadRequest = ServletFileUploadUtil.getFileUploadRequest(exchange, cachedBody); + HttpServletRequest fileUploadRequest = getFileUploadRequest(exchange, cachedBody); params = RequestUtil.convertMultipartRequestToMap(fileUploadRequest); } else { params = RequestUtil.parseQueryToMap(cachedBody); @@ -112,5 +113,17 @@ public class ServerWebExchangeUtil { .build(); } + /** + * 获取一个文件上传request + * + * @param exchange 当前ServerWebExchange + * @param requestBody 上传文件请求体内容 + * @return 返回文件上传request + */ + public static HttpServletRequest getFileUploadRequest(ServerWebExchange exchange, String requestBody) { + byte[] data = requestBody.getBytes(StandardCharsets.UTF_8); + return new FileUploadHttpServletRequest(exchange.getRequest(), data); + } + } diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/common/ServletFileUploadUtil.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/common/ServletFileUploadUtil.java deleted file mode 100644 index 9cb299c6..00000000 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/common/ServletFileUploadUtil.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.gitee.sop.gatewaycommon.gateway.common; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.server.ServerWebExchange; - -import javax.servlet.http.HttpServletRequest; -import java.nio.charset.StandardCharsets; - -/** - * @author tanghc - */ -@Slf4j -public class ServletFileUploadUtil { - - public static HttpServletRequest getFileUploadRequest(ServerWebExchange exchange, String requestBody) { - byte[] data = requestBody.getBytes(StandardCharsets.UTF_8); - return new FileUploadHttpServletRequest(exchange.getRequest(), data); - } - -}