Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: parse response by xml path in http collect #2593

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4d31312
refactor: parse response by xml path in http collect
Carpe-Wang Aug 24, 2024
3da4419
Merge branch 'master' into xml_path_23_8
Carpe-Wang Aug 24, 2024
8e36967
refactor: parse response by xml path in http collect
Carpe-Wang Aug 24, 2024
db9fffc
Merge remote-tracking branch 'origin/xml_path_23_8' into xml_path_23_8
Carpe-Wang Aug 24, 2024
81ad231
Merge branch 'master' into xml_path_23_8
yuluo-yx Aug 25, 2024
eaba224
Merge branch 'master' into xml_path_23_8
yuluo-yx Aug 25, 2024
d303881
Merge branch 'master' into xml_path_23_8
Carpe-Wang Aug 25, 2024
7452bcf
Merge branch 'master' into xml_path_23_8
yuluo-yx Aug 27, 2024
a61a318
Merge branch 'master' into xml_path_23_8
Aias00 Aug 31, 2024
eb24526
Merge branch 'master' into xml_path_23_8
Aias00 Aug 31, 2024
7c6c3ba
Merge branch 'master' into xml_path_23_8
Carpe-Wang Sep 1, 2024
6f283ef
Merge branch 'master' into xml_path_23_8
Aias00 Sep 2, 2024
a03c9cc
Merge branch 'master' into xml_path_23_8
Aias00 Sep 3, 2024
b523e85
Merge branch 'master' into xml_path_23_8
Aias00 Sep 3, 2024
31aa6c9
Merge branch 'master' into xml_path_23_8
Aias00 Sep 4, 2024
874a3a2
Merge branch 'master' into xml_path_23_8
Aias00 Sep 4, 2024
62cd16e
Merge branch 'master' into xml_path_23_8
Aias00 Sep 4, 2024
4b8f7b8
Merge branch 'master' into xml_path_23_8
Aias00 Sep 5, 2024
5c9b65a
Merge branch 'master' into xml_path_23_8
Aias00 Sep 7, 2024
6a7be94
Merge branch 'master' into xml_path_23_8
Aias00 Sep 8, 2024
cdd6504
Merge branch 'master' into xml_path_23_8
Aias00 Sep 9, 2024
ce73683
Merge branch 'master' into xml_path_23_8
Aias00 Sep 10, 2024
bc019b1
Merge branch 'master' into xml_path_23_8
Aias00 Sep 12, 2024
afc8926
Merge branch 'master' into xml_path_23_8
Aias00 Sep 13, 2024
225157a
Merge branch 'master' into xml_path_23_8
Aias00 Sep 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,38 @@ private void parseResponseBySiteMap(String resp, List<String> aliasFields,

private void parseResponseByXmlPath(String resp, List<String> aliasFields, HttpProtocol http,
CollectRep.MetricsData.Builder builder) {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builderFactory = factory.newDocumentBuilder();

Document document = builderFactory.parse(new ByteArrayInputStream(resp.getBytes(StandardCharsets.UTF_8)));
document.getDocumentElement().normalize();

for (String alias : aliasFields) {
NodeList nodeList = document.getElementsByTagName(alias);
if (nodeList.getLength() > 0) {
Node node = nodeList.item(0);
String value = node.getTextContent();

CollectRep.ValueRow.Builder valueRowBuilder = CollectRep.ValueRow.newBuilder();
valueRowBuilder.addColumns(value);
builder.addValues(valueRowBuilder.build());
} else {
CollectRep.ValueRow.Builder valueRowBuilder = CollectRep.ValueRow.newBuilder();
valueRowBuilder.addColumns(CommonConstants.NULL_VALUE);
builder.addValues(valueRowBuilder.build());
}
}

} catch (Exception e) {
String errorMsg = "Error parsing XML response: " + e.getMessage();
log.error(errorMsg, e);
builder.setCode(CollectRep.Code.FAIL);
builder.setMsg(errorMsg);
}
}


private void parseResponseByJsonPath(String resp, List<String> aliasFields, HttpProtocol http,
CollectRep.MetricsData.Builder builder, Long responseTime) {
List<Object> results = JsonPathParser.parseContentWithJsonPath(resp, http.getParseScript());
Expand Down
Loading