优化jmeter工具类

This commit is contained in:
liangdaliang
2025-03-06 18:00:06 +08:00
parent c7237be7e9
commit 632c673e99

View File

@@ -419,15 +419,14 @@ public class JMeterUtil {
if (responseDataList.getLength() > 0) { if (responseDataList.getLength() > 0) {
Element responseDataElement = (Element) responseDataList.item(0); Element responseDataElement = (Element) responseDataList.item(0);
resultMap.put("responseBody", responseDataElement.getTextContent()); resultMap.put("responseBody", responseDataElement.getTextContent());
return resultMap;
} }
// 提取子节点<responseHeader>的内容 // 提取子节点<responseHeader>的内容
NodeList responseHeaderList = httpSampleElement.getElementsByTagName("responseHeader"); NodeList responseHeaderList = httpSampleElement.getElementsByTagName("responseHeader");
if (responseHeaderList.getLength() > 0) { if (responseHeaderList.getLength() > 0) {
Element responseHeaderElement = (Element) responseHeaderList.item(0); Element responseHeaderElement = (Element) responseHeaderList.item(0);
resultMap.put("responseHeader", responseHeaderElement.getTextContent()); resultMap.put("responseHeader", responseHeaderElement.getTextContent());
return resultMap;
} }
return resultMap;
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@@ -442,6 +441,9 @@ public class JMeterUtil {
*/ */
public static Map<String, String> parseHeaders(String responseHeader) { public static Map<String, String> parseHeaders(String responseHeader) {
Map<String, String> headerMap = new HashMap<>(); Map<String, String> headerMap = new HashMap<>();
if (responseHeader == null) {
return headerMap;
}
// 按行拆分 // 按行拆分
String[] lines = responseHeader.split("\n"); String[] lines = responseHeader.split("\n");
// 遍历每一行 // 遍历每一行