diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/EsbDataStruct.java b/backend/src/main/java/io/metersphere/api/dto/automation/EsbDataStruct.java index b9aab28d66..09ee8b0f70 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/EsbDataStruct.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/EsbDataStruct.java @@ -123,7 +123,6 @@ public class EsbDataStruct { element.addAttribute("attr", attrString); } } catch (Exception e) { - System.out.println(this.name); e.printStackTrace(); } @@ -163,7 +162,6 @@ public class EsbDataStruct { element.addAttribute("attr", attrString); } } catch (Exception e) { - System.out.println(this.name); e.printStackTrace(); } diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/TcpTreeTableDataStruct.java b/backend/src/main/java/io/metersphere/api/dto/automation/TcpTreeTableDataStruct.java index 7d4ddf1db9..14cc42971e 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/TcpTreeTableDataStruct.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/TcpTreeTableDataStruct.java @@ -123,7 +123,6 @@ public class TcpTreeTableDataStruct { element.addAttribute("attr", attrString); } } catch (Exception e) { - System.out.println(this.name); e.printStackTrace(); } @@ -163,7 +162,6 @@ public class TcpTreeTableDataStruct { element.addAttribute("attr", attrString); } } catch (Exception e) { - System.out.println(this.name); e.printStackTrace(); } 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 fd095f69db..0e024fb545 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 @@ -424,6 +424,9 @@ public class MockApiUtils { if(StringUtils.isNotEmpty(newScript)){ newScript += "\n"; } + if(StringUtils.isNotEmpty(returnMsg)){ + returnMsg += "\n"; + } } } returnMap.put("script",newScript); @@ -435,8 +438,8 @@ public class MockApiUtils { JSR223Sampler jmeterScriptSampler = new JSR223Sampler(); jmeterScriptSampler.setScriptLanguage(scriptLanguage); jmeterScriptSampler.setScript(script); - SampleResult result = jmeterScriptSampler.sample(null); - System.out.println(result.getResponseData()); + jmeterScriptSampler.sample(null); + } public static RequestMockParams getParams(String urlParams, String apiPath, JSONObject queryParamsObject,JSON paramJson){ @@ -492,7 +495,6 @@ public class MockApiUtils { 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(); @@ -511,6 +513,14 @@ public class MockApiUtils { object.put(key, value); } return object; + } else if (StringUtils.equalsIgnoreCase("text/plain", request.getContentType())) { + JSONObject object = new JSONObject(); + String bodyParam = readBody(request); + if(StringUtils.isNotEmpty(bodyParam)){ + object.put("raw",bodyParam); + } + return object; + } else { JSONObject object = new JSONObject(); String bodyParam = readBody(request); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index 75c1e04d65..1f756accc4 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -1443,67 +1443,55 @@ public class ApiDefinitionService { // return apiDefinitionMapper.selectByExample(example); // } - public List preparedUrl(String projectId, String method, String url, String urlSuffix) { + public List preparedUrl(String projectId, String method, String urlSuffix) { if (StringUtils.isEmpty(urlSuffix)) { return new ArrayList<>(); } else { - if (StringUtils.equalsAnyIgnoreCase(method, "GET", "DELETE")) { - ApiDefinitionExample example = new ApiDefinitionExample(); - ApiDefinitionExample.Criteria criteria = example.createCriteria().andMethodEqualTo(method).andProjectIdEqualTo(projectId); - if (StringUtils.isNotEmpty(url)) { - criteria.andPathEqualTo(url); - } - List apiList = apiDefinitionMapper.selectByExample(example); + ApiDefinitionExample example = new ApiDefinitionExample(); + example.createCriteria().andMethodEqualTo(method).andProjectIdEqualTo(projectId); + List apiList = apiDefinitionMapper.selectByExample(example); - List apiIdList = new ArrayList<>(); - boolean urlSuffixEndEmpty = false; - if (urlSuffix.endsWith("/")) { - urlSuffixEndEmpty = true; - urlSuffix = urlSuffix + "testMock"; + List apiIdList = new ArrayList<>(); + boolean urlSuffixEndEmpty = false; + if (urlSuffix.endsWith("/")) { + urlSuffixEndEmpty = true; + urlSuffix = urlSuffix + "testMock"; + } + String[] urlParams = urlSuffix.split("/"); + if (urlSuffixEndEmpty) { + urlParams[urlParams.length - 1] = ""; + } + for (ApiDefinition api : apiList) { + String path = api.getPath(); + if (path.startsWith("/")) { + path = path.substring(1); } - String[] urlParams = urlSuffix.split("/"); - if (urlSuffixEndEmpty) { - urlParams[urlParams.length - 1] = ""; - } - for (ApiDefinition api : apiList) { - String path = api.getPath(); - if (path.startsWith("/")) { - path = path.substring(1); - } - if (StringUtils.isNotEmpty(path)) { - String[] pathArr = path.split("/"); - if (pathArr.length == urlParams.length) { - boolean isFetch = true; - for (int i = 0; i < urlParams.length; i++) { - String pathItem = pathArr[i]; - if (!(pathItem.startsWith("{") && pathItem.endsWith("}"))) { - if (!StringUtils.equals(pathArr[i], urlParams[i])) { - isFetch = false; - break; - } + if (StringUtils.isNotEmpty(path)) { + String[] pathArr = path.split("/"); + if (pathArr.length == urlParams.length) { + boolean isFetch = true; + for (int i = 0; i < urlParams.length; i++) { + String pathItem = pathArr[i]; + if (!(pathItem.startsWith("{") && pathItem.endsWith("}"))) { + if (!StringUtils.equals(pathArr[i], urlParams[i])) { + isFetch = false; + break; } + } - } - if (isFetch) { - apiIdList.add(api.getId()); - } + } + if (isFetch) { + apiIdList.add(api.getId()); } } } - if (apiIdList.isEmpty()) { - return new ArrayList<>(); - } else { - example.clear(); - example.createCriteria().andIdIn(apiIdList); - return apiDefinitionMapper.selectByExampleWithBLOBs(example); - } + } + if (apiIdList.isEmpty()) { + return new ArrayList<>(); } else { - if (!url.startsWith("/")) { - url = "/" + url; - } - ApiDefinitionExample example = new ApiDefinitionExample(); - ApiDefinitionExample.Criteria criteria = example.createCriteria().andMethodEqualTo(method).andProjectIdEqualTo(projectId).andPathEqualTo(url); + example.clear(); + example.createCriteria().andIdIn(apiIdList); return apiDefinitionMapper.selectByExampleWithBLOBs(example); } } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java index 11bfd9d106..cbc5e69c12 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -605,7 +605,6 @@ public class ApiScenarioReportService { if (obj != null) { ReportCounter counter = (ReportCounter) obj; counter.setNumber(counter.getNumber() + 1); - System.out.println("得到统计数量:" + counter.getNumber()); MessageCache.cache.put(report.getScenarioId(), counter); } } 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 e2ed305bec..bbf42009e8 100644 --- a/backend/src/main/java/io/metersphere/api/service/MockConfigService.java +++ b/backend/src/main/java/io/metersphere/api/service/MockConfigService.java @@ -1032,7 +1032,7 @@ public class MockConfigService { List aualifiedApiList = new ArrayList<>(); if (project != null) { String urlSuffix = this.getUrlSuffix(project.getSystemId(), request); - aualifiedApiList = apiDefinitionService.preparedUrl(project.getId(), method, urlSuffix, urlSuffix); + aualifiedApiList = apiDefinitionService.preparedUrl(project.getId(), method, urlSuffix); JSON paramJson = MockApiUtils.getPostParamMap(request); JSONObject parameterObject = MockApiUtils.getParameterJsonObject(request); @@ -1094,7 +1094,7 @@ public class MockConfigService { List aualifiedApiList = new ArrayList<>(); if (project != null) { String urlSuffix = this.getUrlSuffix(project.getSystemId(), request); - aualifiedApiList = apiDefinitionService.preparedUrl(project.getId(), method, null, urlSuffix); + aualifiedApiList = apiDefinitionService.preparedUrl(project.getId(), method, urlSuffix); /** * GET/DELETE 这种通过url穿参数的接口,在接口路径相同的情况下可能会出现这样的情况: diff --git a/backend/src/main/java/io/metersphere/commons/utils/JsonStructUtils.java b/backend/src/main/java/io/metersphere/commons/utils/JsonStructUtils.java index 4f0bb742e3..7b877743ec 100644 --- a/backend/src/main/java/io/metersphere/commons/utils/JsonStructUtils.java +++ b/backend/src/main/java/io/metersphere/commons/utils/JsonStructUtils.java @@ -59,9 +59,15 @@ public class JsonStructUtils { } public static boolean checkJsonArrayCompliance(JSONArray sourceArray, JSONArray matchArray) { - if (sourceArray == null && matchArray == null) { + if(sourceArray == null){ + sourceArray = new JSONArray(); + } + if(matchArray == null){ + matchArray = new JSONArray(); + } + if (sourceArray.isEmpty() && matchArray.isEmpty()) { return true; - } else if (sourceArray != null && matchArray != null && sourceArray.size() >= matchArray.size()) { + } else if (!sourceArray.isEmpty() && !matchArray.isEmpty() && sourceArray.size() >= matchArray.size()) { try { for (int i = 0; i < matchArray.size(); i++) { Object obj = matchArray.get(i);