From 4befeadbcffb5b996bd3f1377d903afda98d4f10 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Wed, 27 Dec 2023 15:50:55 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8E=86=E5=8F=B2=E6=95=B0=E6=8D=AE=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E8=AF=B7=E6=B1=82=E8=B7=AF=E5=BE=84=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fit2-zhao --- .../request/sampler/MsHTTPSamplerProxy.java | 26 ++++++++++++------- .../constants/MsTestElementConstants.java | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java index 8259bb6f2a..29fb6aea05 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java @@ -36,6 +36,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.apache.jmeter.config.Arguments; @@ -114,6 +115,11 @@ public class MsHTTPSamplerProxy extends MsTestElement { } hashTree = this.getHashTree(); } + if (StringUtils.equalsAnyIgnoreCase(this.getReferenced(), + MsTestElementConstants.REF.name(), MsTestElementConstants.COPY.name()) + || BooleanUtils.isTrue(this.isRefEnvironment)) { + this.setUrl(null); + } HTTPSamplerProxy sampler = new HTTPSamplerProxy(); sampler.setEnabled(this.isEnable()); sampler.setName(this.getName()); @@ -397,17 +403,19 @@ public class MsHTTPSamplerProxy extends MsTestElement { sampler.setProperty(HTTPSamplerBase.PATH, path); } } else { - String envPath; + String envPath = this.path; try { - URL urlObject = new URL(url); - if (url.contains("${")) { - envPath = url; - } else { - sampler.setDomain(URLDecoder.decode(urlObject.getHost(), StandardCharsets.UTF_8)); - envPath = urlObject.getPath(); - sampler.setPort(urlObject.getPort()); + if (StringUtils.isNotBlank(url)) { + URL urlObject = new URL(url); + if (url.contains("${")) { + envPath = url; + } else { + sampler.setDomain(URLDecoder.decode(urlObject.getHost(), StandardCharsets.UTF_8)); + envPath = urlObject.getPath(); + sampler.setPort(urlObject.getPort()); + } + sampler.setProtocol(urlObject.getProtocol()); } - sampler.setProtocol(urlObject.getProtocol()); } catch (Exception e) { envPath = url == null ? "" : url; } diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/constants/MsTestElementConstants.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/constants/MsTestElementConstants.java index b281b284e2..91228ab1a6 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/constants/MsTestElementConstants.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/constants/MsTestElementConstants.java @@ -1,5 +1,5 @@ package io.metersphere.commons.constants; public enum MsTestElementConstants { - LoopController, SCENARIO, REF, Deleted, TransactionController + LoopController, SCENARIO, REF, COPY, Deleted, TransactionController }