From 63e642911da1163f6da5a211ebeaa8810968bcc5 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Fri, 14 May 2021 19:06:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=87=AA=E5=AE=9A=E4=B9=89=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E4=BC=9A=E5=BC=95=E7=94=A8=E7=8E=AF=E5=A2=83=E5=9F=9F?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/sampler/MsHTTPSamplerProxy.java | 46 ++++++++++--------- .../io/metersphere/api/dto/scenario/Body.java | 16 +++---- .../scenario/component/ApiComponent.vue | 1 + 3 files changed, 32 insertions(+), 31 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 7c10a7a095..aa62933f51 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 @@ -234,31 +234,33 @@ public class MsHTTPSamplerProxy extends MsTestElement { LogUtil.error(e.getMessage(), e); } } else { - //1.9 增加对Mock环境的判断 - if (this.isMockEnvironment()) { - url = httpConfig.getProtocol() + "://" + httpConfig.getSocket() + "/mock/" + this.getProjectId(); - } else { - if (httpConfig.isMock()) { + if (!isCustomizeReq()) { + //1.9 增加对Mock环境的判断 + if (this.isMockEnvironment()) { url = httpConfig.getProtocol() + "://" + httpConfig.getSocket() + "/mock/" + this.getProjectId(); } else { - url = httpConfig.getProtocol() + "://" + httpConfig.getSocket(); - } + if (httpConfig.isMock()) { + url = httpConfig.getProtocol() + "://" + httpConfig.getSocket() + "/mock/" + this.getProjectId(); + } else { + url = httpConfig.getProtocol() + "://" + httpConfig.getSocket(); + } + } + URL urlObject = new URL(url); + String envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getPath(); + if (StringUtils.isNotBlank(this.getPath())) { + envPath += this.getPath(); + } + if (StringUtils.isNotEmpty(httpConfig.getDomain())) { + sampler.setDomain(httpConfig.getDomain()); + sampler.setProtocol(httpConfig.getProtocol()); + } else { + sampler.setDomain(""); + sampler.setProtocol(""); + } + sampler.setPort(httpConfig.getPort()); + sampler.setPath(envPath); } - URL urlObject = new URL(url); - String envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getPath(); - if (StringUtils.isNotBlank(this.getPath())) { - envPath += this.getPath(); - } - if (StringUtils.isNotEmpty(httpConfig.getDomain())) { - sampler.setDomain(httpConfig.getDomain()); - sampler.setProtocol(httpConfig.getProtocol()); - } else { - sampler.setDomain(""); - sampler.setProtocol(""); - } - sampler.setPort(httpConfig.getPort()); - sampler.setPath(envPath); } String envPath = sampler.getPath(); if (CollectionUtils.isNotEmpty(this.getRest()) && this.isRest()) { @@ -267,7 +269,7 @@ public class MsHTTPSamplerProxy extends MsTestElement { } if (CollectionUtils.isNotEmpty(this.getArguments())) { String path = getPostQueryParameters(URLDecoder.decode(envPath, "UTF-8")); - if (HTTPConstants.DELETE.equals(this.getMethod())) { + if (HTTPConstants.DELETE.equals(this.getMethod()) && !path.startsWith("${")) { if (!path.startsWith("/")) { path = "/" + path; } 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 285c2b9aba..afe95ad664 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 @@ -80,19 +80,17 @@ public class Body { } private void parseJonBodyMock() { - try { - if (StringUtils.isNotBlank(this.type) && StringUtils.equals(this.type, "JSON")) { - if(StringUtils.isNotEmpty(this.format) && this.getJsonSchema() != null - && "JSON-SCHEMA".equals(this.format)) { - this.raw = JSONSchemaGenerator.getJson(com.alibaba.fastjson.JSON.toJSONString(this.getJsonSchema())); - } else { // json 文本也支持 mock 参数 + if (StringUtils.isNotBlank(this.type) && StringUtils.equals(this.type, "JSON")) { + if(StringUtils.isNotEmpty(this.format) && this.getJsonSchema() != null + && "JSON-SCHEMA".equals(this.format)) { + this.raw = JSONSchemaGenerator.getJson(com.alibaba.fastjson.JSON.toJSONString(this.getJsonSchema())); + } else { // json 文本也支持 mock 参数 + try { JSONObject jsonObject = com.alibaba.fastjson.JSON.parseObject(this.getRaw()); jsonMockParse(jsonObject); this.raw = JSONObject.toJSONString(jsonObject); - } + } catch (Exception e) {} } - } catch (Exception e) { - LogUtil.error(e.getMessage(), e); } } diff --git a/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue b/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue index 2fc6e2f559..120e00195f 100644 --- a/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue +++ b/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue @@ -145,6 +145,7 @@ if (!this.request.projectId) { this.request.projectId = getCurrentProjectID(); } + this.request.customizeReq = this.isCustomizeReq; // 加载引用对象数据 this.getApiInfo(); if (this.request.protocol === 'HTTP') {