From b9143716f7dfc0ff0f679586f81ad082ae8fc101 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Wed, 23 Dec 2020 20:57:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=AE=9A=E4=B9=89=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/sampler/MsHTTPSamplerProxy.java | 46 ++++++++++++++----- .../report/components/ResponseText.vue | 9 ++-- .../automation/scenario/EditApiScenario.vue | 15 ++++-- .../api/definition/ApiDefinition.vue | 2 +- .../components/response/ResponseResult.vue | 9 ++-- .../components/runtest/RunTestHTTPPage.vue | 3 +- 6 files changed, 59 insertions(+), 25 deletions(-) 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() {