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
XMLAssertion : drop jdom dependency by using XMLReader #3894
Comments
@pmouawad (migrated from Bugzilla): BUG_59156.patchIndex: src/components/org/apache/jmeter/assertions/XMLAssertion.java
===================================================================
--- src/components/org/apache/jmeter/assertions/XMLAssertion.java (revision 1719809)
+++ src/components/org/apache/jmeter/assertions/XMLAssertion.java (working copy)
@@ -22,13 +22,18 @@
import java.io.Serializable;
import java.io.StringReader;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.testelement.AbstractTestElement;
import org.apache.jmeter.testelement.ThreadListener;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;
-import org.jdom.JDOMException;
-import org.jdom.input.SAXBuilder;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
/**
* Checks if the result is a well-formed XML content using jdom
@@ -37,13 +42,17 @@
public class XMLAssertion extends AbstractTestElement implements Serializable, Assertion, ThreadListener {
private static final Logger log = LoggingManager.getLoggerForClass();
- private static final long serialVersionUID = 240L;
+ private static final long serialVersionUID = 241L;
// one builder for all requests in a thread
- private static final ThreadLocal<SAXBuilder> myBuilder = new ThreadLocal<SAXBuilder>() {
+ private static final ThreadLocal<SAXParser> myBuilder = new ThreadLocal<SAXParser>() {
@Override
- protected SAXBuilder initialValue() {
- return new SAXBuilder();
+ protected SAXParser initialValue() {
+ try {
+ return SAXParserFactory.newInstance().newSAXParser();
+ } catch (ParserConfigurationException | SAXException e) {
+ return null;
+ }
}
};
@@ -62,18 +71,18 @@
return result.setResultForNull();
}
result.setFailure(false);
- SAXBuilder builder = myBuilder.get();
-
- try {
- builder.build(new StringReader(resultData));
- } catch (JDOMException e) {
- log.debug("Cannot parse result content", e); // may well happen
- result.setFailure(true);
- result.setFailureMessage(e.getMessage());
- } catch (IOException e) {
- log.error("Cannot read result content", e); // should never happen
+ SAXParser builder = myBuilder.get();
+ if(myBuilder!=null) {
+ try {
+ builder.parse(new InputSource(new StringReader(resultData)), new DefaultHandler());
+ } catch (SAXException | IOException e) {
+ log.error("Cannot read result content", e); // should never happen
+ result.setError(true);
+ result.setFailureMessage(e.getMessage());
+ }
+ } else {
result.setError(true);
- result.setFailureMessage(e.getMessage());
+ result.setFailureMessage("Cannot initialize SAXParser, check jmeter.log file");
}
return result; |
@pmouawad (migrated from Bugzilla): URL: http://svn.apache.org/viewvc?rev=1734706&view=rev Modified: |
@pmouawad (migrated from Bugzilla): URL: http://svn.apache.org/viewvc?rev=1734731&view=rev Modified: |
@pmouawad (migrated from Bugzilla): URL: http://svn.apache.org/viewvc?rev=1734736&view=rev Modified: |
@pmouawad (Bug 59156):
Hello,
This assertion only checks that response is well-formed XML by parsing the file using JDom 1.X which is now deprecated.
I personally don't find it very useful and have never used it.
So I would tend to drop it.
If we decide to keep it, then at least we should drop jdom dependency by just using a javax SAXParser instead of:
http://www.jdom.org/docs/apidocs.1.1/org/jdom/input/SAXBuilder.html
OS: All
The text was updated successfully, but these errors were encountered: