From d5fd36b35ea4d8f9c7781d5bfcba8cfe4c5f186f Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Thu, 21 Oct 2021 18:30:29 +0800 Subject: [PATCH] =?UTF-8?q?fix(Mock=E6=B5=8B=E8=AF=95):=20mock=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=9A=84=E5=8C=B9=E9=85=8D=E6=96=B9=E5=BC=8F=E6=94=B9?= =?UTF-8?q?=E4=B8=BAquery=E3=80=81rest=E3=80=81body=E5=85=A8=E5=8C=B9?= =?UTF-8?q?=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit mock测试的匹配方式改为query、rest、body全匹配 --- .../api/dto/mock/MockApiUtils.java | 203 ++++++++++ .../api/service/MockConfigService.java | 357 +++++------------- 2 files changed, 290 insertions(+), 270 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/mock/MockApiUtils.java b/backend/src/main/java/io/metersphere/api/dto/mock/MockApiUtils.java index e0c6c185f5..75f87bb4df 100644 --- a/backend/src/main/java/io/metersphere/api/dto/mock/MockApiUtils.java +++ b/backend/src/main/java/io/metersphere/api/dto/mock/MockApiUtils.java @@ -1,9 +1,11 @@ package io.metersphere.api.dto.mock; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONValidator; import io.metersphere.api.dto.mockconfig.response.JsonSchemaReturnObj; +import io.metersphere.base.domain.ApiDefinitionWithBLOBs; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.json.JSONSchemaGenerator; import io.metersphere.commons.utils.XMLUtils; @@ -12,8 +14,10 @@ import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.jmeter.protocol.java.sampler.JSR223Sampler; import org.apache.jmeter.samplers.SampleResult; +import org.json.XML; import javax.servlet.http.HttpServletRequest; +import java.io.*; import java.util.*; /** @@ -435,4 +439,203 @@ public class MockApiUtils { SampleResult result = jmeterScriptSampler.sample(null); System.out.println(result.getResponseData()); } + + public static RequestMockParams getParams(String urlParams, ApiDefinitionWithBLOBs api, HttpServletRequest request){ + RequestMockParams returnParams = getGetParamMap(urlParams,api,request); + JSON paramJson = getPostParamMap(request); + if (paramJson instanceof JSONObject) { + JSONArray paramsArray = new JSONArray(); + paramsArray.add(paramJson); + returnParams.setBodyParams(paramsArray); + } else if (paramJson instanceof JSONArray) { + JSONArray paramArray = (JSONArray) paramJson; + returnParams.setBodyParams(paramArray); + } + return returnParams; + } + + private static RequestMockParams getGetParamMap(String urlParams, ApiDefinitionWithBLOBs api, HttpServletRequest request) { + RequestMockParams requestMockParams = new RequestMockParams(); + + JSONObject urlParamsObject = getSendRestParamMapByIdAndUrl(api, urlParams); + + JSONObject queryParamsObject = new JSONObject(); + Enumeration paramNameItor = request.getParameterNames(); + while (paramNameItor.hasMoreElements()) { + String key = paramNameItor.nextElement(); + String value = request.getParameter(key); + queryParamsObject.put(key, value); + } + + requestMockParams.setRestParamsObj(urlParamsObject); + requestMockParams.setQueryParamsObj(queryParamsObject); + return requestMockParams; + } + + private static JSON getPostParamMap(HttpServletRequest request) { + if (StringUtils.equalsIgnoreCase("application/JSON", request.getContentType())) { + JSON returnJson = null; + try { + String param = getRequestPostStr(request); + JSONValidator jsonValidator = JSONValidator.from(param); + if (StringUtils.equalsIgnoreCase("Array", jsonValidator.getType().name())) { + returnJson = JSONArray.parseArray(param); + } else if (StringUtils.equalsIgnoreCase("Object", jsonValidator.getType().name())) { + returnJson = JSONObject.parseObject(param); + } + } catch (Exception e) { + e.printStackTrace(); + } + return returnJson; + } else if (StringUtils.equalsIgnoreCase("text/xml", request.getContentType())) { + String xmlString = readXml(request); + System.out.println(xmlString); + + org.json.JSONObject xmlJSONObj = XML.toJSONObject(xmlString); + String jsonStr = xmlJSONObj.toString(); + JSONObject object = null; + try { + object = JSONObject.parseObject(jsonStr); + } catch (Exception e) { + } + return object; + } else if (StringUtils.equalsIgnoreCase("application/x-www-form-urlencoded", request.getContentType())) { + JSONObject object = new JSONObject(); + Enumeration paramNameItor = request.getParameterNames(); + while (paramNameItor.hasMoreElements()) { + String key = paramNameItor.nextElement(); + String value = request.getParameter(key); + object.put(key, value); + } + return object; + } else { + JSONObject object = new JSONObject(); + String bodyParam = readBody(request); + object.put("raw",bodyParam); + + Enumeration paramNameItor = request.getParameterNames(); + while (paramNameItor.hasMoreElements()) { + String key = paramNameItor.nextElement(); + String value = request.getParameter(key); + object.put(key, value); + } + return object; + } + } + + private static JSONObject getSendRestParamMapByIdAndUrl(ApiDefinitionWithBLOBs api, String urlParams) { + JSONObject returnJson = new JSONObject(); + if (api != null) { + String path = api.getPath(); + if (path.startsWith("/")) { + path = path.substring(1); + } + String[] pathArr = path.split("/"); + String[] sendParamArr = urlParams.split("/"); + + //获取 url的<参数名-参数值>,通过匹配api的接口设置和实际发送的url + for (int i = 0; i < pathArr.length; i++) { + String param = pathArr[i]; + if (param.startsWith("{") && param.endsWith("}")) { + param = param.substring(1, param.length() - 1); + String value = ""; + if (sendParamArr.length > i) { + value = sendParamArr[i]; + } + returnJson.put(param, value); + } + } + + } + return returnJson; + } + private static String readBody(HttpServletRequest request) { + String result = ""; + try { + InputStream inputStream = request.getInputStream(); + ByteArrayOutputStream outSteam = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + int len; + while ((len = inputStream.read(buffer)) != -1) { + outSteam.write(buffer, 0, len); + } + outSteam.close(); + inputStream.close(); + result = new String(outSteam.toByteArray(), "UTF-8"); + } catch (Exception e) { + e.printStackTrace(); + } + return result; + } + + /** + * 描述:获取 post 请求内容 + *
+     * 举例:
+     * 
+ * + * @param request + * @return + * @throws IOException + */ + private static String getRequestPostStr(HttpServletRequest request) throws IOException { + byte buffer[] = getRequestPostBytes(request); + String charEncoding = request.getCharacterEncoding(); + if (charEncoding == null) { + charEncoding = "UTF-8"; + } + return new String(buffer, charEncoding); + } + + private static String readXml(HttpServletRequest request) { + String inputLine = null; + // 接收到的数据 + StringBuffer recieveData = new StringBuffer(); + BufferedReader in = null; + try { + in = new BufferedReader(new InputStreamReader( + request.getInputStream(), "UTF-8")); + while ((inputLine = in.readLine()) != null) { + recieveData.append(inputLine); + } + } catch (IOException e) { + } finally { + try { + if (null != in) { + in.close(); + } + } catch (IOException e) { + } + } + + return recieveData.toString(); + } + + /** + * 描述:获取 post 请求的 byte[] 数组 + *
+     * 举例:
+     * 
+ * + * @param request + * @return + * @throws IOException + */ + private static byte[] getRequestPostBytes(HttpServletRequest request) throws IOException { + int contentLength = request.getContentLength(); + if (contentLength < 0) { + return null; + } + byte buffer[] = new byte[contentLength]; + for (int i = 0; i < contentLength; ) { + + int readlen = request.getInputStream().read(buffer, i, + contentLength - i); + if (readlen == -1) { + break; + } + i += readlen; + } + return buffer; + } } diff --git a/backend/src/main/java/io/metersphere/api/service/MockConfigService.java b/backend/src/main/java/io/metersphere/api/service/MockConfigService.java index 520cf85bcc..07b730bc91 100644 --- a/backend/src/main/java/io/metersphere/api/service/MockConfigService.java +++ b/backend/src/main/java/io/metersphere/api/service/MockConfigService.java @@ -298,32 +298,56 @@ public class MockConfigService { } } - JSONArray jsonArray = requestMockParams.getBodyParams(); - if (jsonArray == null) { - //url or get 参数 - JSONArray argumentsArray = expectParamsObj.getJSONArray("arguments"); - JSONArray restArray = expectParamsObj.getJSONArray("rest"); - - JSONObject urlRequestParamObj = MockApiUtils.getParams(argumentsArray); - JSONObject restRequestParamObj = MockApiUtils.getParams(restArray); - - if (requestMockParams.getQueryParamsObj() == null || requestMockParams.getQueryParamsObj().isEmpty()) { - return JsonStructUtils.checkJsonObjCompliance(requestMockParams.getRestParamsObj(), restRequestParamObj); - } else if (requestMockParams.getRestParamsObj() == null || requestMockParams.getRestParamsObj().isEmpty()) { - return JsonStructUtils.checkJsonObjCompliance(requestMockParams.getQueryParamsObj(), urlRequestParamObj); - } else { - return JsonStructUtils.checkJsonObjCompliance(requestMockParams.getQueryParamsObj(), urlRequestParamObj) - && JsonStructUtils.checkJsonObjCompliance(requestMockParams.getRestParamsObj(), restRequestParamObj); - } - - } else { - // body参数 + if(expectParamsObj.containsKey("body")){ JSONObject expectBodyObject = expectParamsObj.getJSONObject("body"); JSONArray mockExpectJsonArray = MockApiUtils.getExpectBodyParams(expectBodyObject); - - return JsonStructUtils.checkJsonArrayCompliance(jsonArray, mockExpectJsonArray); + JSONArray jsonArray = requestMockParams.getBodyParams(); + if(!JsonStructUtils.checkJsonArrayCompliance(jsonArray, mockExpectJsonArray)){ + return false; + } } + if(expectParamsObj.containsKey("arguments")){ + JSONArray argumentsArray = expectParamsObj.getJSONArray("arguments"); + JSONObject urlRequestParamObj = MockApiUtils.getParams(argumentsArray); + if(!JsonStructUtils.checkJsonObjCompliance(requestMockParams.getQueryParamsObj(), urlRequestParamObj)){ + return false; + } + } + + if(expectParamsObj.containsKey("rest")){ + JSONArray restArray = expectParamsObj.getJSONArray("rest"); + JSONObject restRequestParamObj = MockApiUtils.getParams(restArray); + if(!JsonStructUtils.checkJsonObjCompliance(requestMockParams.getRestParamsObj(), restRequestParamObj)){ + return false; + } + } +// JSONArray jsonArray = requestMockParams.getBodyParams(); +// if (jsonArray == null) { +// //url or get 参数 +// JSONArray argumentsArray = expectParamsObj.getJSONArray("arguments"); +// JSONArray restArray = expectParamsObj.getJSONArray("rest"); +// +// JSONObject urlRequestParamObj = MockApiUtils.getParams(argumentsArray); +// JSONObject restRequestParamObj = MockApiUtils.getParams(restArray); +// +// if (requestMockParams.getQueryParamsObj() == null || requestMockParams.getQueryParamsObj().isEmpty()) { +// return JsonStructUtils.checkJsonObjCompliance(requestMockParams.getRestParamsObj(), restRequestParamObj); +// } else if (requestMockParams.getRestParamsObj() == null || requestMockParams.getRestParamsObj().isEmpty()) { +// return JsonStructUtils.checkJsonObjCompliance(requestMockParams.getQueryParamsObj(), urlRequestParamObj); +// } else { +// return JsonStructUtils.checkJsonObjCompliance(requestMockParams.getQueryParamsObj(), urlRequestParamObj) +// && JsonStructUtils.checkJsonObjCompliance(requestMockParams.getRestParamsObj(), restRequestParamObj); +// } +// +// } else { +// // body参数 +// JSONObject expectBodyObject = expectParamsObj.getJSONObject("body"); +// JSONArray mockExpectJsonArray = MockApiUtils.getExpectBodyParams(expectBodyObject); +// +// return JsonStructUtils.checkJsonArrayCompliance(jsonArray, mockExpectJsonArray); +// } + // JSONObject mockExpectJson = new JSONObject(); // if (isJsonParam) { // String jsonParams = mockExpectRequestObj.getString("jsonData"); @@ -357,7 +381,7 @@ public class MockConfigService { // } // boolean isMatching = JsonStructUtils.checkJsonObjCompliance(mockExpectRequestObj, mockExpectJson); -// return isMatching; + return true; } private boolean isRequestMockExpectMatching(JSONObject mockExpectRequestObj, JSONObject reqJsonObj) { @@ -869,156 +893,6 @@ public class MockConfigService { } mockConfigMapper.deleteByExample(configExample); } - - public RequestMockParams getGetParamMap(String urlParams, ApiDefinitionWithBLOBs api, HttpServletRequest request) { - RequestMockParams requestMockParams = new RequestMockParams(); - - JSONObject urlParamsObject = this.getSendRestParamMapByIdAndUrl(api, urlParams); - - JSONObject queryParamsObject = new JSONObject(); - Enumeration paramNameItor = request.getParameterNames(); - while (paramNameItor.hasMoreElements()) { - String key = paramNameItor.nextElement(); - String value = request.getParameter(key); - queryParamsObject.put(key, value); - } - - requestMockParams.setRestParamsObj(urlParamsObject); - requestMockParams.setQueryParamsObj(queryParamsObject); - return requestMockParams; - } - - public JSON getPostParamMap(HttpServletRequest request) { - if (StringUtils.equalsIgnoreCase("application/JSON", request.getContentType())) { - JSON returnJson = null; - try { - String param = this.getRequestPostStr(request); - JSONValidator jsonValidator = JSONValidator.from(param); - if (StringUtils.equalsIgnoreCase("Array", jsonValidator.getType().name())) { - returnJson = JSONArray.parseArray(param); - } else if (StringUtils.equalsIgnoreCase("Object", jsonValidator.getType().name())) { - returnJson = JSONObject.parseObject(param); - } - } catch (Exception e) { - e.printStackTrace(); - } - return returnJson; - } else if (StringUtils.equalsIgnoreCase("text/xml", request.getContentType())) { - String xmlString = this.readXml(request); - System.out.println(xmlString); - - org.json.JSONObject xmlJSONObj = XML.toJSONObject(xmlString); - String jsonStr = xmlJSONObj.toString(); - JSONObject object = null; - try { - object = JSONObject.parseObject(jsonStr); - } catch (Exception e) { - } - return object; - } else if (StringUtils.equalsIgnoreCase("application/x-www-form-urlencoded", request.getContentType())) { - JSONObject object = new JSONObject(); - Enumeration paramNameItor = request.getParameterNames(); - while (paramNameItor.hasMoreElements()) { - String key = paramNameItor.nextElement(); - String value = request.getParameter(key); - object.put(key, value); - } - return object; - } else { - JSONObject object = new JSONObject(); - String bodyParam = this.readBody(request); - object.put("raw",bodyParam); -// if (!StringUtils.isEmpty(bodyParam)) { -// try { -// object = JSONObject.parseObject(bodyParam); -// } catch (Exception e) { -// object.put("raw",bodyParam); -// } -// } - - Enumeration paramNameItor = request.getParameterNames(); - while (paramNameItor.hasMoreElements()) { - String key = paramNameItor.nextElement(); - String value = request.getParameter(key); - object.put(key, value); - } - return object; - } - } - - private String readXml(HttpServletRequest request) { - { - String inputLine = null; - // 接收到的数据 - StringBuffer recieveData = new StringBuffer(); - BufferedReader in = null; - try { - in = new BufferedReader(new InputStreamReader( - request.getInputStream(), "UTF-8")); - while ((inputLine = in.readLine()) != null) { - recieveData.append(inputLine); - } - } catch (IOException e) { - } finally { - try { - if (null != in) { - in.close(); - } - } catch (IOException e) { - } - } - - return recieveData.toString(); - } - } - - private String readBody(HttpServletRequest request) { - String result = ""; - try { - InputStream inputStream = request.getInputStream(); - ByteArrayOutputStream outSteam = new ByteArrayOutputStream(); - byte[] buffer = new byte[1024]; - int len; - while ((len = inputStream.read(buffer)) != -1) { - outSteam.write(buffer, 0, len); - } - outSteam.close(); - inputStream.close(); - result = new String(outSteam.toByteArray(), "UTF-8"); - } catch (Exception e) { - e.printStackTrace(); - } - return result; - } - - public JSONObject getSendRestParamMapByIdAndUrl(ApiDefinitionWithBLOBs api, String urlParams) { -// ApiDefinitionWithBLOBs api = apiDefinitionMapper.selectByPrimaryKey(apiId); - JSONObject returnJson = new JSONObject(); - if (api != null) { - String path = api.getPath(); - if (path.startsWith("/")) { - path = path.substring(1); - } - String[] pathArr = path.split("/"); - String[] sendParamArr = urlParams.split("/"); - - //获取 url的<参数名-参数值>,通过匹配api的接口设置和实际发送的url - for (int i = 0; i < pathArr.length; i++) { - String param = pathArr[i]; - if (param.startsWith("{") && param.endsWith("}")) { - param = param.substring(1, param.length() - 1); - String value = ""; - if (sendParamArr.length > i) { - value = sendParamArr[i]; - } - returnJson.put(param, value); - } - } - - } - return returnJson; - } - public List> getApiParamsByApiDefinitionBLOBs(ApiDefinitionWithBLOBs apiModel) { if (apiModel == null) { return new ArrayList<>(); @@ -1110,30 +984,6 @@ public class MockConfigService { } } } - //Binary的先不处理 -// } else if (StringUtils.equals(type, "BINARY")) { -// if (bodyObj.containsKey("binary")) { -// List> bodyParamList = new ArrayList<>(); -// JSONArray kvsArr = bodyObj.getJSONArray("binary"); -// -// for (int i = 0; i < kvsArr.size(); i++) { -// JSONObject kv = kvsArr.getJSONObject(i); -// if (kv.containsKey("description") && kv.containsKey("files")) { -// String name = kv.getString("description"); -// JSONArray fileArr = kv.getJSONArray("files"); -// String value = ""; -// for (int j = 0; j < fileArr.size(); j++) { -// JSONObject fileObj = fileArr.getJSONObject(j); -// if (fileObj.containsKey("name")) { -// value += fileObj.getString("name") + " ;"; -// } -// } -// if (!paramNameList.contains(name)) { -// paramNameList.add(name); -// } -// } -// } -// } } } } catch (Exception e) { @@ -1185,36 +1035,51 @@ public class MockConfigService { if (project != null) { String urlSuffix = this.getUrlSuffix(project.getSystemId(), request); aualifiedApiList = apiDefinitionService.preparedUrl(project.getId(), method, urlSuffix, urlSuffix); - List apiIdList = aualifiedApiList.stream().map(ApiDefinitionWithBLOBs::getId).collect(Collectors.toList()); - MockConfigResponse mockConfigData = this.findByApiIdList(apiIdList); - if (mockConfigData != null && mockConfigData.getMockExpectConfigList() != null) { - JSON paramJson = this.getPostParamMap(request); - if (paramJson instanceof JSONObject) { - JSONArray paramsArray = new JSONArray(); - paramsArray.add(paramJson); - RequestMockParams mockParams = new RequestMockParams(); - mockParams.setBodyParams(paramsArray); - MockExpectConfigResponse finalExpectConfig = this.findExpectConfig(requestHeaderMap, mockConfigData.getMockExpectConfigList(), mockParams); - if (finalExpectConfig != null) { - isMatch = true; - returnStr = this.updateHttpServletResponse(finalExpectConfig, url, requestHeaderMap, mockParams, response); - } - } else if (paramJson instanceof JSONArray) { - JSONArray paramArray = (JSONArray) paramJson; - RequestMockParams mockParams = new RequestMockParams(); - mockParams.setBodyParams(paramArray); - MockExpectConfigResponse finalExpectConfig = this.findExpectConfig(requestHeaderMap, mockConfigData.getMockExpectConfigList(), mockParams); - if (finalExpectConfig != null) { - isMatch = true; - returnStr = this.updateHttpServletResponse(finalExpectConfig, url, requestHeaderMap, mockParams, response); - } + for (ApiDefinitionWithBLOBs api : aualifiedApiList) { + RequestMockParams mockParams = MockApiUtils.getParams(urlSuffix, api, request); + + MockConfigResponse mockConfigData = this.findByApiId(api.getId()); + MockExpectConfigResponse finalExpectConfig = this.findExpectConfig(requestHeaderMap, mockConfigData.getMockExpectConfigList(), mockParams); + if (finalExpectConfig != null) { + isMatch = true; + returnStr = this.updateHttpServletResponse(finalExpectConfig, url, requestHeaderMap, mockParams, response); + break; } } + + +// List apiIdList = aualifiedApiList.stream().map(ApiDefinitionWithBLOBs::getId).collect(Collectors.toList()); +// MockConfigResponse mockConfigData = this.findByApiIdList(apiIdList); + +// if (mockConfigData != null && mockConfigData.getMockExpectConfigList() != null) { +// String urlSuffix = this.getUrlSuffix(project.getSystemId(), request); +// aualifiedApiList = apiDefinitionService.preparedUrl(project.getId(), method, null, urlSuffix); +// JSON paramJson = MockApiUtils.getParams(request); +// if (paramJson instanceof JSONObject) { +// JSONArray paramsArray = new JSONArray(); +// paramsArray.add(paramJson); +// RequestMockParams mockParams = new RequestMockParams(); +// mockParams.setBodyParams(paramsArray); +// MockExpectConfigResponse finalExpectConfig = this.findExpectConfig(requestHeaderMap, mockConfigData.getMockExpectConfigList(), mockParams); +// if (finalExpectConfig != null) { +// isMatch = true; +// returnStr = this.updateHttpServletResponse(finalExpectConfig, url, requestHeaderMap, mockParams, response); +// } +// } else if (paramJson instanceof JSONArray) { +// JSONArray paramArray = (JSONArray) paramJson; +// RequestMockParams mockParams = new RequestMockParams(); +// mockParams.setBodyParams(paramArray); +// MockExpectConfigResponse finalExpectConfig = this.findExpectConfig(requestHeaderMap, mockConfigData.getMockExpectConfigList(), mockParams); +// if (finalExpectConfig != null) { +// isMatch = true; +// returnStr = this.updateHttpServletResponse(finalExpectConfig, url, requestHeaderMap, mockParams, response); +// } +// } +// } } if (!isMatch) { -// returnStr = this.updateHttpServletResponse(aualifiedApiList, response); response.setStatus(404); } return returnStr; @@ -1239,7 +1104,7 @@ public class MockConfigService { */ for (ApiDefinitionWithBLOBs api : aualifiedApiList) { - RequestMockParams paramMap = this.getGetParamMap(urlSuffix, api, request); + RequestMockParams paramMap = MockApiUtils.getParams(urlSuffix, api, request); MockConfigResponse mockConfigData = this.findByApiId(api.getId()); if (mockConfigData != null && mockConfigData.getMockExpectConfigList() != null) { @@ -1254,59 +1119,11 @@ public class MockConfigService { } if (!isMatch) { -// returnStr = this.updateHttpServletResponse(aualifiedApiList, response); response.setStatus(404); } return returnStr; } - /** - * 描述:获取 post 请求的 byte[] 数组 - *
-     * 举例:
-     * 
- * - * @param request - * @return - * @throws IOException - */ - public byte[] getRequestPostBytes(HttpServletRequest request) throws IOException { - int contentLength = request.getContentLength(); - if (contentLength < 0) { - return null; - } - byte buffer[] = new byte[contentLength]; - for (int i = 0; i < contentLength; ) { - - int readlen = request.getInputStream().read(buffer, i, - contentLength - i); - if (readlen == -1) { - break; - } - i += readlen; - } - return buffer; - } - - /** - * 描述:获取 post 请求内容 - *
-     * 举例:
-     * 
- * - * @param request - * @return - * @throws IOException - */ - public String getRequestPostStr(HttpServletRequest request) throws IOException { - byte buffer[] = getRequestPostBytes(request); - String charEncoding = request.getCharacterEncoding(); - if (charEncoding == null) { - charEncoding = "UTF-8"; - } - return new String(buffer, charEncoding); - } - private List parseByJsonDataStruct(String dataString) { List returnList = new ArrayList<>(); try {