diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java index 51bbf47d72..5c60342d6d 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java @@ -101,7 +101,6 @@ public abstract class MsTestElement { public String getJmx(HashTree hashTree) { try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { SaveService.saveTree(hashTree, baos); - System.out.print(baos.toString()); return baos.toString(); } catch (Exception e) { e.printStackTrace(); diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java index b3f5c2aedc..cc4947e9ff 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java @@ -13,6 +13,7 @@ import io.metersphere.api.service.ApiTestEnvironmentService; import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.LogUtil; +import io.metersphere.commons.utils.ScriptEngineUtils; import lombok.Data; import lombok.EqualsAndHashCode; import org.apache.commons.collections.CollectionUtils; @@ -158,12 +159,13 @@ public class MsHTTPSamplerProxy extends MsTestElement { sampler.setDomain(URLDecoder.decode(urlObject.getHost(), "UTF-8")); sampler.setPort(urlObject.getPort()); sampler.setProtocol(urlObject.getProtocol()); - + String envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getPath(); if (CollectionUtils.isNotEmpty(this.getRest()) && this.isRest()) { - sampler.setPath(getRestParameters(URLDecoder.decode(urlObject.getPath(), "UTF-8"))); + envPath = getRestParameters(URLDecoder.decode(envPath, "UTF-8")); + sampler.setPath(envPath); } if (CollectionUtils.isNotEmpty(this.getArguments())) { - sampler.setPath(getPostQueryParameters(URLDecoder.decode(urlObject.getPath(), "UTF-8"))); + sampler.setPath(getPostQueryParameters(URLDecoder.decode(envPath, "UTF-8"))); } } } catch (Exception e) { @@ -221,7 +223,8 @@ public class MsHTTPSamplerProxy extends MsTestElement { stringBuffer.append("/"); Map keyValueMap = new HashMap<>(); this.getRest().stream().filter(KeyValue::isEnable).filter(KeyValue::isValid).forEach(keyValue -> - keyValueMap.put(keyValue.getName(), keyValue.getValue()) + keyValueMap.put(keyValue.getName(), keyValue.getValue() != null && keyValue.getValue().startsWith("@") ? + ScriptEngineUtils.calculate(keyValue.getValue()) : keyValue.getValue()) ); try { Pattern p = Pattern.compile("(\\{)([\\w]+)(\\})"); @@ -243,7 +246,8 @@ public class MsHTTPSamplerProxy extends MsTestElement { stringBuffer.append(path); stringBuffer.append("?"); this.getArguments().stream().filter(KeyValue::isEnable).filter(KeyValue::isValid).forEach(keyValue -> - stringBuffer.append(keyValue.getName()).append("=").append(keyValue.getValue()).append("&") + stringBuffer.append(keyValue.getName()).append("=").append(keyValue.getValue() != null && keyValue.getValue().startsWith("@") ? + ScriptEngineUtils.calculate(keyValue.getValue()) : keyValue.getValue()).append("&") ); return stringBuffer.substring(0, stringBuffer.length() - 1); } @@ -251,7 +255,7 @@ public class MsHTTPSamplerProxy extends MsTestElement { private Arguments httpArguments(List list) { Arguments arguments = new Arguments(); list.stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue -> { - HTTPArgument httpArgument = new HTTPArgument(keyValue.getName(), keyValue.getValue()); + HTTPArgument httpArgument = new HTTPArgument(keyValue.getName(), keyValue.getValue() != null && keyValue.getValue().startsWith("@") ? ScriptEngineUtils.calculate(keyValue.getValue()) : keyValue.getValue()); httpArgument.setAlwaysEncoded(keyValue.isEncode()); if (StringUtils.isNotBlank(keyValue.getContentType())) { httpArgument.setContentType(keyValue.getContentType()); diff --git a/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java b/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java index df70761830..b02f2474d5 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java @@ -66,7 +66,7 @@ public class JMeterService { } } - private HashTree getHashTree(Object scriptWrapper) throws Exception { + public static HashTree getHashTree(Object scriptWrapper) throws Exception { Field field = scriptWrapper.getClass().getDeclaredField("testPlan"); field.setAccessible(true); return (HashTree) field.get(scriptWrapper); diff --git a/backend/src/main/java/io/metersphere/api/parse/old/JmeterDocumentParser.java b/backend/src/main/java/io/metersphere/api/parse/old/JmeterDocumentParser.java index f406b826d5..5825b19b57 100644 --- a/backend/src/main/java/io/metersphere/api/parse/old/JmeterDocumentParser.java +++ b/backend/src/main/java/io/metersphere/api/parse/old/JmeterDocumentParser.java @@ -166,6 +166,16 @@ public class JmeterDocumentParser { u += k + "=" + v; return u; }); + //rest参数处理 + if (url.contains("@")) { + String vars[] = url.split("@"); + for (String item : vars) { + if (item.endsWith("/")) { + item = item.substring(0, item.length() - 1); + } + url = url.replace("@" + item, ScriptEngineUtils.calculate("@" + item)); + } + } ele.setTextContent(url + ((params != null && !params.equals("?")) ? params : "")); break; case "Argument.value": diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index d8c0ff940d..19c1b0376d 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -349,8 +349,8 @@ public class ApiAutomationService { } catch (Exception ex) { LogUtil.error(ex.getMessage()); } - testPlan.toHashTree(jmeterHashTree, testPlan.getHashTree(), new ParameterConfig()); + testPlan.toHashTree(jmeterHashTree, testPlan.getHashTree(), new ParameterConfig()); String runMode = ApiRunMode.SCENARIO.name(); if (StringUtils.isNotBlank(request.getRunMode()) && StringUtils.equals(request.getRunMode(), ApiRunMode.SCENARIO_PLAN.name())) { runMode = ApiRunMode.SCENARIO_PLAN.name(); @@ -380,9 +380,10 @@ public class ApiAutomationService { config.setConfig(envConfig); HashTree hashTree = request.getTestElement().generateHashTree(config); // 调用执行方法 - jMeterService.runDefinition(request.getId(), hashTree, request.getReportId(), ApiRunMode.SCENARIO.name()); createScenarioReport(request.getId(), request.getScenarioId(), request.getScenarioName(), ReportTriggerMode.MANUAL.name(), request.getExecuteType(), request.getProjectId(), SessionUtils.getUserId()); + // 调用执行方法 + jMeterService.runDefinition(request.getId(), hashTree, request.getReportId(), ApiRunMode.SCENARIO.name()); return request.getId(); } diff --git a/backend/src/main/java/io/metersphere/i18n/Translator.java b/backend/src/main/java/io/metersphere/i18n/Translator.java index 0f0303c466..1b0cebec47 100644 --- a/backend/src/main/java/io/metersphere/i18n/Translator.java +++ b/backend/src/main/java/io/metersphere/i18n/Translator.java @@ -17,6 +17,6 @@ public class Translator { * 单Key翻译 */ public static String get(String key) { - return messageSource.getMessage(key, null, "Not Support Key", LocaleContextHolder.getLocale()); + return messageSource.getMessage(key, null, "Not Support Key: " + key, LocaleContextHolder.getLocale()); } } diff --git a/backend/src/main/java/io/metersphere/xpack b/backend/src/main/java/io/metersphere/xpack index f27d1609d7..c10b11f224 160000 --- a/backend/src/main/java/io/metersphere/xpack +++ b/backend/src/main/java/io/metersphere/xpack @@ -1 +1 @@ -Subproject commit f27d1609d77f7d6c988d37d709466e844d350e17 +Subproject commit c10b11f224e4186306e6ae3a3976e29a42af96a5 diff --git a/backend/src/main/resources/i18n/messages_en_US.properties b/backend/src/main/resources/i18n/messages_en_US.properties index da8d250df6..ae2aa26f23 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -60,6 +60,7 @@ test_resource_pool_name_is_null=Test Resource Pool name cannot be null test_resource_pool_name_already_exists=The test resource pool name already exists load_test=Load Test test_resource_pool_is_use=This resource pool is in use and cannot be deleted +only_one_k8s=Only one K8S can be added #project project_name_is_null=Project name cannot be null project_name_already_exists=The project name already exists diff --git a/backend/src/main/resources/i18n/messages_zh_CN.properties b/backend/src/main/resources/i18n/messages_zh_CN.properties index 0b440262da..983fac6be2 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -60,6 +60,7 @@ test_resource_pool_name_is_null=资源池名称不能为空 test_resource_pool_name_already_exists=资源池名称已存在 load_test=性能测试 test_resource_pool_is_use=正在使用此资源池,无法删除 +only_one_k8s=只能添加一个 K8S #project project_name_is_null=项目名称不能为空 project_name_already_exists=项目名称已存在 diff --git a/backend/src/main/resources/i18n/messages_zh_TW.properties b/backend/src/main/resources/i18n/messages_zh_TW.properties index 56b0884a60..97a457beb3 100644 --- a/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -60,6 +60,7 @@ test_resource_pool_name_is_null=資源池名稱不能為空 test_resource_pool_name_already_exists=資源池名稱已存在 load_test=性能測試 test_resource_pool_is_use=正在使用此資源池,無法刪除 +only_one_k8s=只能添加一個 K8S #project project_name_is_null=項目名稱不能為空 project_name_already_exists=項目名稱已存在 diff --git a/frontend/src/business/components/common/json/JsonTable.vue b/frontend/src/business/components/common/json/JsonTable.vue new file mode 100644 index 0000000000..511929f7e7 --- /dev/null +++ b/frontend/src/business/components/common/json/JsonTable.vue @@ -0,0 +1,211 @@ + + + +