You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by fs...@apache.org on 2022/04/13 14:19:47 UTC
[jmeter] branch master updated: Specify the char encoding when decoding bytes into strings
This is an automated email from the ASF dual-hosted git repository.
fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git
The following commit(s) were added to refs/heads/master by this push:
new d8a6876169 Specify the char encoding when decoding bytes into strings
d8a6876169 is described below
commit d8a6876169ea6327b8c20f23445a472af32f4276
Author: Felix Schumacher <fe...@internetallee.de>
AuthorDate: Wed Apr 13 16:17:56 2022 +0200
Specify the char encoding when decoding bytes into strings
As all other commits related to #708, this is based on patch by Wilson Kurniawan (wilson at visenze.com)
Closes #708
---
.../org/apache/jmeter/gui/action/HtmlReportGenerator.java | 3 ++-
.../apache/jmeter/protocol/http/proxy/HttpRequestHdr.java | 5 +++--
.../apache/jmeter/protocol/tcp/sampler/TCPClientImpl.java | 15 +++++++++++++--
xdocs/changes.xml | 2 ++
4 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/src/core/src/main/java/org/apache/jmeter/gui/action/HtmlReportGenerator.java b/src/core/src/main/java/org/apache/jmeter/gui/action/HtmlReportGenerator.java
index 87803da1e3..e00fee3f9c 100644
--- a/src/core/src/main/java/org/apache/jmeter/gui/action/HtmlReportGenerator.java
+++ b/src/core/src/main/java/org/apache/jmeter/gui/action/HtmlReportGenerator.java
@@ -20,6 +20,7 @@ package org.apache.jmeter.gui.action;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.Charset;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
@@ -83,7 +84,7 @@ public class HtmlReportGenerator {
LOGGER.debug("Running report generation");
resultCode = sc.run(generationCommand);
if (resultCode != 0) {
- errorMessageList.add(commandExecutionOutput.toString());
+ errorMessageList.add(commandExecutionOutput.toString(Charset.defaultCharset().name()));
LOGGER.info("The HTML report generation failed and returned: {}", commandExecutionOutput);
return errorMessageList;
}
diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java
index abd69a883b..c931bcb677 100644
--- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java
+++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/HttpRequestHdr.java
@@ -24,6 +24,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
@@ -164,7 +165,7 @@ public class HttpRequestHdr {
inHeaders = false;
firstLine = false; // cannot be first line either
}
- final String reqLine = line.toString();
+ final String reqLine = line.toString(StandardCharsets.ISO_8859_1.name());
if (firstLine) {
parseFirstLine(reqLine);
firstLine = false;
@@ -189,7 +190,7 @@ public class HttpRequestHdr {
if (log.isDebugEnabled()){
log.debug("rawPostData in default JRE encoding: {}, Request: '{}'",
new String(rawPostData, Charset.defaultCharset()),
- clientRequest.toString().replaceAll("\r\n", CRLF));
+ clientRequest.toString(StandardCharsets.ISO_8859_1.name()).replaceAll("\r\n", CRLF));
}
return clientRequest.toByteArray();
}
diff --git a/src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/sampler/TCPClientImpl.java b/src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/sampler/TCPClientImpl.java
index 749b295a0b..66ba928ac8 100644
--- a/src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/sampler/TCPClientImpl.java
+++ b/src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/sampler/TCPClientImpl.java
@@ -21,6 +21,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import org.apache.commons.lang3.StringUtils;
@@ -115,11 +116,21 @@ public class TCPClientImpl extends AbstractTCPClient {
// do we need to close byte array (or flush it?)
if(log.isDebugEnabled()) {
- log.debug("Read: {}\n{}", w.size(), w.toString());
+ log.debug("Read: {}\n{}", w.size(), w.toString(CHARSET));
}
return w.toString(CHARSET);
+ } catch (UnsupportedEncodingException e) {
+ throw new ReadException("Error decoding bytes from server with " + CHARSET + ", bytes read: " + w.size(),
+ e, "<Read bytes with bad encoding>");
} catch (IOException e) {
- throw new ReadException("Error reading from server, bytes read: " + w.size(), e, w.toString());
+ String decodedBytes;
+ try {
+ decodedBytes = w.toString(CHARSET);
+ } catch (UnsupportedEncodingException uee) {
+ // we should never get here, as it would have crashed earlier
+ decodedBytes = "<Read bytes with bad encoding>";
+ }
+ throw new ReadException("Error reading from server, bytes read: " + w.size(), e, decodedBytes);
}
}
diff --git a/xdocs/changes.xml b/xdocs/changes.xml
index 321ee336dd..a14681778a 100644
--- a/xdocs/changes.xml
+++ b/xdocs/changes.xml
@@ -217,6 +217,7 @@ however, the profile can't be updated while the test is running.
<li><pr>692></pr>Fix a few deprecation warnings for Gradle. Contributed by Sampath Kumar Krishnasamy (sampathkumar.krishnasamykuppusamy at aexp.com)</li>
<li><pr>697></pr>Junit 5 tests to use asserts from Junit 5 API. Contributed by Sampath Kumar Krishnasamy (sampathkumar.krishnasamykuppusamy at aexp.com)</li>
<li><bug>65983</bug><pr>707</pr>Use current screenshot for save-to-file listener in documentation. Based on patch by NaveenKumar Namachivayam (catch.nkn at gmail.com)</li>
+ <li><pr>708</pr>Make errorprone happier. Based on patch by Wilson Kurniawan (wilson at visenze.comr)></li>
</ul>
<!-- =================== Bug fixes =================== -->
@@ -323,6 +324,7 @@ however, the profile can't be updated while the test is running.
<li>Ji Hun (jihunkimkw at gmail.com)</li>
<li>Peter Paul Bakker (peter.paul.bakker at stokpop.nl)</li>
<li>NaveenKumar Namachivayam (catch.nkn at gmail.com)</li>
+ <li>Wilson Kurniawan (wilson at visenze.com)</li>
</ul>
<p>We also thank bug reporters who helped us improve JMeter.</p>
<ul>