You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by se...@apache.org on 2012/08/23 14:47:05 UTC
svn commit: r1376466 -
/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
Author: sebb
Date: Thu Aug 23 12:47:04 2012
New Revision: 1376466
URL: http://svn.apache.org/viewvc?rev=1376466&view=rev
Log:
Fix bug accidentally introduced in r1351008 - ContentType cannot have null parameter, so need to fetch File entry MIME type before creating it
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=1376466&r1=1376465&r2=1376466&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 Thu Aug 23 12:47:04 2012
@@ -1010,18 +1010,29 @@ public class HTTPHC4Impl extends HTTPHCA
StringBuilder putBody = new StringBuilder(1000);
boolean hasPutBody = false;
+ HTTPFileArg files[] = getHTTPFiles();
// Check if the header manager had a content type header
// This allows the user to specify his own content-type
Header contentTypeHeader = put.getFirstHeader(HTTPConstants.HEADER_CONTENT_TYPE);
- final String contentTypeValue = contentTypeHeader == null ? null : contentTypeHeader.getValue();
- final boolean hasContentTypeHeader = contentTypeValue != null;
+ String contentTypeValue = contentTypeHeader == null ? null : contentTypeHeader.getValue();
+ if(contentTypeValue == null) {
+ // Allow the mimetype of the file to control the content type
+ // This is not obvious in GUI if you are not uploading any files,
+ // but just sending the content of nameless parameters
+ HTTPFileArg file = files.length > 0? files[0] : null;
+ if(file != null && file.getMimeType() != null && file.getMimeType().length() > 0) {
+ contentTypeValue = file.getMimeType();
+ }
+ }
// Check for local contentEncoding override
final String contentEncoding = getContentEncodingOrNull();
final boolean haveContentEncoding = contentEncoding != null;
-
- HttpParams putParams = put.getParams();
- HTTPFileArg files[] = getHTTPFiles();
+
+ final HttpParams putParams = put.getParams();
+ final String charset = getCharsetWithDefault(putParams);
+ final ContentType contentType = ContentType.create(contentTypeValue, charset);
+
// If there are no arguments, we can send a file as the body of the request
@@ -1029,7 +1040,7 @@ public class HTTPHC4Impl extends HTTPHCA
hasPutBody = true;
// If getSendFileAsPostBody returned true, it's sure that file is not null
- FileEntity fileRequestEntity = new FileEntity(new File(files[0].getPath()), (ContentType) null); // TODO is null correct?
+ FileEntity fileRequestEntity = new FileEntity(new File(files[0].getPath()), contentType);
put.setEntity(fileRequestEntity);
// We just add placeholder text for file content
@@ -1040,12 +1051,6 @@ public class HTTPHC4Impl extends HTTPHCA
else if(getSendParameterValuesAsPostBody()) {
hasPutBody = true;
- // If a content encoding is specified, we set it as http parameter, so that
- // the post body will be encoded in the specified content encoding
- if(haveContentEncoding) {
- putParams.setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET,contentEncoding);
- }
- String charset = getCharsetWithDefault(putParams);
// Just append all the parameter values, and use that as the post body
StringBuilder putBodyContent = new StringBuilder();
PropertyIterator args = getArguments().iterator();
@@ -1059,8 +1064,6 @@ public class HTTPHC4Impl extends HTTPHCA
}
putBodyContent.append(value);
}
- ContentType contentType =
- ContentType.create(contentTypeValue, charset);
StringEntity requestEntity = new StringEntity(putBodyContent.toString(), contentType);
put.setEntity(requestEntity);
}
@@ -1072,7 +1075,6 @@ public class HTTPHC4Impl extends HTTPHCA
ByteArrayOutputStream bos = new ByteArrayOutputStream();
put.getEntity().writeTo(bos);
bos.flush();
- String charset = getCharsetWithDefault(putParams);
// We get the posted bytes using the charset that was used to create them
// if none was set, platform encoding will be used
@@ -1082,16 +1084,6 @@ public class HTTPHC4Impl extends HTTPHCA
else {
putBody.append("<RequestEntity was not repeatable, cannot view what was sent>");
}
- if(!hasContentTypeHeader) {
- // Allow the mimetype of the file to control the content type
- // This is not obvious in GUI if you are not uploading any files,
- // but just sending the content of nameless parameters
- // TODO: needs a multiple file upload scenerio
- HTTPFileArg file = files.length > 0? files[0] : null;
- if(file != null && file.getMimeType() != null && file.getMimeType().length() > 0) {
- put.setHeader(HTTPConstants.HEADER_CONTENT_TYPE, file.getMimeType());
- }
- }
return putBody.toString();
}
return null;