From 8a280a74dbe1737608fd811cb08227aed9e5584e Mon Sep 17 00:00:00 2001 From: C370228492 <89453996+C370228492@users.noreply.github.com> Date: Fri, 12 Aug 2022 12:53:51 +0800 Subject: [PATCH] Update ElementUtil.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixed 设置引用环境,没有带出来环境的url前缀。 重现步骤: 为环境指定http协议,域名,端口 为场景指定环境为上述环境 该场景中有2个自定义请求,第一个没有设置跟随环境, 第二个点跟随环境按钮时无法带出环境的url前缀。 原因:处理第一个自定义请求时,抛出空指针异常 修复方法: io.metersphere.api.dto.definition.request.ElementUtil#dataSetDomain 中判断 getIsRefEnvironment是否为true时先判断是否是null。BooleanUtils.isTrue(httpSamplerProxy.getIsRefEnvironment())) --- .../io/metersphere/api/dto/definition/request/ElementUtil.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java index f08a76faf9..b38c7223a0 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java @@ -32,6 +32,7 @@ import io.metersphere.plugin.core.MsParameter; import io.metersphere.plugin.core.MsTestElement; import io.metersphere.service.EnvironmentGroupProjectService; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.apache.jmeter.config.Arguments; import org.apache.jmeter.config.CSVDataSet; @@ -417,7 +418,7 @@ public class ElementUtil { } else if (element != null && element.get("type").toString().equals("HTTPSamplerProxy")) { MsHTTPSamplerProxy httpSamplerProxy = JSON.toJavaObject(element, MsHTTPSamplerProxy.class); if (httpSamplerProxy != null - && (!httpSamplerProxy.isCustomizeReq() || (httpSamplerProxy.isCustomizeReq() && httpSamplerProxy.getIsRefEnvironment()))) { + && (!httpSamplerProxy.isCustomizeReq() || (httpSamplerProxy.isCustomizeReq() && BooleanUtils.isTrue(httpSamplerProxy.getIsRefEnvironment())))) { // 多态JSON普通转换会丢失内容,需要通过 ObjectMapper 获取 if (element != null && StringUtils.isNotEmpty(element.getString("hashTree"))) { LinkedList elements = mapper.readValue(element.getString("hashTree"),