jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1832787 - in /jmeter/trunk/src: components/org/apache/jmeter/visualizers/RenderAsXPath2.java core/org/apache/jmeter/util/XPathQueryCacheLoader.java core/org/apache/jmeter/util/XPathUtil.java
Date Sun, 03 Jun 2018 20:12:50 GMT
Author: pmouawad
Date: Sun Jun  3 20:12:49 2018
New Revision: 1832787

URL: http://svn.apache.org/viewvc?rev=1832787&view=rev
Log:
Bug 60991 - XPath Extractor : Implement XPath 2.0

Fix failures on import order
Use isNotEmpty
Ensure context is cleaned up on each call
Bugzilla Id: 60991

Modified:
    jmeter/trunk/src/components/org/apache/jmeter/visualizers/RenderAsXPath2.java
    jmeter/trunk/src/core/org/apache/jmeter/util/XPathQueryCacheLoader.java
    jmeter/trunk/src/core/org/apache/jmeter/util/XPathUtil.java

Modified: jmeter/trunk/src/components/org/apache/jmeter/visualizers/RenderAsXPath2.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/visualizers/RenderAsXPath2.java?rev=1832787&r1=1832786&r2=1832787&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/visualizers/RenderAsXPath2.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/visualizers/RenderAsXPath2.java Sun Jun
 3 20:12:49 2018
@@ -129,7 +129,8 @@ public class RenderAsXPath2 implements R
     private String process(String textToParse, XPath2Extractor extractor) {
         try {
             List<String> matchStrings = new ArrayList<>();
-            XPathUtil.putValuesForXPathInListUsingSaxon(textToParse, xpathExpressionField.getText(),
matchStrings, extractor.getFragment(), -1, getDocumentNamespaces(textToParse));
+            XPathUtil.putValuesForXPathInListUsingSaxon(textToParse, xpathExpressionField.getText(),
+                    matchStrings, extractor.getFragment(), -1, getDocumentNamespaces(textToParse));
             StringBuilder builder = new StringBuilder();
             int nbFound = matchStrings.size();
             builder.append("Match count: ").append(nbFound).append("\n");

Modified: jmeter/trunk/src/core/org/apache/jmeter/util/XPathQueryCacheLoader.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/util/XPathQueryCacheLoader.java?rev=1832787&r1=1832786&r2=1832787&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/util/XPathQueryCacheLoader.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/util/XPathQueryCacheLoader.java Sun Jun  3 20:12:49
2018
@@ -24,12 +24,12 @@ import org.apache.commons.lang3.tuple.Im
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.github.benmanes.caffeine.cache.CacheLoader;
-
 import net.sf.saxon.s9api.Processor;
 import net.sf.saxon.s9api.XPathCompiler;
 import net.sf.saxon.s9api.XPathExecutable;
 
+import com.github.benmanes.caffeine.cache.CacheLoader;
+
 /**
  * load method is called when the key composed of
  * namespaces + xPathQuery is not in the cache.

Modified: jmeter/trunk/src/core/org/apache/jmeter/util/XPathUtil.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/util/XPathUtil.java?rev=1832787&r1=1832786&r2=1832787&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/util/XPathUtil.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/util/XPathUtil.java Sun Jun  3 20:12:49 2018
@@ -47,6 +47,7 @@ import javax.xml.transform.sax.SAXSource
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.jmeter.assertions.AssertionResult;
 import org.apache.xml.utils.PrefixResolver;
@@ -65,9 +66,6 @@ import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import org.xml.sax.SAXParseException;
 
-import com.github.benmanes.caffeine.cache.Caffeine;
-import com.github.benmanes.caffeine.cache.LoadingCache;
-
 import net.sf.saxon.s9api.Processor;
 import net.sf.saxon.s9api.SaxonApiException;
 import net.sf.saxon.s9api.XPathExecutable;
@@ -76,6 +74,9 @@ import net.sf.saxon.s9api.XdmItem;
 import net.sf.saxon.s9api.XdmNode;
 import net.sf.saxon.s9api.XdmValue;
 
+import com.github.benmanes.caffeine.cache.Caffeine;
+import com.github.benmanes.caffeine.cache.LoadingCache;
+
 /**
  * This class provides a few utility methods for dealing with XML/XPath.
  */
@@ -366,8 +367,6 @@ public class XPathUtil {
         putValuesForXPathInList(document, xPathQuery, matchStrings, fragment, -1);
     }
 
-
-
     /**
      * Put in matchStrings results of evaluation
      * @param document XML document
@@ -428,7 +427,7 @@ public class XPathUtil {
 
         //check the cache
         XPathExecutable xPathExecutable;
-        if(!xPathQuery.equals("")) {
+        if(StringUtils.isNotEmpty(xPathQuery)) {
             xPathExecutable = XPATH_CACHE.get(key);
         }
         else {
@@ -445,31 +444,42 @@ public class XPathUtil {
             XdmNode xdmNode = builder.build(new StreamSource(reader));
             
             if(xPathExecutable!=null) {
-                XPathSelector selector = xPathExecutable.load();
-                selector.setContextItem(xdmNode);
-                XdmValue nodes = selector.evaluate();
-                int length = nodes.size();
-                int indexToMatch = matchNumber;
-                // In case we need to extract everything
-                if(matchNumber < 0) {
-                    for(XdmItem item : nodes) {
-                        if(fragment) {
-                            matchStrings.add(item.toString());
+                XPathSelector selector = null;
+                try {
+                    selector = xPathExecutable.load();
+                    selector.setContextItem(xdmNode);
+                    XdmValue nodes = selector.evaluate();
+                    int length = nodes.size();
+                    int indexToMatch = matchNumber;
+                    // In case we need to extract everything
+                    if(matchNumber < 0) {
+                        for(XdmItem item : nodes) {
+                            if(fragment) {
+                                matchStrings.add(item.toString());
+                            }
+                            else {
+                                matchStrings.add(item.getStringValue());
+                            }
                         }
-                        else {
-                            matchStrings.add(item.getStringValue());
+                    } else {
+                        if(indexToMatch <= length) {
+                            if(matchNumber == 0 && length>0) {
+                                indexToMatch = JMeterUtils.getRandomInt(length)+1;
+                            } 
+                            XdmItem item = nodes.itemAt(indexToMatch-1);
+                            matchStrings.add(fragment ? item.toString() : item.getStringValue());
+                        } else {
+                            if(log.isWarnEnabled()) {
+                                log.warn("Error : {}{}", JMeterUtils.getResString("xpath2_extractor_match_number_failure"),indexToMatch);
+                            }
                         }
                     }
-                } else {
-                    if(indexToMatch <= length) {
-                        if(matchNumber == 0 && length>0) {
-                            indexToMatch = JMeterUtils.getRandomInt(length)+1;
-                        } 
-                        XdmItem item = nodes.itemAt(indexToMatch-1);
-                        matchStrings.add(fragment ? item.toString() : item.getStringValue());
-                    } else {
-                        if(log.isWarnEnabled()) {
-                            log.warn("Error : {}{}", JMeterUtils.getResString("xpath2_extractor_match_number_failure"),indexToMatch);
+                } finally {
+                    if(selector != null) {
+                        try {
+                            selector.getUnderlyingXPathContext().setContextItem(null);
+                        } catch (Exception e) {
+                            // NOOP
                         }
                     }
                 }
@@ -553,8 +563,6 @@ public class XPathUtil {
         }
     }
 
-
-
     /**
      * 
      * @param document XML Document



Mime
View raw message