This commit is contained in:
chenjianxing 2020-08-17 19:23:53 +08:00
commit 60ed8a0535
2 changed files with 8 additions and 7 deletions

View File

@ -30,11 +30,12 @@ public class JmeterDocumentParser {
private final static String ELEMENT_PROP = "elementProp";
public static byte[] parse(byte[] source) {
final InputSource inputSource = new InputSource(new ByteArrayInputStream(source));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
try (
ByteArrayInputStream byteStream = new ByteArrayInputStream(source)
) {
InputSource inputSource = new InputSource(byteStream);
DocumentBuilder docBuilder = factory.newDocumentBuilder();
final Document document = docBuilder.parse(inputSource);
final Element jmeterTestPlan = document.getDocumentElement();
@ -157,7 +158,6 @@ public class JmeterDocumentParser {
break;
case "Argument.value":
String textContent = ele.getTextContent();
System.out.println(textContent);
ele.setTextContent(ScriptEngineUtils.calculate(textContent));
break;
default:
@ -215,8 +215,6 @@ public class JmeterDocumentParser {
strUrlParas.put(key, value);
}
} else {
strUrlParas.put("errorParam", p);
}
}
return strUrlParas;

View File

@ -344,7 +344,10 @@ public class APITestService {
InputStream is = null;
try {
is = new ByteArrayInputStream(file.getBytes());
byte[] bytes = file.getBytes();
// 解析 xml 处理 mock 数据
bytes = JmeterDocumentParser.parse(bytes);
is = new ByteArrayInputStream(bytes);
} catch (IOException e) {
LogUtil.error(e);
}