Update XMLHandler#438
Conversation
| } catch (Exception ex) { | ||
| LOG.error("Error in handler: " + ex.getMessage(), ex); | ||
| return ""; | ||
| Node node = (Node) XPATH_FACTORY.newXPath() |
There was a problem hiding this comment.
GetElementAttr breaks its existing attribute-XPath contract. Expressions such as root/child/@first now return ""; element expressions instead concatenate every attribute value.
| return (org.jdom2.Element) XPath.selectSingleNode(this.xmlDocument, xPathExpression); | ||
| String currentPath = String.join("/", Arrays.copyOfRange(segments, 0, currentNode + 1)); | ||
|
|
||
| Node existing = (Node) XPATH_FACTORY.newXPath() |
There was a problem hiding this comment.
Namespace handling is nonfunctional. XPath instances never receive a NamespaceContext, parsing is not namespace-aware, and createElementNS receives a name with the prefix removed. The user-facing ns: request configuration therefore cannot create namespaced XML.
| * @return TRUE if the xPath expression exists; false otherwise | ||
| */ | ||
| public boolean xPathExists(String xpathExpr) | ||
| public boolean xPathExists(String xPathExpression) |
There was a problem hiding this comment.
evaluate(...) returns the XPath string value here, not the matched node. This makes existing empty elements report false, unlike the previous node-based implementation. Could this evaluate with XPathConstants.NODE and check for null? Please add coverage for <root><empty/></root>.
| private static final XPathFactory XPATH_FACTORY = XPathFactory.newInstance(); | ||
| private static final TransformerFactory TRANSFORMER_FACTORY; | ||
|
|
||
| static { |
There was a problem hiding this comment.
XXE hardening fails open. If one provider-specific feature is unsupported, the remaining features are skipped and parsing continues. Standard ACCESS_EXTERNAL_DTD/ACCESS_EXTERNAL_SCHEMA parser restrictions are also absent.
Update XMLHandler
Removes the
jdom2dependency and rewritesGenericXMLHandleron top of the JDK's built-injava.xmlAPIs (org.w3c.domDOM +javax.xmlXPath/Transformer).jdom2is being dropped because the XML exception types it throws have been removed from the Java runtime.What changed
jdom2removed from all POMs that declared it (pom.xml,agent_common,script_processor,web/web_ui).GenericXMLHandlerrewritten using DOM / XPath / Transformer:GetElementText,GetElementAttr,GetElementList,xPathExists), write (SetElementText,SetElementAttribute,Save), andtoString()reimplemented with nojdom2types.SetElementText/SetElementAttributestill build any missing path segments (and the root element) via a newresolveOrCreateElementhelper, soXMLRequestcan construct a body from an empty document as before.disallow-doctype-decl, external general/parameter entities disabled, XInclude off, entity-reference expansion off, and external DTD/stylesheet access cleared on the transformer.JsonHandler/JsonHandlerTestclasses are deleted.Tests
@generatedBy CodePro) stubs inGenericXMLHandlerTest/XMLRequestTestwith real assertions covering both the string- and file-based constructor paths, get/set of text & attributes,GetElementList,xPathExists(positive and negative),isXMLValid(valid + invalid),clone, and the path helpers.mvn clean testforagent_commonis green.Please make sure these check boxes are checked before submitting
mvn clean test -P default** PR review process **