JMeter3.0 Graphical HTML report Chinese garbled Problem processing (reprint)

Source: Internet
Author: User

As a result of the personal application in JMeter 3.0, the script of the test Plan/sampler and other components named is not in Chinese, so in the previous introduction of the dashboard report characteristics of the blog (the original stamp here)) written, did not mention the question of Chinese. After a friend feedback, sampler name is in Chinese, the generated report shows as garbled, their own Test, indeed. , the script contains two sampler named Chinese: After performing the test, the generated Dashboard report chart is garbled: So by viewing the official documents and source code, find the reason and resolved, originally intended to be directly appended to the previous article, but in view of the length of the space, decided to make a new article, and then add the link in the previous article. Two. SolutionFirst on the solution: Modify the JMETER report module read the data in the source code of the character set to UTF-8, compiled after the replacement to Jmeter_home\lib\ext\apachejmeter_core.jar, here will share a I handled a jar package , but it is recommended that you do it yourself: Basic Solutions1. Download Apache-jmeter-3.0_src.zip 2, related source location: apache-jmeter-3.0/src/core/org/apache/jmeter/report/core/ Csvsamplereader.java 3, assigns the charst of Csvsamplereader to UTF-8 private static final String CHARSET = Standardcharsets.utf_8  . DisplayName (); 4. Compile the file and replace the original file within the Jmeter_home\lib\ext\apachejmeter_core.jar with the resulting. class file.  Of course, you can also directly recompile the source code packaging, but it will be time-consuming. Effect Recommended SolutionsA more recommended scenario for setting character encodings is to set the default character encoding to UTF-8, while supporting the. Properties configuration item. The character encoding configuration entry for the JMeter read-write result file (xml/csv) is _file_encoding in the./bin/saveservice.properties file, by Org.apache.jmeter.save.SaveService.getFileEncoding (String Dflt) reads, when not specified in the configuration phase, uses the method's input as the default encoding, where we pass in UFT-8 as the default format, Therefore, step 3 in the underlying scenario is changed as follows: private static final String CHARSET = saveservice.getfileencoding (standardcharsets.utf_8.  DisplayName ()); After compilation, replace it. The _file_encoding of the Saveservice.properties file is configured by default to UTF-8, and in most cases we do not need to modify it. file SharingShared files and jar packages are handled using recommended scenarios. You can use the class file to replace the local Apachejmeter_core.jar, or you can directly download the shared jar package to replace the local corresponding jar package. Separate Csvsamplereader.class file: Https://pan.baidu.com/s/1bo10QnX, extract code ee68 Processed APACHEJMETER_CORE.JAR:HTTPS://PAN.BAIDU.COM/S/1MHKLWGW, extract code id7h Note: On GitHub you can see that the JMeter Trunk branch has been dashboard The default character encoding for report is changed to UFT-8, and the recommendation in this article is how it is implemented in the official update. Just now the official has not released the update, so do it yourself. three. Genesis AnalysisThe Dashboard report attribute generates an HTML chart, a file that uses JMeter to record test results data (the file specified by the command line when the-L is executed, or it can be specified in the listener of the graphical interface, which is not expanded as a basic knowledge) as a data source, Apache Freemarker as the template engine, the default template is located in Jmeter_home\bin\report-template. Check the official instructions to confirm that there are no configuration items for HTML report character encoding. View the data source file, determine the file format is UTF-8, the Chinese in the file is normally readable, and exclude the possibility of problems with the data source. View the resulting file, the main data in the specified path/content/js/graph.js, select a chart data, view the value of its label ("label": "*"), displayed as garbled, excluding JS parsing into garbled possible. At this time, the first thought of Java file read process problems, from the official release of the source package to view the source code Src/core/org/apache/jmeter/report/core/csvsamplereader, found that the character encoding is specified as iso8859-1:
Package org.apache.jmeter.report.core;//secondary content slightly ... public class Csvsamplereader implements closeable{//secondary content slightly ... private Static final String CHARSET = "iso8859-1";//minor content slightly ... private csvsamplereader (File inputfile, samplemetadata metadata, Char separator, Boolean usesavesamplecfg) {if (! ( Inputfile.isfile () && inputfile.canread ()) {throw new IllegalArgumentException (Inputfile.getabsolutepath () + "does not exist or was not readable");} This.file = inputfile;try {this.reader = new BufferedReader (new InputStreamReader (file), FileInputStream), buf_size);} catch (FileNotFoundException | Unsupportedencodingexception ex) {throw new Sampleexception ("Could not create File Reader!", ex);}}
At this point, the cause of the problem is determined.

JMeter3.0 Graphical HTML report Chinese garbled Problem processing (reprint)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.