Author: pmouawad Date: Mon Aug 25 10:39:07 2014 New Revision: 1620292 URL: http://svn.apache.org/r1620292 Log: Bug 56772 - Handle IE Conditional comments when parsing embedded resources Commit missing class and handle null UA Bugzilla Id: 56772
Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/HTMLParser.java jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/HTMLParser.java URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/HTMLParser.java?rev=1620292&r1=1620291&r2=1620292&view=diff ============================================================================== --- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/HTMLParser.java (original) +++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/HTMLParser.java Mon Aug 25 10:39:07 2014 @@ -28,6 +28,7 @@ import java.util.concurrent.ConcurrentHa import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.lang3.StringUtils; import org.apache.jmeter.util.JMeterUtils; import org.apache.jorphan.logging.LoggingManager; import org.apache.log.Logger; @@ -243,6 +244,10 @@ public abstract class HTMLParser { * @return version null if not IE or the version after MSIE */ protected Float extractIEVersion(String userAgent) { + if(StringUtils.isEmpty(userAgent)) { + log.info("userAgent is null"); + return null; + } Matcher matcher = IE_UA_PATTERN.matcher(userAgent); String ieVersion = null; while (matcher.find()) { Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java?rev=1620292&r1=1620291&r2=1620292&view=diff ============================================================================== --- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java (original) +++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java Mon Aug 25 10:39:07 2014 @@ -180,6 +180,8 @@ public abstract class HTTPSamplerBase ex public static final String CONCURRENT_POOL = "HTTPSampler.concurrentPool"; // $NON-NLS-1$ private static final String CONCURRENT_POOL_DEFAULT = "4"; // default for concurrent pool (do not change) + + private static final String USER_AGENT = "User-Agent"; // $NON-NLS-1$ //- JMX names @@ -1184,7 +1186,8 @@ public abstract class HTTPSamplerBase ex HTMLParser.getParser(parserName) : HTMLParser.getParser(); // we don't; use the default parser - urls = parser.getEmbeddedResourceURLs(responseData, res.getURL(), res.getDataEncodingWithDefault()); + String userAgent = getUserAgent(res); + urls = parser.getEmbeddedResourceURLs(userAgent, responseData, res.getURL(), res.getDataEncodingWithDefault()); } } } catch (HTMLParseException e) { @@ -1335,6 +1338,33 @@ public abstract class HTTPSamplerBase ex } /** + * Extract User-Agent header value + * @param sampleResult HTTPSampleResult + * @return User Agent part + */ + private String getUserAgent(HTTPSampleResult sampleResult) { + String res = sampleResult.getRequestHeaders(); + int index = res.indexOf(USER_AGENT); + if(index >=0) { + // see HTTPHC3Impl#getConnectionHeaders + // see HTTPHC4Impl#getConnectionHeaders + // see HTTPJavaImpl#getConnectionHeaders + //': ' is used by JMeter to fill-in requestHeaders, see getConnectionHeaders + final String userAgentPrefix = USER_AGENT+": "; + String userAgentHdr = res.substring( + index+userAgentPrefix.length(), + res.indexOf('\n',// '\n' is used by JMeter to fill-in requestHeaders, see getConnectionHeaders + index+userAgentPrefix.length()+1)); + return userAgentHdr.trim(); + } else { + if(log.isInfoEnabled()) { + log.info("No user agent extracted from requestHeaders:"+res); + } + return null; + } + } + + /** * Set parent successful attribute based on IGNORE_FAILED_EMBEDDED_RESOURCES parameter * @param res {@link HTTPSampleResult} * @param initialValue boolean