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 61e6e69 Sending mime type with parameter throws
IllegalArgumentException
61e6e69 is described below
commit 61e6e69c575cbc34a04a879ffe9b920206563904
Author: Felix Schumacher <[email protected]>
AuthorDate: Tue Dec 22 16:19:23 2020 +0100
Sending mime type with parameter throws IllegalArgumentException
The create method of ContentType doesn't work with mime-types that
contain multiple parts (separated by semicolons). The parse method
does, so use that one.
Bugzilla Id: 65024
---
.../jmeter/protocol/http/sampler/HTTPHC4Impl.java | 12 +++++--
.../protocol/http/sampler/TestHTTPHC4Impl.java | 40 ++++++++++++++++++++++
xdocs/changes.xml | 1 +
3 files changed, 51 insertions(+), 2 deletions(-)
diff --git
a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
index 4e8a4f3..3396ddb 100644
---
a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
+++
b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
@@ -1559,7 +1559,15 @@ public class HTTPHC4Impl extends HTTPHCAbstractImpl {
if (arg.isSkippable(parameterName)) {
continue;
}
- StringBody stringBody = new StringBody(arg.getValue(),
ContentType.create(arg.getContentType(), charset));
+ ContentType contentType;
+ if (arg.getContentType().indexOf(';') >= 0) {
+ // assume, that the content type contains charset info
+ // don't add another charset and use parse to cope with
the semicolon
+ contentType = ContentType.parse(arg.getContentType());
+ } else {
+ contentType = ContentType.create(arg.getContentType(),
charset);
+ }
+ StringBody stringBody = new StringBody(arg.getValue(),
contentType);
FormBodyPart formPart = FormBodyPartBuilder.create(
parameterName, stringBody).build();
multipartEntityBuilder.addPart(formPart);
@@ -1572,7 +1580,7 @@ public class HTTPHC4Impl extends HTTPHCAbstractImpl {
HTTPFileArg file = files[i];
File reservedFile =
FileServer.getFileServer().getResolvedFile(file.getPath());
- fileBodies[i] = new ViewableFileBody(reservedFile,
ContentType.create(file.getMimeType()));
+ fileBodies[i] = new ViewableFileBody(reservedFile,
ContentType.parse(file.getMimeType()));
multipartEntityBuilder.addPart(file.getParamName(),
fileBodies[i] );
}
diff --git
a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestHTTPHC4Impl.java
b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestHTTPHC4Impl.java
index e3dc38a..0d2223f 100644
---
a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestHTTPHC4Impl.java
+++
b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestHTTPHC4Impl.java
@@ -20,7 +20,14 @@ package org.apache.jmeter.protocol.http.sampler;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import java.io.File;
+import java.util.Collections;
+
+import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
+import org.apache.http.client.methods.HttpPost;
import org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui;
+import org.apache.jmeter.protocol.http.util.HTTPArgument;
+import org.apache.jmeter.protocol.http.util.HTTPFileArg;
import org.apache.jmeter.threads.JMeterContext;
import org.apache.jmeter.threads.JMeterContextService;
import org.apache.jmeter.threads.JMeterVariables;
@@ -42,6 +49,39 @@ public class TestHTTPHC4Impl {
}
@Test
+ void testParameterWithMimeTypeWithCharset() throws Exception {
+ HTTPSamplerBase sampler = (HTTPSamplerBase) new
HttpTestSampleGui().createTestElement();
+ sampler.setThreadContext(jmctx);
+ sampler.setDoMultipart(true);
+ HttpEntityEnclosingRequestBase post = new HttpPost();
+ HTTPArgument argument = new HTTPArgument("upload", "some data");
+ argument.setContentType("text/html; charset=utf-8");
+ sampler.getArguments().addArgument(argument);
+ HTTPHC4Impl hc = new HTTPHC4Impl(sampler);
+ String requestData = hc.setupHttpEntityEnclosingRequestData(post);
+ assertTrue(requestData.contains("charset=utf-8"));
+ }
+
+ @Test
+ void testFileargWithMimeTypeWithCharset() throws Exception {
+ HTTPSamplerBase sampler = (HTTPSamplerBase) new
HttpTestSampleGui().createTestElement();
+ sampler.setThreadContext(jmctx);
+ sampler.setDoMultipart(true);
+ HttpEntityEnclosingRequestBase post = new HttpPost();
+ HTTPFileArg fileArg = new HTTPFileArg();
+ fileArg.setMimeType("text/html; charset=utf-8");
+ fileArg.setName("somefile.html");
+ fileArg.setParamName("upload");
+ File dummyFile = File.createTempFile("somefile", ".html");
+ dummyFile.deleteOnExit();
+ fileArg.setPath(dummyFile.getAbsolutePath());
+ sampler.setHTTPFiles(Collections.singletonList(fileArg).toArray(new
HTTPFileArg[1]));
+ HTTPHC4Impl hc = new HTTPHC4Impl(sampler);
+ String requestData = hc.setupHttpEntityEnclosingRequestData(post);
+ assertTrue(requestData.contains("charset=utf-8"));
+ }
+
+ @Test
public void
testNotifyFirstSampleAfterLoopRestartWhenThreadIterationIsSameUser() {
jmvars.putObject(SAME_USER, true);
jmctx.setVariables(jmvars);
diff --git a/xdocs/changes.xml b/xdocs/changes.xml
index afac388..a802885 100644
--- a/xdocs/changes.xml
+++ b/xdocs/changes.xml
@@ -141,6 +141,7 @@ Summary
<li><bug>65002</bug>HTTP(S) Test Script recorder creates an invalid Basic
authentication URL. Contributed by Ubik Load Pack
(https://ubikloadpack.com)</li>
<li><bug>65004</bug>HTTP(S) Test Script recorder computes wrong HTTP Request
breaking the application. Contributed by Ubik Load Pack
(https://ubikloadpack.com)</li>
<li><bug>64543</bug>On MacOSX, Darklaf- IntelliJ Theme throws NPE in
javax.swing.ToolTipManager.initiateToolTip</li>
+ <li><bug>65024</bug>Sending mime type with parameter throws
IllegalArgumentException</li>
</ul>
<h3>Other Samplers</h3>