jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1225193 - in /jmeter/trunk: bin/testfiles/ src/protocol/http/org/apache/jmeter/protocol/http/parser/ src/protocol/http/org/apache/jmeter/protocol/http/sampler/ test/src/org/apache/jmeter/protocol/http/parser/ xdocs/
Date Wed, 28 Dec 2011 14:33:41 GMT
Author: pmouawad
Date: Wed Dec 28 14:33:41 2011
New Revision: 1225193

URL: http://svn.apache.org/viewvc?rev=1225193&view=rev
Log:
Bug 49374 - Encoding of embedded element URLs depend on the file.encoding property
Now using SampleResult#getDataEncodingWithDefault() to avoid relying on file.encoding of the
JVM.
Modified HTMLParserTestFile_2.xml to take into account the impact of encoding change.

Modified:
    jmeter/trunk/bin/testfiles/HTMLParserTestFile_2.xml
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/HTMLParser.java
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/HtmlParserHTMLParser.java
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/JTidyHTMLParser.java
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/RegexpHTMLParser.java
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
    jmeter/trunk/test/src/org/apache/jmeter/protocol/http/parser/TestHTMLParser.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/bin/testfiles/HTMLParserTestFile_2.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/bin/testfiles/HTMLParserTestFile_2.xml?rev=1225193&r1=1225192&r2=1225193&view=diff
==============================================================================
--- jmeter/trunk/bin/testfiles/HTMLParserTestFile_2.xml (original)
+++ jmeter/trunk/bin/testfiles/HTMLParserTestFile_2.xml Wed Dec 28 14:33:41 2011
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <testResults version="1.2">
-<httpSample s="true" lb="Download embedded" rc="200" rm="OK" tn="Thread Group 1-1" dt="text"
de="" by="40174" sc="1" ec="0" ng="1" na="1">
-  <httpSample s="true" lb="file:testfiles/HTMLParserTestFile_2.html" rc="200" rm="OK"
tn="Thread Group 1-1" dt="text" de="" by="40174" sc="1" ec="0" ng="0" na="0">
+<httpSample s="true" lb="Download embedded" rc="200" rm="OK" tn="Thread Group 1-1" dt="text"
de="UTF-8" by="40174" sc="1" ec="0" ng="1" na="1">
+  <httpSample s="true" lb="file:testfiles/HTMLParserTestFile_2.html" rc="200" rm="OK"
tn="Thread Group 1-1" dt="text" de="UTF-8" by="40174" sc="1" ec="0" ng="0" na="0">
     <responseHeader class="java.lang.String"></responseHeader>
     <requestHeader class="java.lang.String"></requestHeader>
     <responseFile class="java.lang.String"></responseFile>
@@ -19,8 +19,8 @@
     <queryString class="java.lang.String"></queryString>
     <java.net.URL>file:testfiles/HTMLParserTestFile_2_files/style.css</java.net.URL>
   </httpSample>
-  <httpSample s="true" lb="file:testfiles/HTMLParserTestFile_2_files/halfbanner.htm" rc="200"
rm="OK" tn="Thread Group 1-1" dt="text" de="" by="398" sc="1" ec="0" ng="0" na="0">
-    <httpSample s="true" lb="file:testfiles/HTMLParserTestFile_2_files/halfbanner.htm"
rc="200" rm="OK" tn="Thread Group 1-1" dt="text" de="" by="398" sc="1" ec="0" ng="0" na="0">
+  <httpSample s="true" lb="file:testfiles/HTMLParserTestFile_2_files/halfbanner.htm" rc="200"
rm="OK" tn="Thread Group 1-1" dt="text" de="UTF-8" by="398" sc="1" ec="0" ng="0" na="0">
+    <httpSample s="true" lb="file:testfiles/HTMLParserTestFile_2_files/halfbanner.htm"
rc="200" rm="OK" tn="Thread Group 1-1" dt="text" de="UTF-8" by="398" sc="1" ec="0" ng="0"
na="0">
       <responseHeader class="java.lang.String"></responseHeader>
       <requestHeader class="java.lang.String"></requestHeader>
       <responseFile class="java.lang.String"></responseFile>

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=1225193&r1=1225192&r2=1225193&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
Wed Dec 28 14:33:41 2011
@@ -121,9 +121,10 @@ public abstract class HTMLParser {
      *            HTML code
      * @param baseUrl
      *            Base URL from which the HTML code was obtained
+     * @param encoding Charset
      * @return an Iterator for the resource URLs
      */
-    public Iterator<URL> getEmbeddedResourceURLs(byte[] html, URL baseUrl) throws HTMLParseException
{
+    public Iterator<URL> getEmbeddedResourceURLs(byte[] html, URL baseUrl, String encoding)
throws HTMLParseException {
         // The Set is used to ignore duplicated binary files.
         // Using a LinkedHashSet to avoid unnecessary overhead in iterating
         // the elements in the set later on. As a side-effect, this will keep
@@ -131,7 +132,7 @@ public abstract class HTMLParser {
         // behaviour.
 
         Collection<URLString> col = new LinkedHashSet<URLString>();
-        return getEmbeddedResourceURLs(html, baseUrl, new URLCollection(col));
+        return getEmbeddedResourceURLs(html, baseUrl, new URLCollection(col),encoding);
 
         // An additional note on using HashSets to store URLs: I just
         // discovered that obtaining the hashCode of a java.net.URL implies
@@ -167,9 +168,10 @@ public abstract class HTMLParser {
      *            Base URL from which the HTML code was obtained
      * @param coll
      *            URLCollection
+     * @param encoding Charset
      * @return an Iterator for the resource URLs
      */
-    public abstract Iterator<URL> getEmbeddedResourceURLs(byte[] html, URL baseUrl,
URLCollection coll)
+    public abstract Iterator<URL> getEmbeddedResourceURLs(byte[] html, URL baseUrl,
URLCollection coll, String encoding)
             throws HTMLParseException;
 
     /**
@@ -186,10 +188,11 @@ public abstract class HTMLParser {
      *            Base URL from which the HTML code was obtained
      * @param coll
      *            Collection - will contain URLString objects, not URLs
+     * @param encoding Charset
      * @return an Iterator for the resource URLs
      */
-    public Iterator<URL> getEmbeddedResourceURLs(byte[] html, URL baseUrl, Collection<URLString>
coll) throws HTMLParseException {
-        return getEmbeddedResourceURLs(html, baseUrl, new URLCollection(coll));
+    public Iterator<URL> getEmbeddedResourceURLs(byte[] html, URL baseUrl, Collection<URLString>
coll, String encoding) throws HTMLParseException {
+        return getEmbeddedResourceURLs(html, baseUrl, new URLCollection(coll), encoding);
     }
 
     /**

Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/HtmlParserHTMLParser.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/HtmlParserHTMLParser.java?rev=1225193&r1=1225192&r2=1225193&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/HtmlParserHTMLParser.java
(original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/HtmlParserHTMLParser.java
Wed Dec 28 14:33:41 2011
@@ -64,7 +64,7 @@ class HtmlParserHTMLParser extends HTMLP
      * {@inheritDoc}
      */
     @Override
-    public Iterator<URL> getEmbeddedResourceURLs(byte[] html, URL baseUrl, URLCollection
urls) throws HTMLParseException {
+    public Iterator<URL> getEmbeddedResourceURLs(byte[] html, URL baseUrl, URLCollection
urls, String encoding) throws HTMLParseException {
 
         if (log.isDebugEnabled()) {
             log.debug("Parsing html of: " + baseUrl);
@@ -72,7 +72,7 @@ class HtmlParserHTMLParser extends HTMLP
 
         Parser htmlParser = null;
         try {
-            String contents = new String(html); // TODO - charset?
+            String contents = new String(html,encoding); 
             htmlParser = new Parser();
             htmlParser.setInputHTML(contents);
         } catch (Exception e) {

Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/JTidyHTMLParser.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/JTidyHTMLParser.java?rev=1225193&r1=1225192&r2=1225193&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/JTidyHTMLParser.java
(original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/JTidyHTMLParser.java
Wed Dec 28 14:33:41 2011
@@ -53,10 +53,10 @@ class JTidyHTMLParser extends HTMLParser
      * {@inheritDoc}
      */
     @Override
-    public Iterator<URL> getEmbeddedResourceURLs(byte[] html, URL baseUrl, URLCollection
urls) throws HTMLParseException {
+    public Iterator<URL> getEmbeddedResourceURLs(byte[] html, URL baseUrl, URLCollection
urls, String encoding) throws HTMLParseException {
         Document dom = null;
         try {
-            dom = (Document) getDOM(html);
+            dom = (Document) getDOM(html, encoding);
         } catch (SAXException se) {
             throw new HTMLParseException(se);
         }
@@ -194,10 +194,10 @@ class JTidyHTMLParser extends HTMLParser
      *
      * @return a <code>tidy</code> HTML parser
      */
-    private static Tidy getTidyParser() {
+    private static Tidy getTidyParser(String encoding) {
         log.debug("Start : getParser");
         Tidy tidy = new Tidy();
-        tidy.setInputEncoding("UTF8");
+        tidy.setInputEncoding(encoding);
         tidy.setOutputEncoding("UTF8");
         tidy.setQuiet(true);
         tidy.setShowWarnings(false);
@@ -218,9 +218,9 @@ class JTidyHTMLParser extends HTMLParser
      * @throws SAXException
      *             indicates an error parsing the xml document
      */
-    private static Node getDOM(byte[] text) throws SAXException {
+    private static Node getDOM(byte[] text, String encoding) throws SAXException {
         log.debug("Start : getDOM");
-        Node node = getTidyParser().parseDOM(new ByteArrayInputStream(text), null);
+        Node node = getTidyParser(encoding).parseDOM(new ByteArrayInputStream(text), null);
         if (log.isDebugEnabled()) {
             log.debug("node : " + node);
         }

Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/RegexpHTMLParser.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/RegexpHTMLParser.java?rev=1225193&r1=1225192&r2=1225193&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/RegexpHTMLParser.java
(original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/parser/RegexpHTMLParser.java
Wed Dec 28 14:33:41 2011
@@ -18,6 +18,7 @@
 
 package org.apache.jmeter.protocol.http.parser;
 
+import java.io.UnsupportedEncodingException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Iterator;
@@ -31,6 +32,7 @@ import org.apache.log.Logger;
 // trivial. Performance did not improve -- at least not significantly.
 // Finally decided for ORO following advise from Stefan Bodewig (message
 // to jmeter-dev dated 25 Nov 2003 8:52 CET) [Jordi]
+import org.apache.oro.text.MalformedCachePatternException;
 import org.apache.oro.text.regex.MatchResult;
 import org.apache.oro.text.regex.Pattern;
 import org.apache.oro.text.regex.PatternMatcherInput;
@@ -140,56 +142,63 @@ class RegexpHTMLParser extends HTMLParse
 
     /**
      * {@inheritDoc}
+     * @throws HTMLParseException 
      */
     @Override
-    public Iterator<URL> getEmbeddedResourceURLs(byte[] html, URL baseUrl, URLCollection
urls) {
+    public Iterator<URL> getEmbeddedResourceURLs(byte[] html, URL baseUrl, URLCollection
urls, String encoding) throws HTMLParseException {
 
-        Perl5Matcher matcher = JMeterUtils.getMatcher();
-        PatternMatcherInput input = localInput.get();
-        // TODO: find a way to avoid the cost of creating a String here --
-        // probably a new PatternMatcherInput working on a byte[] would do
-        // better.
-        input.setInput(new String(html)); // TODO - charset?
-        Pattern pattern=JMeterUtils.getPatternCache().getPattern(
-                REGEXP,
-                Perl5Compiler.CASE_INSENSITIVE_MASK
-                | Perl5Compiler.SINGLELINE_MASK
-                | Perl5Compiler.READ_ONLY_MASK);
-
-        while (matcher.contains(input, pattern)) {
-            MatchResult match = matcher.getMatch();
-            String s;
-            if (log.isDebugEnabled()) {
-                log.debug("match groups " + match.groups() + " " + match.toString());
-            }
-            // Check for a BASE HREF:
-            for (int g = 1; g <= NUM_BASE_GROUPS && g <= match.groups(); g++)
{
-                s = match.group(g);
-                if (s != null) {
-                    if (log.isDebugEnabled()) {
-                        log.debug("new baseUrl: " + s + " - " + baseUrl.toString());
-                    }
-                    try {
-                        baseUrl = ConversionUtils.makeRelativeURL(baseUrl, s);
-                    } catch (MalformedURLException e) {
-                        // Doesn't even look like a URL?
-                        // Maybe it isn't: Ignore the exception.
-                        if (log.isDebugEnabled()) {
-                            log.debug("Can't build base URL from RL " + s + " in page " +
baseUrl, e);
-                        }
-                    }
-                }
-            }
-            for (int g = NUM_BASE_GROUPS + 1; g <= match.groups(); g++) {
-                s = match.group(g);
-                if (s != null) {
-                    if (log.isDebugEnabled()) {
-                        log.debug("group " + g + " - " + match.group(g));
-                    }
-                    urls.addURL(s, baseUrl);
-                }
-            }
-        }
-        return urls.iterator();
+        try {
+			Perl5Matcher matcher = JMeterUtils.getMatcher();
+			PatternMatcherInput input = localInput.get();
+			// TODO: find a way to avoid the cost of creating a String here --
+			// probably a new PatternMatcherInput working on a byte[] would do
+			// better.
+			input.setInput(new String(html, encoding)); 
+			Pattern pattern=JMeterUtils.getPatternCache().getPattern(
+			        REGEXP,
+			        Perl5Compiler.CASE_INSENSITIVE_MASK
+			        | Perl5Compiler.SINGLELINE_MASK
+			        | Perl5Compiler.READ_ONLY_MASK);
+
+			while (matcher.contains(input, pattern)) {
+			    MatchResult match = matcher.getMatch();
+			    String s;
+			    if (log.isDebugEnabled()) {
+			        log.debug("match groups " + match.groups() + " " + match.toString());
+			    }
+			    // Check for a BASE HREF:
+			    for (int g = 1; g <= NUM_BASE_GROUPS && g <= match.groups(); g++) {
+			        s = match.group(g);
+			        if (s != null) {
+			            if (log.isDebugEnabled()) {
+			                log.debug("new baseUrl: " + s + " - " + baseUrl.toString());
+			            }
+			            try {
+			                baseUrl = ConversionUtils.makeRelativeURL(baseUrl, s);
+			            } catch (MalformedURLException e) {
+			                // Doesn't even look like a URL?
+			                // Maybe it isn't: Ignore the exception.
+			                if (log.isDebugEnabled()) {
+			                    log.debug("Can't build base URL from RL " + s + " in page " + baseUrl,
e);
+			                }
+			            }
+			        }
+			    }
+			    for (int g = NUM_BASE_GROUPS + 1; g <= match.groups(); g++) {
+			        s = match.group(g);
+			        if (s != null) {
+			            if (log.isDebugEnabled()) {
+			                log.debug("group " + g + " - " + match.group(g));
+			            }
+			            urls.addURL(s, baseUrl);
+			        }
+			    }
+			}
+			return urls.iterator();
+		} catch (UnsupportedEncodingException e) {
+			throw new HTMLParseException(e.getMessage(), e);
+		} catch (MalformedCachePatternException e) {
+			throw new HTMLParseException(e.getMessage(), e);
+		}
     }
 }

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=1225193&r1=1225192&r2=1225193&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
Wed Dec 28 14:33:41 2011
@@ -1103,7 +1103,7 @@ public abstract class HTTPSamplerBase ex
                         HTMLParser.getParser(parserName)
                         :
                         HTMLParser.getParser(); // we don't; use the default parser
-                    urls = parser.getEmbeddedResourceURLs(responseData, res.getURL());
+                    urls = parser.getEmbeddedResourceURLs(responseData, res.getURL(), res.getDataEncodingWithDefault());
                 }
             }
         } catch (HTMLParseException e) {

Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/http/parser/TestHTMLParser.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/parser/TestHTMLParser.java?rev=1225193&r1=1225192&r2=1225193&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/http/parser/TestHTMLParser.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/http/parser/TestHTMLParser.java Wed Dec
28 14:33:41 2011
@@ -264,9 +264,9 @@ public class TestHTMLParser extends JMet
             }
             Iterator<URL> result;
             if (c == null) {
-                result = p.getEmbeddedResourceURLs(buffer, new URL(url));
+                result = p.getEmbeddedResourceURLs(buffer, new URL(url), System.getProperty("file.encoding"));
             } else {
-                result = p.getEmbeddedResourceURLs(buffer, new URL(url), c);
+                result = p.getEmbeddedResourceURLs(buffer, new URL(url), c,System.getProperty("file.encoding"));
             }
             /*
              * TODO: Exact ordering is only required for some tests; change the

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1225193&r1=1225192&r2=1225193&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Wed Dec 28 14:33:41 2011
@@ -158,6 +158,7 @@ This behaviour can be changed with prope
 <li>Bug 52279 - Switching to another language loses icons in Tree and logs error Can't
obtain GUI class from ...</li>
 <li>Bug 52280 - The menu item Options / Choose Language does not change all the displayed
text to the new language</li>
 <li>Bug 52376 - StatCalculator#addValue(T val, int sampleCount) should use long, not
int</li>
+<li>Bug 49374 - Encoding of embedded element URLs depend on the file.encoding property</li>
 </ul>
 
 <!-- =================== Improvements =================== -->



Mime
View raw message