From 4e01bf5af3aafd72ab23084fc553d58acbe631a6 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Wed, 23 Dec 2020 13:11:56 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E5=A4=96=E9=83=A8=E5=AF=BC=E5=85=A5=E5=92=8C?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E9=87=8D=E6=9E=84=E5=8E=BB=E9=99=A4=E5=9F=9F?= =?UTF-8?q?=E5=90=8D=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/sampler/MsHTTPSamplerProxy.java | 17 ++++++++++++- .../io/metersphere/api/dto/scenario/Body.java | 11 +++++---- .../api/dto/scenario/KeyValue.java | 2 +- .../api/parse/ApiImportAbstractParser.java | 24 ++++++++++++++++--- .../api/automation/scenario/ApiComponent.vue | 19 ++++++--------- .../automation/scenario/EditApiScenario.vue | 4 ---- .../components/debug/DebugHttpPage.vue | 6 +++-- 7 files changed, 56 insertions(+), 27 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 1786eca223..de84c2c899 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 @@ -119,9 +119,15 @@ public class MsHTTPSamplerProxy extends MsTestElement { sampler.setPort(config.getConfig().getHttpConfig().getPort()); sampler.setProtocol(config.getConfig().getHttpConfig().getProtocol()); url = config.getConfig().getHttpConfig().getProtocol() + "://" + config.getConfig().getHttpConfig().getSocket(); + // 补充如果是完整URL 则用自身URL + boolean isUrl = false; + if (StringUtils.isNotEmpty(this.getUrl()) && isURL(this.getUrl())) { + url = this.getUrl(); + isUrl = true; + } URL urlObject = new URL(url); String envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getPath(); - if (StringUtils.isNotBlank(this.getPath())) { + if (StringUtils.isNotBlank(this.getPath()) && !isUrl) { envPath += this.getPath(); } if (CollectionUtils.isNotEmpty(this.getRest()) && this.isRest()) { @@ -243,6 +249,15 @@ public class MsHTTPSamplerProxy extends MsTestElement { tree.add(headerManager); } + public boolean isURL(String str) { + //转换为小写 + try { + new URL(str); + return true; + } catch (Exception e) { + return false; + } + } private boolean isRest() { return this.getRest().stream().filter(KeyValue::isEnable).filter(KeyValue::isValid).toArray().length > 0; diff --git a/backend/src/main/java/io/metersphere/api/dto/scenario/Body.java b/backend/src/main/java/io/metersphere/api/dto/scenario/Body.java index fc0e0f7fa3..7ba26ee3d1 100644 --- a/backend/src/main/java/io/metersphere/api/dto/scenario/Body.java +++ b/backend/src/main/java/io/metersphere/api/dto/scenario/Body.java @@ -98,11 +98,14 @@ public class Body { return StringUtils.equals(type, XML); } - public boolean isWwwFROM() { - return StringUtils.equals(type, WWW_FROM); + public void initKvs() { + this.kvs = new ArrayList<>(); + this.kvs.add(new KeyValue()); } - public boolean isFromData() { - return StringUtils.equals(type, FORM_DATA); + public void initBinary() { + this.binary = new ArrayList<>(); + this.binary.add(new KeyValue()); } + } diff --git a/backend/src/main/java/io/metersphere/api/dto/scenario/KeyValue.java b/backend/src/main/java/io/metersphere/api/dto/scenario/KeyValue.java index 25a9e982a1..328517e501 100644 --- a/backend/src/main/java/io/metersphere/api/dto/scenario/KeyValue.java +++ b/backend/src/main/java/io/metersphere/api/dto/scenario/KeyValue.java @@ -15,7 +15,7 @@ public class KeyValue { private List files; private String description; private String contentType; - private boolean enable; + private boolean enable = true; private boolean encode = true; private boolean required; diff --git a/backend/src/main/java/io/metersphere/api/parse/ApiImportAbstractParser.java b/backend/src/main/java/io/metersphere/api/parse/ApiImportAbstractParser.java index e455e98637..4b80284658 100644 --- a/backend/src/main/java/io/metersphere/api/parse/ApiImportAbstractParser.java +++ b/backend/src/main/java/io/metersphere/api/parse/ApiImportAbstractParser.java @@ -20,6 +20,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -72,7 +73,7 @@ public abstract class ApiImportAbstractParser implements ApiImportParser { protected ApiDefinitionResult buildApiDefinition(String id, String name, String path, String method) { ApiDefinitionResult apiDefinition = new ApiDefinitionResult(); apiDefinition.setName(name); - apiDefinition.setPath(path); + apiDefinition.setPath(formatPath(path)); apiDefinition.setProtocol(RequestType.HTTP); apiDefinition.setMethod(method); apiDefinition.setId(id); @@ -81,17 +82,34 @@ public abstract class ApiImportAbstractParser implements ApiImportParser { return apiDefinition; } + private String formatPath(String url) { + try { + URL urlObject = new URL(url); + StringBuffer pathBuffer = new StringBuffer(urlObject.getPath()); + if (StringUtils.isNotEmpty(urlObject.getQuery())) { + pathBuffer.append("?").append(urlObject.getQuery()); + } + return pathBuffer.toString(); + } catch (Exception ex) { + return url; + } + } + protected MsHTTPSamplerProxy buildRequest(String name, String path, String method) { MsHTTPSamplerProxy request = new MsHTTPSamplerProxy(); request.setName(name); - request.setPath(path); + // 路径去掉域名/IP 地址,保留方法名称及参数 + request.setPath(formatPath(path)); request.setMethod(method); request.setProtocol(RequestType.HTTP); request.setId(UUID.randomUUID().toString()); request.setHeaders(new ArrayList<>()); request.setArguments(new ArrayList<>()); request.setRest(new ArrayList<>()); - request.setBody(new Body()); + Body body = new Body(); + body.initKvs(); + body.initBinary(); + request.setBody(body); return request; } diff --git a/frontend/src/business/components/api/automation/scenario/ApiComponent.vue b/frontend/src/business/components/api/automation/scenario/ApiComponent.vue index f982f29274..895c4f66c5 100644 --- a/frontend/src/business/components/api/automation/scenario/ApiComponent.vue +++ b/frontend/src/business/components/api/automation/scenario/ApiComponent.vue @@ -37,7 +37,12 @@
- + + + + + + @@ -96,20 +101,10 @@ try { let urlObject = new URL(this.request.url); let url = urlObject.protocol + "//" + urlObject.host + "/"; - if (url) { - let path = this.request.url.substr(url.length); - if (!path.startsWith('/')) { - path = "/" + path; - } - this.request.path = path; - } else { - this.request.url = this.request.path; - } } catch (e) { if (this.request.url) { this.request.path = this.request.url; - } else { - this.request.url = this.request.path; + this.request.url = undefined; } } } diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index dfaf072dfb..04c37fa135 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -945,8 +945,4 @@ font-size: 13px; } - /deep/ .el-form-item__content { - line-height: 100%; - } - diff --git a/frontend/src/business/components/api/definition/components/debug/DebugHttpPage.vue b/frontend/src/business/components/api/definition/components/debug/DebugHttpPage.vue index 55ab7ea8a9..bcb2bbb98b 100644 --- a/frontend/src/business/components/api/definition/components/debug/DebugHttpPage.vue +++ b/frontend/src/business/components/api/definition/components/debug/DebugHttpPage.vue @@ -16,7 +16,7 @@ + @command="handleCommand" size="small" v-if="testCase===undefined && !scenario"> {{$t('commons.test')}} {{$t('api_test.definition.request.save_as')}} @@ -76,7 +76,9 @@ method: [{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}], url: [ {max: 500, required: true, message: this.$t('commons.input_limit', [1, 500]), trigger: 'blur'}, - {validator: validateURL, trigger: 'blur'} + /* + {validator: validateURL, trigger: 'blur'} + */ ], }, debugForm: {method: REQ_METHOD[0].id, environmentId: ""},