From 46586e7da60151a4ddb6cc3b10233f43aa33f427 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Tue, 14 Jul 2020 17:23:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Djmx=E5=8F=AA=E6=9C=89?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E7=BB=84=E6=B2=A1=E6=9C=89=E9=87=87=E6=A0=B7?= =?UTF-8?q?=E5=99=A8=E5=AF=BC=E8=87=B4=E6=97=A0=E6=B3=95=E6=94=B6=E5=88=B0?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metersphere/performance/engine/EngineFactory.java | 2 ++ .../performance/engine/docker/DockerTestEngine.java | 2 ++ .../parse/xml/reader/jmx/JmeterDocumentParser.java | 10 ++++++++++ .../src/main/resources/i18n/messages_en_US.properties | 1 + .../src/main/resources/i18n/messages_zh_CN.properties | 1 + .../src/main/resources/i18n/messages_zh_TW.properties | 1 + 6 files changed, 17 insertions(+) diff --git a/backend/src/main/java/io/metersphere/performance/engine/EngineFactory.java b/backend/src/main/java/io/metersphere/performance/engine/EngineFactory.java index 0c2036a07d..835534dc39 100644 --- a/backend/src/main/java/io/metersphere/performance/engine/EngineFactory.java +++ b/backend/src/main/java/io/metersphere/performance/engine/EngineFactory.java @@ -110,6 +110,8 @@ public class EngineFactory { try (ByteArrayInputStream source = new ByteArrayInputStream(fileContent.getFile())) { String content = engineSourceParser.parse(engineContext, source); engineContext.setContent(content); + } catch (MSException e) { + throw e; } catch (Exception e) { MSException.throwException(e); } diff --git a/backend/src/main/java/io/metersphere/performance/engine/docker/DockerTestEngine.java b/backend/src/main/java/io/metersphere/performance/engine/docker/DockerTestEngine.java index aa02ef77bb..41964c9967 100644 --- a/backend/src/main/java/io/metersphere/performance/engine/docker/DockerTestEngine.java +++ b/backend/src/main/java/io/metersphere/performance/engine/docker/DockerTestEngine.java @@ -66,6 +66,8 @@ public class DockerTestEngine extends AbstractEngine { EngineContext context = null; try { context = EngineFactory.createContext(loadTest, resource.getId(), realThreadNum, this.getStartTime(), this.getReportId(), resourceIndex); + } catch (MSException e) { + throw e; } catch (Exception e) { MSException.throwException(e); } diff --git a/backend/src/main/java/io/metersphere/performance/parse/xml/reader/jmx/JmeterDocumentParser.java b/backend/src/main/java/io/metersphere/performance/parse/xml/reader/jmx/JmeterDocumentParser.java index 6ae7ea9bcb..895d256578 100644 --- a/backend/src/main/java/io/metersphere/performance/parse/xml/reader/jmx/JmeterDocumentParser.java +++ b/backend/src/main/java/io/metersphere/performance/parse/xml/reader/jmx/JmeterDocumentParser.java @@ -2,8 +2,10 @@ package io.metersphere.performance.parse.xml.reader.jmx; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.config.KafkaProperties; +import io.metersphere.i18n.Translator; import io.metersphere.performance.engine.EngineContext; import io.metersphere.performance.parse.xml.reader.DocumentParser; import org.apache.commons.lang3.StringUtils; @@ -709,6 +711,14 @@ public class JmeterDocumentParser implements DocumentParser { } private void processThreadGroup(Element threadGroup) { + // 检查 threadgroup 后面的hashtree是否为空 + Node hashTree = threadGroup.getNextSibling(); + while (!(hashTree instanceof Element)) { + hashTree = hashTree.getNextSibling(); + } + if (!hashTree.hasChildNodes()) { + MSException.throwException(Translator.get("jmx_content_valid")); + } // 重命名 tagName Document document = threadGroup.getOwnerDocument(); document.renameNode(threadGroup, threadGroup.getNamespaceURI(), CONCURRENCY_THREAD_GROUP); diff --git a/backend/src/main/resources/i18n/messages_en_US.properties b/backend/src/main/resources/i18n/messages_en_US.properties index 1d14244156..3235997a3b 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -45,6 +45,7 @@ duplicate_node_ip=Duplicate IPs max_thread_insufficient=The number of concurrent users exceeds related_case_del_fail_prefix=Connected to related_case_del_fail_suffix=TestCase, please disassociate first +jmx_content_valid=JMX content is invalid #workspace workspace_name_is_null=Workspace name cannot be null workspace_name_already_exists=The workspace name already exists diff --git a/backend/src/main/resources/i18n/messages_zh_CN.properties b/backend/src/main/resources/i18n/messages_zh_CN.properties index 1a0bb91584..45c659347c 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -45,6 +45,7 @@ duplicate_node_ip=节点 IP 重复 max_thread_insufficient=并发用户数超额 related_case_del_fail_prefix=已关联到 related_case_del_fail_suffix=测试用例,请先解除关联 +jmx_content_valid=JMX 内容无效,请检查 #workspace workspace_name_is_null=工作空间名不能为空 workspace_name_already_exists=工作空间名已存在 diff --git a/backend/src/main/resources/i18n/messages_zh_TW.properties b/backend/src/main/resources/i18n/messages_zh_TW.properties index 79d31c162b..61d3091cd7 100644 --- a/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -45,6 +45,7 @@ duplicate_node_ip=節點 IP 重復 max_thread_insufficient=並發用戶數超額 related_case_del_fail_prefix=已關聯到 related_case_del_fail_suffix=測試用例,請先解除關聯 +jmx_content_valid=JMX 內容無效,請檢查 #workspace workspace_name_is_null=工作空間名不能為空 workspace_name_already_exists=工作空間名已存在