Lines 56-63
Link Here
|
56 |
import org.apache.jmeter.protocol.http.control.CookieManager; |
56 |
import org.apache.jmeter.protocol.http.control.CookieManager; |
57 |
import org.apache.jmeter.protocol.http.control.DNSCacheManager; |
57 |
import org.apache.jmeter.protocol.http.control.DNSCacheManager; |
58 |
import org.apache.jmeter.protocol.http.control.HeaderManager; |
58 |
import org.apache.jmeter.protocol.http.control.HeaderManager; |
59 |
import org.apache.jmeter.protocol.http.parser.HTMLParseException; |
59 |
import org.apache.jmeter.protocol.http.parser.BaseParser; |
60 |
import org.apache.jmeter.protocol.http.parser.HTMLParser; |
60 |
import org.apache.jmeter.protocol.http.parser.LinkExtractorParseException; |
|
|
61 |
import org.apache.jmeter.protocol.http.parser.LinkExtractorParser; |
61 |
import org.apache.jmeter.protocol.http.util.ConversionUtils; |
62 |
import org.apache.jmeter.protocol.http.util.ConversionUtils; |
62 |
import org.apache.jmeter.protocol.http.util.EncoderCache; |
63 |
import org.apache.jmeter.protocol.http.util.EncoderCache; |
63 |
import org.apache.jmeter.protocol.http.util.HTTPArgument; |
64 |
import org.apache.jmeter.protocol.http.util.HTTPArgument; |
Lines 303-338
Link Here
|
303 |
|
304 |
|
304 |
|
305 |
|
305 |
// Derive the mapping of content types to parsers |
306 |
// Derive the mapping of content types to parsers |
306 |
private static final Map<String, String> parsersForType = new HashMap<>(); |
307 |
private static final Map<String, String> PARSERS_FOR_CONTENT_TYPE = new HashMap<>(); |
307 |
// Not synch, but it is not modified after creation |
308 |
// Not synch, but it is not modified after creation |
308 |
|
309 |
|
309 |
private static final String RESPONSE_PARSERS= // list of parsers |
310 |
private static final String RESPONSE_PARSERS= // list of parsers |
310 |
JMeterUtils.getProperty("HTTPResponse.parsers");//$NON-NLS-1$ |
311 |
JMeterUtils.getProperty("HTTPResponse.parsers");//$NON-NLS-1$ |
311 |
|
312 |
|
312 |
static{ |
313 |
static{ |
313 |
String []parsers = JOrphanUtils.split(RESPONSE_PARSERS, " " , true);// returns empty array for null |
314 |
String[] parsers = JOrphanUtils.split(RESPONSE_PARSERS, " " , true);// returns empty array for null |
314 |
for (final String parser : parsers) { |
315 |
for (final String parser : parsers) { |
315 |
String classname = JMeterUtils.getProperty(parser + ".className");//$NON-NLS-1$ |
316 |
String classname = JMeterUtils.getProperty(parser + ".className");//$NON-NLS-1$ |
316 |
if (classname == null) { |
317 |
if (classname == null) { |
317 |
log.info("Cannot find .className property for " + parser + ", using default"); |
318 |
log.error("Cannot find .className property for " + parser+", ensure you set property:'"+parser+".className'"); |
318 |
classname = ""; |
319 |
continue; |
319 |
} |
320 |
} |
320 |
String typelist = JMeterUtils.getProperty(parser + ".types");//$NON-NLS-1$ |
321 |
String typelist = JMeterUtils.getProperty(parser + ".types");//$NON-NLS-1$ |
321 |
if (typelist != null) { |
322 |
if (typelist != null) { |
322 |
String[] types = JOrphanUtils.split(typelist, " ", true); |
323 |
String[] types = JOrphanUtils.split(typelist, " ", true); |
323 |
for (final String type : types) { |
324 |
for (final String type : types) { |
324 |
log.info("Parser for " + type + " is " + classname); |
325 |
log.info("Parser for " + type + " is " + classname); |
325 |
parsersForType.put(type, classname); |
326 |
PARSERS_FOR_CONTENT_TYPE.put(type, classname); |
326 |
} |
327 |
} |
327 |
} else { |
328 |
} else { |
328 |
log.warn("Cannot find .types property for " + parser); |
329 |
log.warn("Cannot find .types property for " + parser |
|
|
330 |
+ ", as a consequence parser will not be used, to make it usable, define property:'"+parser+".types'"); |
329 |
} |
331 |
} |
330 |
} |
332 |
} |
331 |
if (parsers.length==0){ // revert to previous behaviour |
|
|
332 |
parsersForType.put("text/html", ""); //$NON-NLS-1$ //$NON-NLS-2$ |
333 |
log.info("No response parsers defined: text/html only will be scanned for embedded resources"); |
334 |
} |
335 |
|
336 |
} |
333 |
} |
337 |
|
334 |
|
338 |
// Bug 49083 |
335 |
// Bug 49083 |
Lines 1194-1212
Link Here
|
1194 |
try { |
1191 |
try { |
1195 |
final byte[] responseData = res.getResponseData(); |
1192 |
final byte[] responseData = res.getResponseData(); |
1196 |
if (responseData.length > 0){ // Bug 39205 |
1193 |
if (responseData.length > 0){ // Bug 39205 |
1197 |
String parserName = getParserClass(res); |
1194 |
final LinkExtractorParser parser = getParser(res); |
1198 |
if(parserName != null) |
1195 |
if(parser != null) { |
1199 |
{ |
|
|
1200 |
final HTMLParser parser = |
1201 |
parserName.length() > 0 ? // we have a name |
1202 |
HTMLParser.getParser(parserName) |
1203 |
: |
1204 |
HTMLParser.getParser(); // we don't; use the default parser |
1205 |
String userAgent = getUserAgent(res); |
1196 |
String userAgent = getUserAgent(res); |
1206 |
urls = parser.getEmbeddedResourceURLs(userAgent, responseData, res.getURL(), res.getDataEncodingWithDefault()); |
1197 |
urls = parser.getEmbeddedResourceURLs(userAgent, responseData, res.getURL(), res.getDataEncodingWithDefault()); |
1207 |
} |
1198 |
} |
1208 |
} |
1199 |
} |
1209 |
} catch (HTMLParseException e) { |
1200 |
} catch (LinkExtractorParseException e) { |
1210 |
// Don't break the world just because this failed: |
1201 |
// Don't break the world just because this failed: |
1211 |
res.addSubResult(errorResult(e, new HTTPSampleResult(res))); |
1202 |
res.addSubResult(errorResult(e, new HTTPSampleResult(res))); |
1212 |
setParentSampleSuccess(res, false); |
1203 |
setParentSampleSuccess(res, false); |
Lines 1358-1363
Link Here
|
1358 |
} |
1349 |
} |
1359 |
|
1350 |
|
1360 |
/** |
1351 |
/** |
|
|
1352 |
* Gets parser from {@link HTTPSampleResult#getMediaType()}. |
1353 |
* Returns null if no parser defined for it |
1354 |
* @param res {@link HTTPSampleResult} |
1355 |
* @return {@link LinkExtractorParser} |
1356 |
* @throws LinkExtractorParseException |
1357 |
*/ |
1358 |
private LinkExtractorParser getParser(HTTPSampleResult res) |
1359 |
throws LinkExtractorParseException { |
1360 |
String parserClassName = |
1361 |
PARSERS_FOR_CONTENT_TYPE.get(res.getMediaType()); |
1362 |
if( !StringUtils.isEmpty(parserClassName) ) { |
1363 |
return BaseParser.getParser(parserClassName); |
1364 |
} |
1365 |
return null; |
1366 |
} |
1367 |
|
1368 |
/** |
1361 |
* @param url URL to escape |
1369 |
* @param url URL to escape |
1362 |
* @return escaped url |
1370 |
* @return escaped url |
1363 |
*/ |
1371 |
*/ |
Lines 1434-1448
Link Here
|
1434 |
} |
1442 |
} |
1435 |
} |
1443 |
} |
1436 |
|
1444 |
|
1437 |
/* |
|
|
1438 |
* @param res HTTPSampleResult to check |
1439 |
* @return parser class name (may be "") or null if entry does not exist |
1440 |
*/ |
1441 |
private String getParserClass(HTTPSampleResult res) { |
1442 |
final String ct = res.getMediaType(); |
1443 |
return parsersForType.get(ct); |
1444 |
} |
1445 |
|
1446 |
// TODO: make static? |
1445 |
// TODO: make static? |
1447 |
protected String encodeSpaces(String path) { |
1446 |
protected String encodeSpaces(String path) { |
1448 |
return JOrphanUtils.replaceAllChars(path, ' ', "%20"); // $NON-NLS-1$ |
1447 |
return JOrphanUtils.replaceAllChars(path, ' ', "%20"); // $NON-NLS-1$ |