From fb9f992b60f881318af59e3b25b389c34dd28083 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Wed, 18 May 2022 20:24:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E5=AF=BC=E5=87=BAJMX=E6=97=B6host=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E5=A2=9E=E5=8A=A0=E5=B8=A6=E7=AB=AF=E5=8F=A3=E5=8F=B7?= =?UTF-8?q?=E5=9F=9F=E5=90=8D=E7=9A=84=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 场景导出JMX时host转换增加带端口号域名的解析 --- .../request/dns/MsDNSCacheManager.java | 2 + .../request/sampler/MsHTTPSamplerProxy.java | 60 +++++++++++-------- 2 files changed, 38 insertions(+), 24 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/dns/MsDNSCacheManager.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/dns/MsDNSCacheManager.java index ce7f14672c..1916b3f367 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/dns/MsDNSCacheManager.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/dns/MsDNSCacheManager.java @@ -76,6 +76,8 @@ public class MsDNSCacheManager extends MsTestElement { String hostDomain = host.getDomain().trim().replace("http://", "").replace("https://", ""); if (StringUtils.equals(hostDomain, domain)) { dnsMap.put(hostDomain, host.getIp()); + }else if(StringUtils.startsWith(hostDomain,domain+":")){ + dnsMap.put(domain,StringUtils.replace(hostDomain,domain,host.getIp())); } } }); 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 8ed1ecfd0a..c9604fc22a 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 @@ -216,10 +216,22 @@ public class MsHTTPSamplerProxy extends MsTestElement { if (config.isOperating() && config.isEffective(this.getProjectId()) && config.getConfig().get(this.getProjectId()).getCommonConfig() != null && config.getConfig().get(this.getProjectId()).getCommonConfig().isEnableHost()) { //导出的需要将DNSCache去掉,并把域名进行ip替换 - Map dnsMap = MsDNSCacheManager.getEnvironmentDns(config.getConfig().get(this.getProjectId()), httpConfig); + Map dnsMap = MsDNSCacheManager.getEnvironmentDns(config.getConfig().get(this.getProjectId()), httpConfig); String domain = sampler.getDomain(); - if(dnsMap.containsKey(domain)){ - sampler.setDomain(dnsMap.get(domain)); + if (dnsMap.containsKey(domain)) { + String address = dnsMap.get(domain); + if (address.contains(":")) { + String[] addressArr = StringUtils.split(address, ":"); + if (addressArr.length == 2) { + try { + sampler.setDomain(addressArr[0]); + sampler.setPort(Integer.parseInt(addressArr[1])); + } catch (Exception ignored) { + } + } + } else { + sampler.setDomain(dnsMap.get(domain)); + } } } final HashTree httpSamplerTree = tree.add(sampler); @@ -682,28 +694,28 @@ public class MsHTTPSamplerProxy extends MsTestElement { list.stream(). filter(KeyValue::isValid). filter(KeyValue::isEnable).forEach(keyValue -> { - try { - String value = StringUtils.isNotEmpty(keyValue.getValue()) && keyValue.getValue().startsWith("@") ? ScriptEngineUtils.buildFunctionCallString(keyValue.getValue()) : keyValue.getValue(); - HTTPArgument httpArgument = new HTTPArgument(keyValue.getName(), value); - if (keyValue.getValue() == null) { - httpArgument.setValue(""); - } - httpArgument.setAlwaysEncoded(keyValue.isUrlEncode()); - if (StringUtils.isNotBlank(keyValue.getContentType())) { - httpArgument.setContentType(keyValue.getContentType()); - } - if (StringUtils.equalsIgnoreCase(this.method, "get")) { - if (StringUtils.isNotEmpty(httpArgument.getValue())) { - arguments.addArgument(httpArgument); - } - } else { - arguments.addArgument(httpArgument); - } - } catch (Exception e) { + try { + String value = StringUtils.isNotEmpty(keyValue.getValue()) && keyValue.getValue().startsWith("@") ? ScriptEngineUtils.buildFunctionCallString(keyValue.getValue()) : keyValue.getValue(); + HTTPArgument httpArgument = new HTTPArgument(keyValue.getName(), value); + if (keyValue.getValue() == null) { + httpArgument.setValue(""); + } + httpArgument.setAlwaysEncoded(keyValue.isUrlEncode()); + if (StringUtils.isNotBlank(keyValue.getContentType())) { + httpArgument.setContentType(keyValue.getContentType()); + } + if (StringUtils.equalsIgnoreCase(this.method, "get")) { + if (StringUtils.isNotEmpty(httpArgument.getValue())) { + arguments.addArgument(httpArgument); + } + } else { + arguments.addArgument(httpArgument); + } + } catch (Exception e) { - } - } - ); + } + } + ); return arguments; }