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

XMLAssertion : drop jdom dependency by using XMLReader #3894

Closed
asfimport opened this issue Mar 9, 2016 · 4 comments
Closed

XMLAssertion : drop jdom dependency by using XMLReader #3894

asfimport opened this issue Mar 9, 2016 · 4 comments

Comments

@asfimport
Copy link
Collaborator

@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

@asfimport
Copy link
Collaborator Author

@pmouawad (migrated from Bugzilla):
Created attachment BUG_59156.patch: Patch dropping JDOM

BUG_59156.patch
Index: 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;

@asfimport
Copy link
Collaborator Author

@pmouawad (migrated from Bugzilla):
Author: pmouawad
Date: Sat Mar 12 14:25:49 2016
New Revision: 1734706

URL: http://svn.apache.org/viewvc?rev=1734706&view=rev
Log:
#3894 - XMLAssertion : drop jdom dependency by using XMLReader
Move code to standard Java XML API
Fix Tests to remove dependencies on jdom
Move jdom download to lib/doc as it is needed for printable documentation generation (Anakia)
Remove jdom from Maven dependencies and also remove velocity version property by the way as it is not needed (commented)
Move jdom reference in build.properties in the doc block
#3894

Modified:
jmeter/trunk/build.properties
jmeter/trunk/build.xml
jmeter/trunk/eclipse.classpath
jmeter/trunk/lib/ (props changed)
jmeter/trunk/lib/aareadme.txt
jmeter/trunk/lib/doc/ (props changed)
jmeter/trunk/res/maven/ApacheJMeter_parent.pom
jmeter/trunk/src/components/org/apache/jmeter/assertions/XMLAssertion.java
jmeter/trunk/test/src/org/apache/jmeter/functions/ComponentReferenceFunctionTest.java
jmeter/trunk/test/src/org/apache/jmeter/junit/JMeterTest.java
jmeter/trunk/xdocs/changes.xml

@asfimport
Copy link
Collaborator Author

@pmouawad (migrated from Bugzilla):
Author: pmouawad
Date: Sat Mar 12 20:18:49 2016
New Revision: 1734731

URL: http://svn.apache.org/viewvc?rev=1734731&view=rev
Log:
#3894 - XMLAssertion : drop jdom dependency by using XMLReader
jdom is now a jar for docs
#3894

Modified:
jmeter/trunk/test/src/org/apache/jmeter/JMeterVersionTest.java

@asfimport
Copy link
Collaborator Author

@pmouawad (migrated from Bugzilla):
Author: pmouawad
Date: Sat Mar 12 20:58:04 2016
New Revision: 1734736

URL: http://svn.apache.org/viewvc?rev=1734736&view=rev
Log:
#3894 - XMLAssertion : drop jdom dependency by using XMLReader
Fix bug
#3894

Modified:
jmeter/trunk/src/components/org/apache/jmeter/assertions/XMLAssertion.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant