Author: pmouawad
Date: Sun Mar  6 15:29:40 2016
New Revision: 1733809

URL: http://svn.apache.org/viewvc?rev=1733809&view=rev
Log:
Bug 56141 - Application does not behave correctly when using HTTP Recorder
Migrate to up to date HttpMime APIs
Bugzilla Id: 56141

Modified:
    
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java

Modified: 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java?rev=1733809&r1=1733808&r2=1733809&view=diff
==============================================================================
--- 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
 (original)
+++ 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
 Sun Mar  6 15:29:40 2016
@@ -83,8 +83,9 @@ import org.apache.http.entity.ContentTyp
 import org.apache.http.entity.FileEntity;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.entity.mime.FormBodyPart;
-import org.apache.http.entity.mime.HttpMultipartMode;
-import org.apache.http.entity.mime.MultipartEntity;
+import org.apache.http.entity.mime.FormBodyPartBuilder;
+import org.apache.http.entity.mime.MIME;
+import org.apache.http.entity.mime.MultipartEntityBuilder;
 import org.apache.http.entity.mime.content.FileBody;
 import org.apache.http.entity.mime.content.StringBody;
 import org.apache.http.impl.client.AbstractHttpClient;
@@ -1076,12 +1077,24 @@ public class HTTPHC4Impl extends HTTPHCA
             Charset charset = null;
             if(haveContentEncoding) {
                 charset = Charset.forName(contentEncoding);
+            } else {
+                charset = MIME.DEFAULT_CHARSET;
+            }
+            
+            if(log.isDebugEnabled()) {
+                log.debug("Building multipart 
with:getDoBrowserCompatibleMultipart():"+
+                        getDoBrowserCompatibleMultipart()+
+                        ", with charset:"+charset+
+                        ", haveContentEncoding:"+haveContentEncoding);
             }
-
             // Write the request to our own stream
-            MultipartEntity multiPart = new MultipartEntity(
-                    getDoBrowserCompatibleMultipart() ? 
HttpMultipartMode.BROWSER_COMPATIBLE : HttpMultipartMode.STRICT,
-                            null, charset);
+            MultipartEntityBuilder multipartEntityBuilder = 
MultipartEntityBuilder.create()
+                    .setCharset(charset);
+            if(getDoBrowserCompatibleMultipart()) {
+                multipartEntityBuilder.setLaxMode();
+            } else {
+                multipartEntityBuilder.setStrictMode();
+            }
             // Create the parts
             // Add any parameters
             for (JMeterProperty jMeterProperty : getArguments()) {
@@ -1090,9 +1103,10 @@ public class HTTPHC4Impl extends HTTPHCA
                 if (arg.isSkippable(parameterName)) {
                     continue;
                 }
-                StringBody stringBody = new StringBody(arg.getValue(), 
charset);
-                FormBodyPart formPart = new FormBodyPart(arg.getName(), 
stringBody);
-                multiPart.addPart(formPart);
+                StringBody stringBody = new StringBody(arg.getValue(), 
ContentType.create("text/plain", charset));
+                FormBodyPart formPart = FormBodyPartBuilder.create(
+                        parameterName, stringBody).build();
+                multipartEntityBuilder.addPart(formPart);
             }
 
             // Add any files
@@ -1103,17 +1117,18 @@ public class HTTPHC4Impl extends HTTPHCA
                 
                 File reservedFile = 
FileServer.getFileServer().getResolvedFile(file.getPath());
                 fileBodies[i] = new ViewableFileBody(reservedFile, 
file.getMimeType());
-                multiPart.addPart(file.getParamName(),fileBodies[i]);
+                multipartEntityBuilder.addPart(file.getParamName(), 
fileBodies[i] );
             }
 
-            post.setEntity(multiPart);
+            HttpEntity entity = multipartEntityBuilder.build();
+            post.setEntity(entity);
 
-            if (multiPart.isRepeatable()){
+            if (entity.isRepeatable()){
                 ByteArrayOutputStream bos = new ByteArrayOutputStream();
                 for(ViewableFileBody fileBody : fileBodies){
                     fileBody.hideFileData = true;
                 }
-                multiPart.writeTo(bos);
+                entity.writeTo(bos);
                 for(ViewableFileBody fileBody : fileBodies){
                     fileBody.hideFileData = false;
                 }


Reply via email to