From 8b508694900171cf52e4c956abcd5bb83fe6f9c6 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 16 Sep 2021 18:11:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9C=BA=E6=99=AF=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96)=20=E5=A2=9E=E5=8A=A0=E6=95=B0=E7=BB=84=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/sampler/MsHTTPSamplerProxy.java | 79 +-- .../api/dto/scenario/HttpConfig.java | 34 +- backend/src/main/java/io/metersphere/xpack | 2 +- .../request/http/ApiHttpRequestForm.vue | 483 +++++++++--------- 4 files changed, 313 insertions(+), 285 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 64b03f08a4..3a80c1ea8b 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 @@ -126,7 +126,7 @@ public class MsHTTPSamplerProxy extends MsTestElement { @JSONField(ordinal = 38) private String alias; - + @JSONField(ordinal = 39) private boolean customizeReq; @@ -274,27 +274,8 @@ public class MsHTTPSamplerProxy extends MsTestElement { addCertificate(config, httpSamplerTree); //增加全局前后至脚本 - MsJSR223PreProcessor preProcessor = httpConfig.getPreProcessor(); - MsJSR223PostProcessor postProcessor = httpConfig.getPostProcessor(); - if(preProcessor != null){ - if (preProcessor.getEnvironmentId() == null) { - if (this.getEnvironmentId() == null) { - preProcessor.setEnvironmentId(useEnvironment); - } else { - preProcessor.setEnvironmentId(this.getEnvironmentId()); - } - } - preProcessor.toHashTree(httpSamplerTree, preProcessor.getHashTree(), config); - } - if(postProcessor != null){ - if (postProcessor.getEnvironmentId() == null) { - if (this.getEnvironmentId() == null) { - postProcessor.setEnvironmentId(useEnvironment); - } else { - postProcessor.setEnvironmentId(this.getEnvironmentId()); - } - } - postProcessor.toHashTree(httpSamplerTree, postProcessor.getHashTree(), config); + if (httpConfig != null) { + this.setScript(httpConfig, httpSamplerTree, config); } if (CollectionUtils.isNotEmpty(hashTree)) { for (MsTestElement el : hashTree) { @@ -311,21 +292,46 @@ public class MsHTTPSamplerProxy extends MsTestElement { } + private void setScript(HttpConfig httpConfig, HashTree httpSamplerTree, ParameterConfig config) { + MsJSR223PreProcessor preProcessor = httpConfig.getPreProcessor(); + MsJSR223PostProcessor postProcessor = httpConfig.getPostProcessor(); + if (preProcessor != null) { + if (preProcessor.getEnvironmentId() == null) { + if (this.getEnvironmentId() == null) { + preProcessor.setEnvironmentId(useEnvironment); + } else { + preProcessor.setEnvironmentId(this.getEnvironmentId()); + } + } + preProcessor.toHashTree(httpSamplerTree, preProcessor.getHashTree(), config); + } + if (postProcessor != null) { + if (postProcessor.getEnvironmentId() == null) { + if (this.getEnvironmentId() == null) { + postProcessor.setEnvironmentId(useEnvironment); + } else { + postProcessor.setEnvironmentId(this.getEnvironmentId()); + } + } + postProcessor.toHashTree(httpSamplerTree, postProcessor.getHashTree(), config); + } + } + private void initConnectAndResponseTimeout(ParameterConfig config) { if (config.isEffective(this.getProjectId())) { String useEvnId = config.getConfig().get(this.getProjectId()).getApiEnvironmentid(); if (StringUtils.isNotEmpty(useEvnId) && !StringUtils.equals(useEvnId, this.getEnvironmentId())) { this.setEnvironmentId(useEvnId); } - CommonConfig commonConfig = config.getConfig().get(this.getProjectId()).getCommonConfig(); - if(commonConfig != null){ - if(this.getConnectTimeout() == null || StringUtils.equals(this.getConnectTimeout(),"60000")){ - if(commonConfig.getRequestTimeout() != 0){ + CommonConfig commonConfig = config.getConfig().get(this.getProjectId()).getCommonConfig(); + if (commonConfig != null) { + if (this.getConnectTimeout() == null || StringUtils.equals(this.getConnectTimeout(), "60000")) { + if (commonConfig.getRequestTimeout() != 0) { this.setConnectTimeout(String.valueOf(commonConfig.getRequestTimeout())); } } - if(this.getResponseTimeout() == null || StringUtils.equals(this.getResponseTimeout(),"60000")){ - if(commonConfig.getResponseTimeout() != 0){ + if (this.getResponseTimeout() == null || StringUtils.equals(this.getResponseTimeout(), "60000")) { + if (commonConfig.getResponseTimeout() != 0) { this.setResponseTimeout(String.valueOf(commonConfig.getResponseTimeout())); } } @@ -340,15 +346,16 @@ public class MsHTTPSamplerProxy extends MsTestElement { private HttpConfig getHttpConfig(ParameterConfig config) { if (config.isEffective(this.getProjectId())) { EnvironmentConfig environmentConfig = config.getConfig().get(this.getProjectId()); - if (environmentConfig != null){ + if (environmentConfig != null) { String useEvnId = environmentConfig.getApiEnvironmentid(); - if(this.authManager == null && environmentConfig.getAuthManager() != null && environmentConfig.getAuthManager().containsKey("hashTree") ){ + if (this.authManager == null && environmentConfig.getAuthManager() != null && environmentConfig.getAuthManager().containsKey("hashTree")) { try { JSONArray jsonArray = environmentConfig.getAuthManager().getJSONArray("hashTree"); - if(jsonArray.size() > 0){ + if (jsonArray.size() > 0) { this.authManager = jsonArray.getJSONObject(0).toJavaObject(MsAuthManager.class); } - }catch (Exception e){} + } catch (Exception e) { + } } if (StringUtils.isNotEmpty(useEvnId) && !StringUtils.equals(useEvnId, this.getEnvironmentId())) { this.setEnvironmentId(useEvnId); @@ -702,18 +709,18 @@ public class MsHTTPSamplerProxy extends MsTestElement { for (KeyValue keyValue : keyValues) { boolean hasHead = false; //检查是否已经有重名的Head。如果Header重复会导致执行报错 - if(headerManager.getHeaders() != null){ - for(int i = 0; i < headerManager.getHeaders().size(); i ++){ + if (headerManager.getHeaders() != null) { + for (int i = 0; i < headerManager.getHeaders().size(); i++) { Header header = headerManager.getHeader(i); String headName = header.getName(); - if(StringUtils.equals(headName,keyValue.getName())){ + if (StringUtils.equals(headName, keyValue.getName())) { hasHead = true; break; } } } - if(!hasHead){ + if (!hasHead) { headerManager.add(new Header(keyValue.getName(), ScriptEngineUtils.buildFunctionCallString(keyValue.getValue()))); } } diff --git a/backend/src/main/java/io/metersphere/api/dto/scenario/HttpConfig.java b/backend/src/main/java/io/metersphere/api/dto/scenario/HttpConfig.java index dc1dd68fe6..dacc65af7b 100644 --- a/backend/src/main/java/io/metersphere/api/dto/scenario/HttpConfig.java +++ b/backend/src/main/java/io/metersphere/api/dto/scenario/HttpConfig.java @@ -63,19 +63,29 @@ public class HttpConfig { } } - public HttpConfig getModuleCondition(String moduleId, HttpConfigCondition configCondition) { - List moduleIds = new ArrayList<>(); - if (CollectionUtils.isNotEmpty(configCondition.getDetails())) { - if (CollectionUtils.isEmpty(configCondition.getModuleIds())) { - for (KeyValue keyValue : configCondition.getDetails()) { - getAllChild(keyValue.getValue(), moduleIds); - } - configCondition.setModuleIds(moduleIds); - } else { - moduleIds = configCondition.getModuleIds(); - } +// public HttpConfig getModuleCondition(String moduleId, HttpConfigCondition configCondition) { +// List moduleIds = new ArrayList<>(); +// if (CollectionUtils.isNotEmpty(configCondition.getDetails())) { +// if (CollectionUtils.isEmpty(configCondition.getModuleIds())) { +// for (KeyValue keyValue : configCondition.getDetails()) { +// getAllChild(keyValue.getValue(), moduleIds); +// } +// configCondition.setModuleIds(moduleIds); +// } else { +// moduleIds = configCondition.getModuleIds(); +// } +// +// if (moduleIds.contains(moduleId)) { +// return initHttpConfig(configCondition); +// } +// } +// return null; +// } - if (moduleIds.contains(moduleId)) { + public HttpConfig getModuleCondition(String moduleId, HttpConfigCondition configCondition) { + if (CollectionUtils.isNotEmpty(configCondition.getDetails())) { + List details = configCondition.getDetails().stream().filter(detail -> StringUtils.contains(detail.getValue(), moduleId)).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(details)) { return initHttpConfig(configCondition); } } diff --git a/backend/src/main/java/io/metersphere/xpack b/backend/src/main/java/io/metersphere/xpack index 6e2b1d3d7d..a6a66f87a5 160000 --- a/backend/src/main/java/io/metersphere/xpack +++ b/backend/src/main/java/io/metersphere/xpack @@ -1 +1 @@ -Subproject commit 6e2b1d3d7d79f985e6edf81eb593670b8da87465 +Subproject commit a6a66f87a57346cdd7da22086bac5e82a7e47bdb diff --git a/frontend/src/business/components/api/definition/components/request/http/ApiHttpRequestForm.vue b/frontend/src/business/components/api/definition/components/request/http/ApiHttpRequestForm.vue index cea1f3a56b..41fc1d6928 100644 --- a/frontend/src/business/components/api/definition/components/request/http/ApiHttpRequestForm.vue +++ b/frontend/src/business/components/api/definition/components/request/http/ApiHttpRequestForm.vue @@ -69,7 +69,7 @@ @@ -83,246 +83,257 @@