|
|
@ -2,7 +2,7 @@ package com.gitee.sop.gatewaycommon.gateway; |
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.gitee.sop.gatewaycommon.bean.SopConstants; |
|
|
|
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.param.ApiParam; |
|
|
|
import com.gitee.sop.gatewaycommon.util.RequestUtil; |
|
|
|
import com.gitee.sop.gatewaycommon.util.RequestUtil; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
@ -14,6 +14,7 @@ import org.springframework.util.MultiValueMap; |
|
|
|
import org.springframework.web.server.ServerWebExchange; |
|
|
|
import org.springframework.web.server.ServerWebExchange; |
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
@ -69,7 +70,7 @@ public class ServerWebExchangeUtil { |
|
|
|
params = JSON.parseObject(cachedBody); |
|
|
|
params = JSON.parseObject(cachedBody); |
|
|
|
} else if (StringUtils.containsIgnoreCase(contentTypeStr, "multipart")) { |
|
|
|
} else if (StringUtils.containsIgnoreCase(contentTypeStr, "multipart")) { |
|
|
|
// 如果是文件上传请求
|
|
|
|
// 如果是文件上传请求
|
|
|
|
HttpServletRequest fileUploadRequest = ServletFileUploadUtil.getFileUploadRequest(exchange, cachedBody); |
|
|
|
HttpServletRequest fileUploadRequest = getFileUploadRequest(exchange, cachedBody); |
|
|
|
params = RequestUtil.convertMultipartRequestToMap(fileUploadRequest); |
|
|
|
params = RequestUtil.convertMultipartRequestToMap(fileUploadRequest); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
params = RequestUtil.parseQueryToMap(cachedBody); |
|
|
|
params = RequestUtil.parseQueryToMap(cachedBody); |
|
|
@ -112,5 +113,17 @@ public class ServerWebExchangeUtil { |
|
|
|
.build(); |
|
|
|
.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); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|