Link Here
|
20 |
import java.io.ByteArrayInputStream; |
20 |
import java.io.ByteArrayInputStream; |
21 |
import java.io.IOException; |
21 |
import java.io.IOException; |
22 |
import java.io.Serializable; |
22 |
import java.io.Serializable; |
23 |
import java.io.UnsupportedEncodingException; |
|
|
24 |
import java.io.StringWriter; |
23 |
import java.io.StringWriter; |
|
|
24 |
import java.io.UnsupportedEncodingException; |
25 |
import java.util.ArrayList; |
25 |
import java.util.ArrayList; |
26 |
import java.util.List; |
26 |
import java.util.List; |
27 |
|
27 |
|
28 |
import javax.xml.parsers.ParserConfigurationException; |
28 |
import javax.xml.parsers.ParserConfigurationException; |
|
|
29 |
import javax.xml.transform.OutputKeys; |
30 |
import javax.xml.transform.Transformer; |
29 |
import javax.xml.transform.TransformerException; |
31 |
import javax.xml.transform.TransformerException; |
|
|
32 |
import javax.xml.transform.TransformerFactory; |
33 |
import javax.xml.transform.dom.DOMSource; |
34 |
import javax.xml.transform.stream.StreamResult; |
30 |
|
35 |
|
31 |
import org.apache.jmeter.assertions.AssertionResult; |
36 |
import org.apache.jmeter.assertions.AssertionResult; |
32 |
import org.apache.jmeter.processor.PostProcessor; |
37 |
import org.apache.jmeter.processor.PostProcessor; |
Link Here
|
49 |
import org.w3c.dom.NodeList; |
54 |
import org.w3c.dom.NodeList; |
50 |
import org.xml.sax.SAXException; |
55 |
import org.xml.sax.SAXException; |
51 |
|
56 |
|
52 |
import javax.xml.transform.OutputKeys; |
|
|
53 |
import javax.xml.transform.Transformer; |
54 |
import javax.xml.transform.TransformerFactory; |
55 |
import javax.xml.transform.dom.DOMSource; |
56 |
import javax.xml.transform.stream.StreamResult; |
57 |
|
58 |
//@see org.apache.jmeter.extractor.TestXPathExtractor for unit tests |
57 |
//@see org.apache.jmeter.extractor.TestXPathExtractor for unit tests |
59 |
|
58 |
|
60 |
/** |
59 |
/** |
Link Here
|
135 |
vars.put(matchNR, "0"); // In case parse fails // $NON-NLS-1$ |
134 |
vars.put(matchNR, "0"); // In case parse fails // $NON-NLS-1$ |
136 |
vars.remove(concat(refName,"1")); // In case parse fails // $NON-NLS-1$ |
135 |
vars.remove(concat(refName,"1")); // In case parse fails // $NON-NLS-1$ |
137 |
|
136 |
|
138 |
List<SampleResult> samples = getSampleList(previousResult); |
137 |
List<String> matches = new ArrayList<String>(); |
139 |
try{ |
138 |
try{ |
140 |
List<String> matches = new ArrayList<String>(); |
139 |
if (isScopeVariable()){ |
141 |
for (SampleResult res : samples) { |
140 |
String inputString=vars.get(getVariableName()); |
142 |
Document d = parseResponse(res); |
141 |
Document d = parseResponse(inputString); |
143 |
getValuesForXPath(d,getXPathQuery(),matches); |
142 |
getValuesForXPath(d,getXPathQuery(),matches); |
|
|
143 |
} else { |
144 |
List<SampleResult> samples = getSampleList(previousResult); |
145 |
for (SampleResult res : samples) { |
146 |
Document d = parseResponse(res.getResponseDataAsString()); |
147 |
getValuesForXPath(d,getXPathQuery(),matches); |
148 |
} |
144 |
} |
149 |
} |
145 |
final int matchCount = matches.size(); |
150 |
final int matchCount = matches.size(); |
146 |
vars.put(matchNR, String.valueOf(matchCount)); |
151 |
vars.put(matchNR, String.valueOf(matchCount)); |
Link Here
|
280 |
/** |
285 |
/** |
281 |
* Converts (X)HTML response to DOM object Tree. |
286 |
* Converts (X)HTML response to DOM object Tree. |
282 |
* This version cares of charset of response. |
287 |
* This version cares of charset of response. |
283 |
* @param result |
288 |
* @param unicodeData |
284 |
* @return |
289 |
* @return |
285 |
* |
290 |
* |
286 |
*/ |
291 |
*/ |
287 |
private Document parseResponse(SampleResult result) |
292 |
private Document parseResponse(String unicodeData) |
288 |
throws UnsupportedEncodingException, IOException, ParserConfigurationException,SAXException,TidyException |
293 |
throws UnsupportedEncodingException, IOException, ParserConfigurationException,SAXException,TidyException |
289 |
{ |
294 |
{ |
290 |
//TODO: validate contentType for reasonable types? |
295 |
//TODO: validate contentType for reasonable types? |
Link Here
|
292 |
// NOTE: responseData encoding is server specific |
297 |
// NOTE: responseData encoding is server specific |
293 |
// Therefore we do byte -> unicode -> byte conversion |
298 |
// Therefore we do byte -> unicode -> byte conversion |
294 |
// to ensure UTF-8 encoding as required by XPathUtil |
299 |
// to ensure UTF-8 encoding as required by XPathUtil |
295 |
String unicodeData = result.getResponseDataAsString(); |
|
|
296 |
// convert unicode String -> UTF-8 bytes |
300 |
// convert unicode String -> UTF-8 bytes |
297 |
byte[] utf8data = unicodeData.getBytes("UTF-8"); // $NON-NLS-1$ |
301 |
byte[] utf8data = unicodeData.getBytes("UTF-8"); // $NON-NLS-1$ |
298 |
ByteArrayInputStream in = new ByteArrayInputStream(utf8data); |
302 |
ByteArrayInputStream in = new ByteArrayInputStream(utf8data); |