From cb6f8f716ca3b07e9d0a1246346276e827507b6a Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Mon, 6 Dec 2021 11:40:31 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E5=AF=BC=E5=85=A5jmx=E6=96=87=E4=BB=B6query=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1008540 --user=赵勇 【github#8283】jmeter脚本上传到ms之后url拼接丢失 https://www.tapd.cn/55049933/s/1077896 --- .../dto/automation/parse/MsJmeterParser.java | 61 +++++++++++++------ 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/parse/MsJmeterParser.java b/backend/src/main/java/io/metersphere/api/dto/automation/parse/MsJmeterParser.java index 9cf36881ba..10e2f7cbba 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/parse/MsJmeterParser.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/parse/MsJmeterParser.java @@ -175,7 +175,6 @@ public class MsJmeterParser extends ApiImportAbstractParser { if (!path.startsWith("http://") && !path.startsWith("https://")) { String domain = source.getDomain(); String protocol = source.getProtocol(); - String method = source.getMethod(); StringBuilder pathAndQuery = new StringBuilder(100); if ("file".equalsIgnoreCase(protocol)) { domain = null; @@ -184,18 +183,6 @@ public class MsJmeterParser extends ApiImportAbstractParser { } pathAndQuery.append(path); - if ("GET".equals(method) || "DELETE".equals(method) || "OPTIONS".equals(method)) { - String queryString = source.getQueryString(source.getContentEncoding()); - if (queryString.length() > 0) { - if (path.contains("?")) { - pathAndQuery.append("&"); - } else { - pathAndQuery.append("?"); - } - - pathAndQuery.append(queryString); - } - } String portAsString = source.getPropertyAsString("HTTPSampler.port"); return this.isProtocolDefaultPort(source) ? new URL(protocol, domain, pathAndQuery.toString()).toExternalForm() : this.url(protocol, domain, portAsString, pathAndQuery.toString()); } else { @@ -213,6 +200,44 @@ public class MsJmeterParser extends ApiImportAbstractParser { return null; } + private static String truncateUrlPage(String strURL) { + String strAllParam = null; + if (StringUtils.isNotEmpty(strURL)) { + String[] arrSplit = strURL.split("[?]"); + if (strURL.length() > 1) { + if (arrSplit.length > 1) { + if (arrSplit[1] != null) { + strAllParam = arrSplit[1]; + } + } + } + } + return strAllParam; + } + + public static Map parseURLParam(String URL) { + Map mapRequest = new LinkedHashMap<>(); + String strUrlParam = truncateUrlPage(URL); + if (StringUtils.isEmpty(strUrlParam)) { + return mapRequest; + } + //每个键值为一组 + String[] arrSplit = strUrlParam.split("[&]"); + for (String strSplit : arrSplit) { + String[] arrSplitEqual = strSplit.split("[=]"); + //解析出键值 + if (arrSplitEqual.length > 1) { + mapRequest.put(arrSplitEqual[0], arrSplitEqual[1]); + } else { + if (StringUtils.isNotEmpty(arrSplitEqual[0])) { + //只有参数没有值,不加入 + mapRequest.put(arrSplitEqual[0], ""); + } + } + } + return mapRequest; + } + private void convertHttpSampler(MsHTTPSamplerProxy samplerProxy, Object key) { try { HTTPSamplerProxy source = (HTTPSamplerProxy) key; @@ -303,9 +328,9 @@ public class MsJmeterParser extends ApiImportAbstractParser { } samplerProxy.getBody().initBinary(); } - // samplerProxy.setPath(source.getPath()); samplerProxy.setMethod(source.getMethod()); - if (this.getUrl(source) != null) { + URL url = source.getUrl(); + if (url != null) { samplerProxy.setUrl(this.getUrl(source)); samplerProxy.setPath(null); } @@ -530,9 +555,11 @@ public class MsJmeterParser extends ApiImportAbstractParser { RegexExtractor regexExtractor = (RegexExtractor) key; if (regexExtractor.useRequestHeaders()) { regex.setUseHeaders("request_headers"); - }if (regexExtractor.useHeaders()) { + } + if (regexExtractor.useHeaders()) { regex.setUseHeaders("true"); - } if (regexExtractor.useBody()) { + } + if (regexExtractor.useBody()) { regex.setUseHeaders("false"); } else if (regexExtractor.useUnescapedBody()) { regex.setUseHeaders("unescaped");