fix(接口测试): 修复mock-server解析请求参数报错的缺陷

This commit is contained in:
Jianguo-Genius 2024-07-15 18:24:39 +08:00 committed by Craftsman
parent f4b277125c
commit 1609701cb1
1 changed files with 4 additions and 3 deletions

View File

@ -46,12 +46,13 @@ public class MockServerUtils {
try { try {
if (request instanceof ShiroHttpServletRequest shiroHttpServletRequest) { if (request instanceof ShiroHttpServletRequest shiroHttpServletRequest) {
String contentType = StringUtils.isBlank(request.getContentType()) ? StringUtils.EMPTY : request.getContentType();
List<String> contentTypeLists = List.of(MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE, MediaType.TEXT_PLAIN_VALUE); List<String> contentTypeLists = List.of(MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE, MediaType.TEXT_PLAIN_VALUE);
if (StringUtils.equals(request.getContentType(), MediaType.APPLICATION_OCTET_STREAM_VALUE)) { if (StringUtils.equals(contentType, MediaType.APPLICATION_OCTET_STREAM_VALUE)) {
InputStream inputStream = shiroHttpServletRequest.getRequest().getInputStream(); InputStream inputStream = shiroHttpServletRequest.getRequest().getInputStream();
byte[] binaryParams = inputStream.readAllBytes(); byte[] binaryParams = inputStream.readAllBytes();
requestParam.setBinaryParamsObj(binaryParams); requestParam.setBinaryParamsObj(binaryParams);
} else if (contentTypeLists.contains(request.getContentType())) { } else if (contentTypeLists.contains(contentType)) {
String inputLine; String inputLine;
StringBuilder receiveData = new StringBuilder(); StringBuilder receiveData = new StringBuilder();
try (BufferedReader in = new BufferedReader(new InputStreamReader( try (BufferedReader in = new BufferedReader(new InputStreamReader(
@ -61,7 +62,7 @@ public class MockServerUtils {
} }
} }
requestPostString = receiveData.toString(); requestPostString = receiveData.toString();
} else if (StringUtils.equals(request.getContentType(), MediaType.APPLICATION_FORM_URLENCODED_VALUE)) { } else if (StringUtils.equals(contentType, MediaType.APPLICATION_FORM_URLENCODED_VALUE)) {
Map<String, String[]> parameterMap = request.getParameterMap(); Map<String, String[]> parameterMap = request.getParameterMap();
LinkedHashMap<String, String> bodyParams = new LinkedHashMap<>(); LinkedHashMap<String, String> bodyParams = new LinkedHashMap<>();
if (parameterMap != null && !parameterMap.isEmpty()) { if (parameterMap != null && !parameterMap.isEmpty()) {