diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java index 478a7a5805..f69807c73b 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java @@ -17,7 +17,6 @@ import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; import io.metersphere.commons.constants.MsTestElementConstants; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.FileUtils; -import io.metersphere.commons.utils.SessionUtils; import lombok.Data; import lombok.EqualsAndHashCode; import org.apache.commons.collections.CollectionUtils; @@ -202,6 +201,7 @@ public class MsScenario extends MsTestElement { } }); } + // HTTP放到请求中,按照域名匹配 if (config.isEffective(this.getProjectId()) && config.getConfig().get(this.getProjectId()).getCommonConfig() != null && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getCommonConfig().getVariables())) { config.getConfig().get(this.getProjectId()).getCommonConfig().getVariables().stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue -> diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java index 867957e944..65678ddc3a 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java @@ -5,9 +5,6 @@ import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONType; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; import io.metersphere.api.dto.definition.request.assertions.MsAssertions; import io.metersphere.api.dto.definition.request.auth.MsAuthManager; import io.metersphere.api.dto.definition.request.configurations.MsHeaderManager; @@ -27,11 +24,7 @@ import io.metersphere.api.dto.definition.request.variable.ScenarioVariable; import io.metersphere.api.dto.mockconfig.MockConfigStaticData; import io.metersphere.api.dto.scenario.KeyValue; import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; -import io.metersphere.api.service.ApiDefinitionService; -import io.metersphere.api.service.ApiTestCaseService; import io.metersphere.api.service.ApiTestEnvironmentService; -import io.metersphere.base.domain.ApiDefinitionWithBLOBs; -import io.metersphere.base.domain.ApiTestCaseWithBLOBs; import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; import io.metersphere.commons.constants.LoopConstants; import io.metersphere.commons.constants.MsTestElementConstants; @@ -158,35 +151,6 @@ public abstract class MsTestElement { return jmeterTestPlanHashTree; } - public void getRefElement(MsTestElement element) { - try { - ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class); - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - if (StringUtils.equals(element.getRefType(), "CASE")) { - ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class); - ApiTestCaseWithBLOBs bloBs = apiTestCaseService.get(element.getId()); - if (bloBs != null) { - element.setProjectId(bloBs.getProjectId()); - element = mapper.readValue(bloBs.getRequest(), new TypeReference() { - }); - hashTree.add(element); - } - } else { - ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(element.getId()); - if (apiDefinition != null) { - element.setProjectId(apiDefinition.getProjectId()); - element = mapper.readValue(apiDefinition.getRequest(), new TypeReference() { - }); - hashTree.add(element); - } - } - } catch (Exception ex) { - ex.printStackTrace(); - LogUtil.error(ex.getMessage()); - } - } - public Arguments addArguments(ParameterConfig config) { if (config.isEffective(this.getProjectId()) && config.getConfig().get(this.getProjectId()).getCommonConfig() != null && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getCommonConfig().getVariables())) { diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java index 80d78efe23..d84e504611 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java @@ -3,6 +3,9 @@ package io.metersphere.api.dto.definition.request.sampler; import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONType; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; import io.github.ningyu.jmeter.plugin.dubbo.sample.DubboSample; import io.github.ningyu.jmeter.plugin.dubbo.sample.MethodArgument; import io.github.ningyu.jmeter.plugin.util.Constants; @@ -12,7 +15,13 @@ import io.metersphere.api.dto.definition.request.sampler.dubbo.MsConfigCenter; import io.metersphere.api.dto.definition.request.sampler.dubbo.MsConsumerAndService; import io.metersphere.api.dto.definition.request.sampler.dubbo.MsRegistryCenter; import io.metersphere.api.dto.scenario.KeyValue; +import io.metersphere.api.service.ApiDefinitionService; +import io.metersphere.api.service.ApiTestCaseService; +import io.metersphere.base.domain.ApiDefinitionWithBLOBs; +import io.metersphere.base.domain.ApiTestCaseWithBLOBs; import io.metersphere.commons.constants.MsTestElementConstants; +import io.metersphere.commons.utils.CommonBeanFactory; +import io.metersphere.commons.utils.LogUtil; import lombok.Data; import lombok.EqualsAndHashCode; import org.apache.commons.collections.CollectionUtils; @@ -29,7 +38,7 @@ import java.util.stream.Collectors; @EqualsAndHashCode(callSuper = true) @JSONType(typeName = "DubboSampler") public class MsDubboSampler extends MsTestElement { - // type 必须放最前面,以便能够转换正确的类 + /** type 必须放最前面,以便能够转换正确的类 */ private String type = "DubboSampler"; @JSONField(ordinal = 52) @@ -55,9 +64,6 @@ public class MsDubboSampler extends MsTestElement { @JSONField(ordinal = 60) private String useEnvironment; -// @JSONField(ordinal = 60) -// private Object requestResult; - @Override public void toHashTree(HashTree tree, List hashTree, ParameterConfig config) { // 非导出操作,且不是启用状态则跳过执行 @@ -68,7 +74,7 @@ public class MsDubboSampler extends MsTestElement { return; } if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) { - this.getRefElement(this); + this.setRefElement(); } final HashTree testPlanTree = tree.add(dubboSample(config)); @@ -79,6 +85,51 @@ public class MsDubboSampler extends MsTestElement { } } + private void setRefElement() { + try { + ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + if (StringUtils.equals(this.getRefType(), "CASE")) { + ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class); + ApiTestCaseWithBLOBs bloBs = apiTestCaseService.get(this.getId()); + if (bloBs != null) { + this.setProjectId(bloBs.getProjectId()); + MsDubboSampler proxy = mapper.readValue(bloBs.getRequest(), new TypeReference() { + }); + this.setHashTree(proxy.getHashTree()); + this.setName(bloBs.getName()); + this.setMethod(proxy.getMethod()); + this.set_interface(proxy.get_interface()); + this.setAttachmentArgs(proxy.getAttachmentArgs()); + this.setArgs(proxy.getArgs()); + this.setConsumerAndService(proxy.getConsumerAndService()); + this.setRegistryCenter(proxy.getRegistryCenter()); + this.setConfigCenter(proxy.getConfigCenter()); + } + } else { + ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(this.getId()); + if (apiDefinition != null) { + this.setProjectId(apiDefinition.getProjectId()); + MsDubboSampler proxy = mapper.readValue(apiDefinition.getRequest(), new TypeReference() { + }); + this.setHashTree(proxy.getHashTree()); + this.setName(apiDefinition.getName()); + this.setMethod(proxy.getMethod()); + this.set_interface(proxy.get_interface()); + this.setAttachmentArgs(proxy.getAttachmentArgs()); + this.setArgs(proxy.getArgs()); + this.setConsumerAndService(proxy.getConsumerAndService()); + this.setRegistryCenter(proxy.getRegistryCenter()); + this.setConfigCenter(proxy.getConfigCenter()); + } + } + } catch (Exception ex) { + ex.printStackTrace(); + LogUtil.error(ex.getMessage()); + } + } + private DubboSample dubboSample(ParameterConfig config) { DubboSample sampler = new DubboSample(); sampler.setEnabled(this.isEnable()); 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 6de8704b08..a7ce7091d0 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 @@ -105,7 +105,7 @@ public class MsHTTPSamplerProxy extends MsTestElement { @JSONField(ordinal = 36) private MsAuthManager authManager; - public void setRefElement() { + private void setRefElement() { try { ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class); ObjectMapper mapper = new ObjectMapper(); @@ -203,14 +203,9 @@ public class MsHTTPSamplerProxy extends MsTestElement { } } - // 添加环境中的公共变量 - Arguments arguments = this.addArguments(config); - if (arguments != null) { - tree.add(ParameterConfig.valueSupposeMock(arguments)); - } try { if (config.isEffective(this.getProjectId())) { - HttpConfig httpConfig = getHttpConfig(config.getConfig().get(this.getProjectId()).getHttpConfig()); + HttpConfig httpConfig = getHttpConfig(config.getConfig().get(this.getProjectId()).getHttpConfig(), tree); if (httpConfig == null) { MSException.throwException("未匹配到环境,请检查环境配置"); } @@ -453,31 +448,74 @@ public class MsHTTPSamplerProxy extends MsTestElement { * @param httpConfig * @return */ - private HttpConfig getHttpConfig(HttpConfig httpConfig) { + private HttpConfig getHttpConfig(HttpConfig httpConfig, HashTree tree) { + boolean isNext = true; if (CollectionUtils.isNotEmpty(httpConfig.getConditions())) { for (HttpConfigCondition item : httpConfig.getConditions()) { - if (item.getType().equals(ConditionType.NONE.name())) { - return httpConfig.initHttpConfig(item); - } else if (item.getType().equals(ConditionType.PATH.name())) { + if (item.getType().equals(ConditionType.PATH.name())) { HttpConfig config = httpConfig.getPathCondition(this.getPath()); if (config != null) { - return config; + isNext = false; + httpConfig = config; + break; } } else if (item.getType().equals(ConditionType.MODULE.name())) { + ApiDefinition apiDefinition; ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class); - ApiDefinition apiDefinition = apiDefinitionService.get(this.getId()); + if (StringUtils.isNotEmpty(this.getReferenced()) && this.getReferenced().equals("REF") && StringUtils.isNotEmpty(this.getRefType()) && this.getRefType().equals("CASE")) { + ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class); + ApiTestCaseWithBLOBs caseWithBLOBs = apiTestCaseService.get(this.getId()); + apiDefinition = apiDefinitionService.get(caseWithBLOBs.getApiDefinitionId()); + } else { + apiDefinition = apiDefinitionService.get(this.getId()); + } if (apiDefinition != null) { HttpConfig config = httpConfig.getModuleCondition(apiDefinition.getModuleId()); if (config != null) { - return config; + isNext = false; + httpConfig = config; + break; } } } } + if (isNext) { + for (HttpConfigCondition item : httpConfig.getConditions()) { + if (item.getType().equals(ConditionType.NONE.name())) { + httpConfig = httpConfig.initHttpConfig(item); + break; + } + } + } + } + + // 环境中请求头 + Arguments arguments = arguments(httpConfig.getHeaders()); + if (arguments != null) { + tree.add(ParameterConfig.valueSupposeMock(arguments)); } return httpConfig; } + private Arguments arguments(List headers) { + Arguments arguments = new Arguments(); + arguments.setEnabled(true); + arguments.setName(StringUtils.isNotEmpty(this.getName()) ? this.getName() : "Arguments"); + arguments.setProperty(TestElement.TEST_CLASS, Arguments.class.getName()); + arguments.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("ArgumentsPanel")); + + // HTTP放到请求中,按照域名匹配 + if (CollectionUtils.isNotEmpty(headers)) { + headers.stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue -> + arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=") + ); + } + if (arguments.getArguments() != null && arguments.getArguments().size() > 0) { + return arguments; + } + return null; + } + 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/definition/request/sampler/MsJDBCSampler.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java index c0a105e651..9aea5e50dc 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java @@ -3,16 +3,24 @@ package io.metersphere.api.dto.definition.request.sampler; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONType; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; import io.metersphere.api.dto.definition.request.MsTestElement; import io.metersphere.api.dto.definition.request.ParameterConfig; import io.metersphere.api.dto.scenario.DatabaseConfig; import io.metersphere.api.dto.scenario.KeyValue; import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; +import io.metersphere.api.service.ApiDefinitionService; +import io.metersphere.api.service.ApiTestCaseService; import io.metersphere.api.service.ApiTestEnvironmentService; +import io.metersphere.base.domain.ApiDefinitionWithBLOBs; +import io.metersphere.base.domain.ApiTestCaseWithBLOBs; import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; import io.metersphere.commons.constants.MsTestElementConstants; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.CommonBeanFactory; +import io.metersphere.commons.utils.LogUtil; import lombok.Data; import lombok.EqualsAndHashCode; import org.apache.commons.collections.CollectionUtils; @@ -46,8 +54,6 @@ public class MsJDBCSampler extends MsTestElement { private List variables; @JSONField(ordinal = 26) private String environmentId; - // @JSONField(ordinal = 27) -// private Object requestResult; @JSONField(ordinal = 28) private String dataSourceId; @JSONField(ordinal = 29) @@ -63,7 +69,7 @@ public class MsJDBCSampler extends MsTestElement { return; } if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) { - this.getRefElement(this); + this.setRefElement(); } if (StringUtils.isNotEmpty(dataSourceId)) { this.dataSource = null; @@ -85,6 +91,51 @@ public class MsJDBCSampler extends MsTestElement { } } + private void setRefElement() { + try { + ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + if (StringUtils.equals(this.getRefType(), "CASE")) { + ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class); + ApiTestCaseWithBLOBs bloBs = apiTestCaseService.get(this.getId()); + if (bloBs != null) { + this.setProjectId(bloBs.getProjectId()); + MsJDBCSampler proxy = mapper.readValue(bloBs.getRequest(), new TypeReference() { + }); + this.setHashTree(proxy.getHashTree()); + this.setName(bloBs.getName()); + this.setDataSource(proxy.getDataSource()); + this.setDataSourceId(proxy.getDataSourceId()); + this.setQuery(proxy.getQuery()); + this.setVariables(proxy.getVariables()); + this.setVariableNames(proxy.getVariableNames()); + this.setResultVariable(proxy.getResultVariable()); + this.setQueryTimeout(proxy.getQueryTimeout()); + } + } else { + ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(this.getId()); + if (apiDefinition != null) { + this.setProjectId(apiDefinition.getProjectId()); + MsJDBCSampler proxy = mapper.readValue(apiDefinition.getRequest(), new TypeReference() { + }); + this.setHashTree(proxy.getHashTree()); + this.setName(apiDefinition.getName()); + this.setDataSource(proxy.getDataSource()); + this.setDataSourceId(proxy.getDataSourceId()); + this.setQuery(proxy.getQuery()); + this.setVariables(proxy.getVariables()); + this.setVariableNames(proxy.getVariableNames()); + this.setResultVariable(proxy.getResultVariable()); + this.setQueryTimeout(proxy.getQueryTimeout()); + } + } + } catch (Exception ex) { + ex.printStackTrace(); + LogUtil.error(ex.getMessage()); + } + } + private void initDataSource() { ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class); ApiTestEnvironmentWithBLOBs environment = environmentService.get(environmentId); diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java index 4ae022bfec..b94a325d2e 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java @@ -2,13 +2,22 @@ package io.metersphere.api.dto.definition.request.sampler; import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONType; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; import io.metersphere.api.dto.automation.EsbDataStruct; import io.metersphere.api.dto.definition.request.MsTestElement; import io.metersphere.api.dto.definition.request.ParameterConfig; import io.metersphere.api.dto.definition.request.processors.pre.MsJSR223PreProcessor; import io.metersphere.api.dto.scenario.KeyValue; import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; +import io.metersphere.api.service.ApiDefinitionService; +import io.metersphere.api.service.ApiTestCaseService; +import io.metersphere.base.domain.ApiDefinitionWithBLOBs; +import io.metersphere.base.domain.ApiTestCaseWithBLOBs; import io.metersphere.commons.constants.MsTestElementConstants; +import io.metersphere.commons.utils.CommonBeanFactory; +import io.metersphere.commons.utils.LogUtil; import lombok.Data; import lombok.EqualsAndHashCode; import org.apache.commons.collections.CollectionUtils; @@ -24,7 +33,9 @@ import org.apache.jmeter.testelement.property.StringProperty; import org.apache.jorphan.collections.HashTree; import org.apache.jorphan.collections.ListedHashTree; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; @Data @EqualsAndHashCode(callSuper = true) @@ -58,8 +69,6 @@ public class MsTCPSampler extends MsTestElement { private String password = ""; @JSONField(ordinal = 33) private String request; - // @JSONField(ordinal = 34) -// private Object requestResult; @JSONField(ordinal = 35) private List parameters; @JSONField(ordinal = 36) @@ -84,14 +93,14 @@ public class MsTCPSampler extends MsTestElement { return; } if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) { - this.getRefElement(this); + this.setRefElement(); } if (config.getConfig() == null) { // 单独接口执行 this.setProjectId(config.getProjectId()); config.setConfig(getEnvironmentConfig(useEnvironment)); } - if(config.getConfig()!=null){ + if (config.getConfig() != null) { parseEnvironment(config.getConfig().get(this.projectId)); } @@ -115,6 +124,45 @@ public class MsTCPSampler extends MsTestElement { } } + private void setRefElement() { + try { + ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + if (StringUtils.equals(this.getRefType(), "CASE")) { + ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class); + ApiTestCaseWithBLOBs bloBs = apiTestCaseService.get(this.getId()); + if (bloBs != null) { + this.setProjectId(bloBs.getProjectId()); + MsTCPSampler proxy = mapper.readValue(bloBs.getRequest(), new TypeReference() { + }); + this.setHashTree(proxy.getHashTree()); + this.setName(bloBs.getName()); + this.setClassname(proxy.getClassname()); + this.setServer(proxy.getServer()); + this.setPort(proxy.getPort()); + this.setRequest(proxy.getRequest()); + } + } else { + ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(this.getId()); + if (apiDefinition != null) { + this.setProjectId(apiDefinition.getProjectId()); + MsTCPSampler proxy = mapper.readValue(apiDefinition.getRequest(), new TypeReference() { + }); + this.setHashTree(proxy.getHashTree()); + this.setName(apiDefinition.getName()); + this.setClassname(proxy.getClassname()); + this.setServer(proxy.getServer()); + this.setPort(proxy.getPort()); + this.setRequest(proxy.getRequest()); + } + } + } catch (Exception ex) { + ex.printStackTrace(); + LogUtil.error(ex.getMessage()); + } + } + private void parseEnvironment(EnvironmentConfig config) { if (!isCustomizeReq() && config != null && config.getTcpConfig() != null) { this.server = config.getTcpConfig().getServer(); diff --git a/backend/src/main/java/io/metersphere/api/dto/scenario/HttpConfigCondition.java b/backend/src/main/java/io/metersphere/api/dto/scenario/HttpConfigCondition.java index 8d194d76aa..06805a1477 100644 --- a/backend/src/main/java/io/metersphere/api/dto/scenario/HttpConfigCondition.java +++ b/backend/src/main/java/io/metersphere/api/dto/scenario/HttpConfigCondition.java @@ -12,4 +12,5 @@ public class HttpConfigCondition { private String socket; private String domain; private int port; + private List headers; } diff --git a/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java b/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java index 491ab44f12..d8aea168e5 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java @@ -280,8 +280,10 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl } } - if (reportTask != null && StringUtils.equals(ReportTriggerMode.API.name(), reportTask.getTriggerMode()) || StringUtils.equals(ReportTriggerMode.SCHEDULE.name(), reportTask.getTriggerMode())) { - sendTask(reportTask, reportUrl, testResult); + if (reportTask != null) { + if (StringUtils.equals(ReportTriggerMode.API.name(), reportTask.getTriggerMode()) || StringUtils.equals(ReportTriggerMode.SCHEDULE.name(), reportTask.getTriggerMode())) { + sendTask(reportTask, reportUrl, testResult); + } } } diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index 7f9dccb6ad..7d432de1c3 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -209,7 +209,7 @@ - + @@ -112,7 +114,7 @@ }, loading: false, pathDetails: new KeyValue({name: "", value: "contains"}), - condition: {type: "NONE", details: [new KeyValue({name: "", value: "contains"})], protocol: "http", socket: "", domain: "", port: 0}, + condition: {type: "NONE", details: [new KeyValue({name: "", value: "contains"})], protocol: "http", socket: "", domain: "", port: 0, headers: [new KeyValue()]}, }; }, watch: { @@ -121,16 +123,17 @@ }, httpConfig: function (o) { // 历史数据处理 - if (this.httpConfig && this.httpConfig.socket) { + if (this.httpConfig && this.httpConfig.socket && this.httpConfig.conditions && this.httpConfig.conditions.length === 0) { this.condition.type = "NONE"; this.condition.socket = this.httpConfig.socket; this.condition.protocol = this.httpConfig.protocol; this.condition.port = this.httpConfig.port; this.condition.domain = this.httpConfig.domain; this.condition.time = new Date().getTime(); + this.condition.headers = this.httpConfig.headers; this.add(); } - this.condition = {type: "NONE", details: [new KeyValue({name: "", value: "contains"})], protocol: "http", socket: "", domain: "", port: 0}; + this.condition = {type: "NONE", details: [new KeyValue({name: "", value: "contains"})], protocol: "http", socket: "", domain: "", port: 0, headers: [new KeyValue()]}; }, }, methods: { @@ -172,6 +175,9 @@ this.httpConfig.protocol = row.protocol; this.httpConfig.port = row.port; this.condition = row; + if (!this.condition.headers) { + this.condition.headers = [new KeyValue()]; + } if (row.type === "PATH" && row.details.length > 0) { this.pathDetails = JSON.parse(JSON.stringify(row.details[0])); } else if (row.type === "MODULE" && row.details.length > 0) { @@ -216,7 +222,7 @@ const index = this.httpConfig.conditions.findIndex((d) => d.id === this.condition.id); this.validateSocket(this.condition.socket); let obj = { - id: this.condition.id, type: this.condition.type, domain: this.condition.domain, socket: this.condition.socket, + id: this.condition.id, type: this.condition.type, domain: this.condition.domain, socket: this.condition.socket, headers: this.condition.headers, protocol: this.condition.protocol, details: this.condition.details, port: this.condition.port, time: this.condition.time }; if (obj.type === "PATH") { @@ -224,7 +230,7 @@ } if (index !== -1) { Vue.set(this.httpConfig.conditions[index], obj, 1); - this.condition = {type: "NONE", details: [new KeyValue({name: "", value: "contains"})], protocol: "", socket: "", domain: ""}; + this.condition = {type: "NONE", details: [new KeyValue({name: "", value: "contains"})], protocol: "http", socket: "", domain: "", headers: [new KeyValue()]}; this.reload(); } }, @@ -235,8 +241,9 @@ }); }, add() { + this.validateSocket(); let obj = { - id: getUUID(), type: this.condition.type, socket: this.condition.socket, protocol: this.condition.protocol, + id: getUUID(), type: this.condition.type, socket: this.condition.socket, protocol: this.condition.protocol, headers: this.condition.headers, domain: this.condition.domain, port: this.condition.port, time: new Date().getTime() }; if (this.condition.type === "PATH") { @@ -256,7 +263,7 @@ }, copy(row) { const index = this.httpConfig.conditions.findIndex((d) => d.id === row.id); - let obj = {id: getUUID(), type: row.type, socket: row.socket, details: row.details, protocol: row.protocol, domain: row.domain, time: new Date().getTime()}; + let obj = {id: getUUID(), type: row.type, socket: row.socket, details: row.details, protocol: row.protocol, headers: JSON.parse(JSON.stringify(this.condition.headers)), domain: row.domain, time: new Date().getTime()}; if (index != -1) { this.httpConfig.conditions.splice(index, 0, obj); } else { @@ -306,4 +313,8 @@ /deep/ .el-form-item { margin-bottom: 10px; } + + .ms-el-form-item__content >>> .el-form-item__content { + line-height: 20px; + } diff --git a/frontend/src/business/components/common/components/MsDrawer.vue b/frontend/src/business/components/common/components/MsDrawer.vue index 6fb8f872a8..411e180a22 100644 --- a/frontend/src/business/components/common/components/MsDrawer.vue +++ b/frontend/src/business/components/common/components/MsDrawer.vue @@ -5,6 +5,9 @@ + + +
@@ -120,6 +123,14 @@ this.directionStyle = 'bottom-style'; this.dragBarDirection = 'vertical'; break; + default: + this.w = this.getWidthPercentage(this.size); + this.h = this.getHeightPercentage(100); + this.x = document.body.clientWidth - this.w; + this.y = 0; + this.directionStyle = 'right-style'; + this.dragBarDirection = 'horizontal'; + break; } }, getWidthPercentage(per) { @@ -156,6 +167,10 @@ case 'bottom': this.w = document.documentElement.clientWidth; break; + default: + this.h = document.documentElement.clientHeight; + this.w = document.documentElement.clientWidth; + break; } } }