Skip to content

Commit

Permalink
fix(性能测试): 修改多jmx情况下无法准确判断是否含有脚本的问题
Browse files Browse the repository at this point in the history
--bug=1026467 --user=宋天阳 【性能测试】编辑性能测试添加自定义脚本jmx文件消息中心无提示
https://www.tapd.cn/55049933/s/1374904
  • Loading branch information
Somebody-JIAN committed May 24, 2023
1 parent 4f7788c commit 9f25002
Showing 1 changed file with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.*;
import org.xml.sax.InputSource;

import javax.xml.parsers.DocumentBuilder;
Expand All @@ -33,7 +30,9 @@ public static boolean isJmxHasScriptByFiles(List<MultipartFile> files) {
public static boolean isJmxHasScriptByStorage(List<FileContent> fileContentList) {
for (FileContent fileContent : fileContentList) {
try {
return jmxBytesHasScript(fileContent.getFile());
if (jmxBytesHasScript(fileContent.getFile())) {
return true;
}
} catch (Exception e) {
LogUtil.error("下载jmx文件解析是否含有脚本数据失败", e);
}
Expand Down Expand Up @@ -107,6 +106,22 @@ private static boolean invalid(Element ele) {
}

private static boolean nodeIsScript(Node node) {
return StringUtils.containsAnyIgnoreCase(node.getNodeName(), "JSR223", "Processor");
if (StringUtils.containsAnyIgnoreCase(node.getNodeName(), "JSR223", "Processor")) {
//JSR223 或者 Processor,判断里面是否有Script字段。 存在Script字段就是脚本
final NodeList childNodes = node.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node childNode = childNodes.item(i);
NamedNodeMap namedNodeMap = childNode.getAttributes();
if (namedNodeMap != null) {
for (int j = 0; j < namedNodeMap.getLength(); j++) {
Node nodeJ = namedNodeMap.item(j);
if (StringUtils.equalsIgnoreCase(nodeJ.getNodeValue(), "script")) {
return true;
}
}
}
}
}
return false;
}
}

0 comments on commit 9f25002

Please sign in to comment.