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 d1a995ea92..0edce5e72d 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 @@ -116,11 +116,7 @@ public class MsHTTPSamplerProxy extends MsTestElement { } try { if (config != null && config.getConfig() != null) { - String url = ""; - sampler.setDomain(config.getConfig().getHttpConfig().getDomain()); - sampler.setPort(config.getConfig().getHttpConfig().getPort()); - sampler.setProtocol(config.getConfig().getHttpConfig().getProtocol()); - url = config.getConfig().getHttpConfig().getProtocol() + "://" + config.getConfig().getHttpConfig().getSocket(); + String url = config.getConfig().getHttpConfig().getProtocol() + "://" + config.getConfig().getHttpConfig().getSocket(); // 补充如果是完整URL 则用自身URL boolean isUrl = false; if (StringUtils.isNotEmpty(this.getUrl()) && isURL(this.getUrl())) { @@ -128,12 +124,21 @@ public class MsHTTPSamplerProxy extends MsTestElement { isUrl = true; } URL urlObject = new URL(url); + if (isUrl) { + sampler.setDomain(URLDecoder.decode(urlObject.getHost(), "UTF-8")); + sampler.setPort(urlObject.getPort()); + sampler.setProtocol(urlObject.getProtocol()); + } else { + sampler.setDomain(config.getConfig().getHttpConfig().getDomain()); + sampler.setPort(config.getConfig().getHttpConfig().getPort()); + sampler.setProtocol(config.getConfig().getHttpConfig().getProtocol()); + } String envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getPath(); if (StringUtils.isNotBlank(this.getPath()) && !isUrl) { envPath += this.getPath(); } if (CollectionUtils.isNotEmpty(this.getRest()) && this.isRest()) { - envPath = getRestParameters(URLDecoder.decode(envPath, "UTF-8")); + envPath = getRestParameters(URLDecoder.decode(envPath, "UTF-8"), config); sampler.setPath(envPath); } if (CollectionUtils.isNotEmpty(this.getArguments())) { @@ -150,7 +155,7 @@ public class MsHTTPSamplerProxy extends MsTestElement { sampler.setProtocol(urlObject.getProtocol()); if (CollectionUtils.isNotEmpty(this.getRest()) && this.isRest()) { - sampler.setPath(getRestParameters(URLDecoder.decode(urlObject.getPath(), "UTF-8"))); + sampler.setPath(getRestParameters(URLDecoder.decode(urlObject.getPath(), "UTF-8"), config)); } if (CollectionUtils.isNotEmpty(this.getArguments())) { sampler.setPath(getPostQueryParameters(URLDecoder.decode(urlObject.getPath(), "UTF-8"))); @@ -193,7 +198,7 @@ public class MsHTTPSamplerProxy extends MsTestElement { } } - private String getRestParameters(String path) { + private String getRestParameters(String path, ParameterConfig config) { StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(path); stringBuffer.append("/"); @@ -201,14 +206,31 @@ public class MsHTTPSamplerProxy extends MsTestElement { this.getRest().stream().filter(KeyValue::isEnable).filter(KeyValue::isValid).forEach(keyValue -> keyValueMap.put(keyValue.getName(), keyValue.getValue()) ); + // 这块是否使用jmeter自身机制? + Map pubKeyValueMap = new HashMap<>(); + if (config != null && config.getVariables() != null) { + config.getVariables().stream().forEach(keyValue -> { + pubKeyValueMap.put(keyValue.getName(), keyValue.getValue()); + }); + } + for (String key : keyValueMap.keySet()) { + if (keyValueMap.get(key) != null && keyValueMap.get(key).startsWith("$")) { + String pubKey = keyValueMap.get(key).substring(2, keyValueMap.get(key).length() - 1); + keyValueMap.put(key, pubKeyValueMap.get(pubKey)); + } + } Pattern p = Pattern.compile("(\\{)([\\w]+)(\\})"); Matcher m = p.matcher(path); StringBuffer sb = new StringBuffer(); - while (m.find()) { - String group = m.group(2); - //替换并且把替换好的值放到sb中 - m.appendReplacement(sb, keyValueMap.get(group)); + try { + while (m.find()) { + String group = m.group(2); + //替换并且把替换好的值放到sb中 + m.appendReplacement(sb, keyValueMap.get(group)); + } + } catch (Exception ex) { + ex.printStackTrace(); } //把符合的数据追加到sb尾 m.appendTail(sb); diff --git a/frontend/src/business/components/api/automation/report/components/ResponseText.vue b/frontend/src/business/components/api/automation/report/components/ResponseText.vue index 5d10582ba0..d732c953c5 100644 --- a/frontend/src/business/components/api/automation/report/components/ResponseText.vue +++ b/frontend/src/business/components/api/automation/report/components/ResponseText.vue @@ -2,14 +2,15 @@
- -
{{ response.headers }}
-
- + + +
{{ response.headers }}
+
+
{{response.console}}
diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index 93d5c5f62d..c9bb269508 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -336,7 +336,6 @@ this.operatingElements = ELEMENTS.get("ALL"); this.getMaintainerOptions(); this.getApiScenario(); - this.getEnvironments(); } , watch: {} @@ -680,6 +679,16 @@ this.environments.forEach(environment => { parseEnvironment(environment); }); + let hasEnvironment = false; + for (let i in this.environments) { + if (this.environments[i].id === this.currentEnvironmentId) { + hasEnvironment = true; + break; + } + } + if (!hasEnvironment) { + this.currentEnvironmentId = ''; + } }); } } @@ -812,8 +821,7 @@ }) } }) - } - , + }, getApiScenario() { if (this.currentScenario.tags != undefined && !(this.currentScenario.tags instanceof Array)) { this.currentScenario.tags = JSON.parse(this.currentScenario.tags); @@ -835,6 +843,7 @@ this.path = "/api/automation/create"; } } + this.getEnvironments(); }) } } diff --git a/frontend/src/business/components/api/definition/ApiDefinition.vue b/frontend/src/business/components/api/definition/ApiDefinition.vue index 07edcab884..050147c459 100644 --- a/frontend/src/business/components/api/definition/ApiDefinition.vue +++ b/frontend/src/business/components/api/definition/ApiDefinition.vue @@ -266,7 +266,7 @@ }, saveApi(data) { this.setTabTitle(data); - this.$refs.apiList[0].initTable(data); + this.refresh(data); }, showExecResult(row) { diff --git a/frontend/src/business/components/api/definition/components/response/ResponseResult.vue b/frontend/src/business/components/api/definition/components/response/ResponseResult.vue index 8be2966cc5..547feb25ac 100644 --- a/frontend/src/business/components/api/definition/components/response/ResponseResult.vue +++ b/frontend/src/business/components/api/definition/components/response/ResponseResult.vue @@ -2,13 +2,14 @@
- -
{{ response.responseResult.headers }}
-
+ + +
{{ response.responseResult.headers }}
+
@@ -80,7 +81,7 @@ data() { return { isActive: true, - activeName: "headers", + activeName: "body", modes: ['text', 'json', 'xml', 'html'], sqlModes: ['text', 'table'], mode: BODY_FORMAT.TEXT diff --git a/frontend/src/business/components/api/definition/components/runtest/RunTestHTTPPage.vue b/frontend/src/business/components/api/definition/components/runtest/RunTestHTTPPage.vue index 861047c291..b2fa12af0b 100644 --- a/frontend/src/business/components/api/definition/components/runtest/RunTestHTTPPage.vue +++ b/frontend/src/business/components/api/definition/components/runtest/RunTestHTTPPage.vue @@ -217,6 +217,7 @@ let url = "/api/definition/update"; let bodyFiles = this.getBodyUploadFiles(); this.api.method = this.api.request.method; + this.api.path = this.api.request.path; this.$fileUpload(url, null, bodyFiles, this.api, () => { this.$success(this.$t('commons.save_success')); this.$emit('saveApi', this.api); @@ -273,7 +274,7 @@ environmentConfigClose() { this.getEnvironments(); }, - refresh(){ + refresh() { this.$emit('refresh'); }, getResult() { diff --git a/frontend/src/business/components/common/components/MsJsonCodeEdit.vue b/frontend/src/business/components/common/components/MsJsonCodeEdit.vue index e908453689..5b8b1313bf 100644 --- a/frontend/src/business/components/common/components/MsJsonCodeEdit.vue +++ b/frontend/src/business/components/common/components/MsJsonCodeEdit.vue @@ -17,12 +17,12 @@ }, mode: { type: String, - default: "tree" + default: "code" }, modes: { type: Array, default: function () { - return ["tree", "code"]; + return ["code"]; } } },