Lines 98-104
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
98 |
|
98 |
|
99 |
private static final boolean canSetPreEmptive; // OK to set pre-emptive auth? |
99 |
private static final boolean canSetPreEmptive; // OK to set pre-emptive auth? |
100 |
|
100 |
|
101 |
private static final ThreadLocal<Map<HostConfiguration, HttpClient>> httpClients = |
101 |
private static final ThreadLocal<Map<HostConfiguration, HttpClient>> httpClients = |
102 |
new ThreadLocal<Map<HostConfiguration, HttpClient>>(){ |
102 |
new ThreadLocal<Map<HostConfiguration, HttpClient>>(){ |
103 |
@Override |
103 |
@Override |
104 |
protected Map<HostConfiguration, HttpClient> initialValue() { |
104 |
protected Map<HostConfiguration, HttpClient> initialValue() { |
Lines 112-152
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
112 |
private volatile boolean resetSSLContext; |
112 |
private volatile boolean resetSSLContext; |
113 |
|
113 |
|
114 |
static { |
114 |
static { |
115 |
log.info("HTTP request retry count = "+RETRY_COUNT); |
115 |
log.info("HTTP request retry count = " + RETRY_COUNT); |
116 |
if (CPS_HTTP > 0) { |
116 |
if (CPS_HTTP > 0) { |
117 |
log.info("Setting up HTTP SlowProtocol, cps="+CPS_HTTP); |
117 |
log.info("Setting up HTTP SlowProtocol, cps=" + CPS_HTTP); |
118 |
Protocol.registerProtocol(HTTPConstants.PROTOCOL_HTTP, |
118 |
Protocol protocol = new Protocol(HTTPConstants.PROTOCOL_HTTP, new SlowHttpClientSocketFactory(CPS_HTTP), HTTPConstants.DEFAULT_HTTP_PORT); |
119 |
new Protocol(HTTPConstants.PROTOCOL_HTTP,new SlowHttpClientSocketFactory(CPS_HTTP),HTTPConstants.DEFAULT_HTTP_PORT)); |
119 |
Protocol.registerProtocol(HTTPConstants.PROTOCOL_HTTP, protocol); |
120 |
} |
120 |
} |
121 |
|
121 |
|
122 |
// Now done in JsseSSLManager (which needs to register the protocol) |
|
|
123 |
// cps = |
124 |
// JMeterUtils.getPropDefault("httpclient.socket.https.cps", 0); // $NON-NLS-1$ |
125 |
// |
126 |
// if (cps > 0) { |
127 |
// log.info("Setting up HTTPS SlowProtocol, cps="+cps); |
128 |
// Protocol.registerProtocol(PROTOCOL_HTTPS, |
129 |
// new Protocol(PROTOCOL_HTTPS,new SlowHttpClientSocketFactory(cps),DEFAULT_HTTPS_PORT)); |
130 |
// } |
131 |
|
132 |
// Set default parameters as needed |
122 |
// Set default parameters as needed |
133 |
HttpParams params = DefaultHttpParams.getDefaultParams(); |
123 |
HttpParams params = DefaultHttpParams.getDefaultParams(); |
134 |
|
124 |
|
135 |
// Process Commons HttpClient parameters file |
125 |
// Process Commons HttpClient parameters file |
136 |
String file=JMeterUtils.getProperty("httpclient.parameters.file"); // $NON-NLS-1$ |
126 |
String file = JMeterUtils.getProperty("httpclient.parameters.file"); // $NON-NLS-1$ |
137 |
if (file != null) { |
127 |
if (file != null) { |
138 |
HttpClientDefaultParameters.load(file, params); |
128 |
HttpClientDefaultParameters.load(file, params); |
139 |
} |
129 |
} |
140 |
|
130 |
|
141 |
// If the pre-emptive parameter is undefined, then we can set it as needed |
131 |
// If the pre-emptive parameter is undefined, then we can set it as needed |
142 |
// otherwise we should do what the user requested. |
132 |
// otherwise we should do what the user requested. |
143 |
canSetPreEmptive = params.getParameter(HTTP_AUTHENTICATION_PREEMPTIVE) == null; |
133 |
canSetPreEmptive = params.getParameter(HTTP_AUTHENTICATION_PREEMPTIVE) == null; |
144 |
|
134 |
|
145 |
// Handle old-style JMeter properties |
135 |
// Handle old-style JMeter properties |
146 |
try { |
136 |
try { |
147 |
params.setParameter(HttpMethodParams.PROTOCOL_VERSION, HttpVersion.parse("HTTP/"+HTTP_VERSION)); |
137 |
params.setParameter(HttpMethodParams.PROTOCOL_VERSION, HttpVersion.parse("HTTP/" + HTTP_VERSION)); |
148 |
} catch (ProtocolException e) { |
138 |
} catch (ProtocolException e) { |
149 |
log.warn("Problem setting protocol version "+e.getLocalizedMessage()); |
139 |
log.warn("Problem setting protocol version " + e.getLocalizedMessage()); |
150 |
} |
140 |
} |
151 |
|
141 |
|
152 |
if (SO_TIMEOUT >= 0){ |
142 |
if (SO_TIMEOUT >= 0){ |
Lines 193-199
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
193 |
|
183 |
|
194 |
if (log.isDebugEnabled()) { |
184 |
if (log.isDebugEnabled()) { |
195 |
log.debug("Start : sample " + urlStr); |
185 |
log.debug("Start : sample " + urlStr); |
196 |
log.debug("method " + method+ " followingRedirect " + areFollowingRedirect + " depth " + frameDepth); |
186 |
log.debug("method " + method + " followingRedirect " + areFollowingRedirect + " depth " + frameDepth); |
197 |
} |
187 |
} |
198 |
|
188 |
|
199 |
HttpMethodBase httpMethod = null; |
189 |
HttpMethodBase httpMethod = null; |
Lines 235-241
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
235 |
} |
225 |
} |
236 |
}; |
226 |
}; |
237 |
} else { |
227 |
} else { |
238 |
throw new IllegalArgumentException("Unexpected method: '"+method+"'"); |
228 |
throw new IllegalArgumentException("Unexpected method: '" + method + "'"); |
239 |
} |
229 |
} |
240 |
|
230 |
|
241 |
final CacheManager cacheManager = getCacheManager(); |
231 |
final CacheManager cacheManager = getCacheManager(); |
Lines 256-262
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
256 |
if (method.equals(HTTPConstants.POST)) { |
246 |
if (method.equals(HTTPConstants.POST)) { |
257 |
String postBody = sendPostData((PostMethod)httpMethod); |
247 |
String postBody = sendPostData((PostMethod)httpMethod); |
258 |
res.setQueryString(postBody); |
248 |
res.setQueryString(postBody); |
259 |
} else if (method.equals(HTTPConstants.PUT) || method.equals(HTTPConstants.PATCH) |
249 |
} else if (method.equals(HTTPConstants.PUT) || method.equals(HTTPConstants.PATCH) |
260 |
|| method.equals(HTTPConstants.DELETE)) { |
250 |
|| method.equals(HTTPConstants.DELETE)) { |
261 |
String putBody = sendEntityData((EntityEnclosingMethod) httpMethod); |
251 |
String putBody = sendEntityData((EntityEnclosingMethod) httpMethod); |
262 |
res.setQueryString(putBody); |
252 |
res.setQueryString(putBody); |
Lines 281-287
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
281 |
Header responseHeader = httpMethod.getResponseHeader(HTTPConstants.HEADER_CONTENT_ENCODING); |
271 |
Header responseHeader = httpMethod.getResponseHeader(HTTPConstants.HEADER_CONTENT_ENCODING); |
282 |
if (responseHeader!= null && HTTPConstants.ENCODING_GZIP.equals(responseHeader.getValue())) { |
272 |
if (responseHeader!= null && HTTPConstants.ENCODING_GZIP.equals(responseHeader.getValue())) { |
283 |
InputStream tmpInput = new GZIPInputStream(instream); // tmp inputstream needs to have a good counting |
273 |
InputStream tmpInput = new GZIPInputStream(instream); // tmp inputstream needs to have a good counting |
284 |
res.setResponseData(readResponse(res, tmpInput, (int) httpMethod.getResponseContentLength())); |
274 |
res.setResponseData(readResponse(res, tmpInput, (int) httpMethod.getResponseContentLength())); |
285 |
} else { |
275 |
} else { |
286 |
res.setResponseData(readResponse(res, instream, (int) httpMethod.getResponseContentLength())); |
276 |
res.setResponseData(readResponse(res, instream, (int) httpMethod.getResponseContentLength())); |
287 |
} |
277 |
} |
Lines 308-314
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
308 |
if (h != null)// Can be missing, e.g. on redirect |
298 |
if (h != null)// Can be missing, e.g. on redirect |
309 |
{ |
299 |
{ |
310 |
ct = h.getValue(); |
300 |
ct = h.getValue(); |
311 |
res.setContentType(ct);// e.g. text/html; charset=ISO-8859-1 |
301 |
res.setContentType(ct); // e.g. text/html; charset=ISO-8859-1 |
312 |
res.setEncodingAndType(ct); |
302 |
res.setEncodingAndType(ct); |
313 |
} |
303 |
} |
314 |
|
304 |
|
Lines 331-337
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
331 |
log.debug("Response headersSize=" + res.getHeadersSize() + " bodySize=" + res.getBodySize() |
321 |
log.debug("Response headersSize=" + res.getHeadersSize() + " bodySize=" + res.getBodySize() |
332 |
+ " Total=" + (res.getHeadersSize() + res.getBodySize())); |
322 |
+ " Total=" + (res.getHeadersSize() + res.getBodySize())); |
333 |
} |
323 |
} |
334 |
|
324 |
|
335 |
// If we redirected automatically, the URL may have changed |
325 |
// If we redirected automatically, the URL may have changed |
336 |
if (getAutoRedirects()){ |
326 |
if (getAutoRedirects()){ |
337 |
res.setURL(new URL(httpMethod.getURI().toString())); |
327 |
res.setURL(new URL(httpMethod.getURI().toString())); |
Lines 350-360
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
350 |
|
340 |
|
351 |
log.debug("End : sample"); |
341 |
log.debug("End : sample"); |
352 |
return res; |
342 |
return res; |
353 |
} catch (IllegalArgumentException e) { // e.g. some kinds of invalid URL |
343 |
} catch (IllegalArgumentException e) { // e.g. some kind of invalid URL |
354 |
res.sampleEnd(); |
344 |
res.sampleEnd(); |
355 |
// pick up headers if failed to execute the request |
345 |
// pick up headers if failed to execute the request |
356 |
// httpMethod can be null if method is unexpected |
346 |
// httpMethod can be null if method is unexpected |
357 |
if(httpMethod != null) { |
347 |
if (httpMethod != null) { |
358 |
res.setRequestHeaders(getConnectionHeaders(httpMethod)); |
348 |
res.setRequestHeaders(getConnectionHeaders(httpMethod)); |
359 |
} |
349 |
} |
360 |
errorResult(e, res); |
350 |
errorResult(e, res); |
Lines 372-385
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
372 |
} |
362 |
} |
373 |
} |
363 |
} |
374 |
} |
364 |
} |
375 |
|
365 |
|
376 |
/** |
366 |
/** |
377 |
* Calculate response headers size |
367 |
* Calculate response headers size |
378 |
* |
368 |
* |
379 |
* @return the size response headers (in bytes) |
369 |
* @return the size response headers (in bytes) |
380 |
*/ |
370 |
*/ |
381 |
private static int calculateHeadersSize(HttpMethodBase httpMethod) { |
371 |
private static int calculateHeadersSize(HttpMethodBase httpMethod) { |
382 |
int headerSize = httpMethod.getStatusLine().toString().length()+2; // add a \r\n |
372 |
int headerSize = httpMethod.getStatusLine().toString().length() + 2; // add a \r\n |
383 |
Header[] rh = httpMethod.getResponseHeaders(); |
373 |
Header[] rh = httpMethod.getResponseHeaders(); |
384 |
for (int i = 0; i < rh.length; i++) { |
374 |
for (int i = 0; i < rh.length; i++) { |
385 |
headerSize += rh[i].toString().length(); // already include the \r\n |
375 |
headerSize += rh[i].toString().length(); // already include the \r\n |
Lines 428-439
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
428 |
int port = uri.getPort(); |
418 |
int port = uri.getPort(); |
429 |
|
419 |
|
430 |
/* |
420 |
/* |
431 |
* We use the HostConfiguration as the key to retrieve the HttpClient, |
421 |
* We use the HostConfiguration as the key to retrieve the HttpClient, |
432 |
* so need to ensure that any items used in its equals/hashcode methods are |
422 |
* so need to ensure that any items used in its equals/hashcode methods are |
433 |
* not changed after use, i.e.: |
423 |
* not changed after use, i.e.: |
434 |
* host, port, protocol, localAddress, proxy |
424 |
* host, port, protocol, localAddress, proxy |
435 |
* |
425 |
*/ |
436 |
*/ |
|
|
437 |
HostConfiguration hc = new HostConfiguration(); |
426 |
HostConfiguration hc = new HostConfiguration(); |
438 |
hc.setHost(host, port, protocol); // All needed to ensure re-usablility |
427 |
hc.setHost(host, port, protocol); // All needed to ensure re-usablility |
439 |
|
428 |
|
Lines 476-482
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
476 |
if ( httpClient == null ) |
465 |
if ( httpClient == null ) |
477 |
{ |
466 |
{ |
478 |
httpClient = new HttpClient(new SimpleHttpConnectionManager()); |
467 |
httpClient = new HttpClient(new SimpleHttpConnectionManager()); |
479 |
httpClient.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, |
468 |
httpClient.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, |
480 |
new DefaultHttpMethodRetryHandler(RETRY_COUNT, false)); |
469 |
new DefaultHttpMethodRetryHandler(RETRY_COUNT, false)); |
481 |
if (log.isDebugEnabled()) { |
470 |
if (log.isDebugEnabled()) { |
482 |
log.debug("Created new HttpClient: @"+System.identityHashCode(httpClient)); |
471 |
log.debug("Created new HttpClient: @"+System.identityHashCode(httpClient)); |
Lines 656-664
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
656 |
// Get all the request headers |
645 |
// Get all the request headers |
657 |
StringBuilder hdrs = new StringBuilder(100); |
646 |
StringBuilder hdrs = new StringBuilder(100); |
658 |
Header[] requestHeaders = method.getRequestHeaders(); |
647 |
Header[] requestHeaders = method.getRequestHeaders(); |
659 |
for(int i = 0; i < requestHeaders.length; i++) { |
648 |
for (int i = 0; i < requestHeaders.length; i++) { |
660 |
// Exclude the COOKIE header, since cookie is reported separately in the sample |
649 |
// Exclude the COOKIE header, since cookie is reported separately in the sample |
661 |
if(!HTTPConstants.HEADER_COOKIE.equalsIgnoreCase(requestHeaders[i].getName())) { |
650 |
if (!HTTPConstants.HEADER_COOKIE.equalsIgnoreCase(requestHeaders[i].getName())) { |
662 |
hdrs.append(requestHeaders[i].getName()); |
651 |
hdrs.append(requestHeaders[i].getName()); |
663 |
hdrs.append(": "); // $NON-NLS-1$ |
652 |
hdrs.append(": "); // $NON-NLS-1$ |
664 |
hdrs.append(requestHeaders[i].getValue()); |
653 |
hdrs.append(requestHeaders[i].getValue()); |
Lines 737-747
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
737 |
HTTPFileArg files[] = getHTTPFiles(); |
726 |
HTTPFileArg files[] = getHTTPFiles(); |
738 |
// Check if we should do a multipart/form-data or an |
727 |
// Check if we should do a multipart/form-data or an |
739 |
// application/x-www-form-urlencoded post request |
728 |
// application/x-www-form-urlencoded post request |
740 |
if(getUseMultipartForPost()) { |
729 |
if (getUseMultipartForPost()) { |
741 |
// If a content encoding is specified, we use that as the |
730 |
// If a content encoding is specified, we use that as the |
742 |
// encoding of any parameter values |
731 |
// encoding of any parameter values |
743 |
String contentEncoding = getContentEncoding(); |
732 |
String contentEncoding = getContentEncoding(); |
744 |
if(isNullOrEmptyTrimmed(contentEncoding)) { |
733 |
if (isNullOrEmptyTrimmed(contentEncoding)) { |
745 |
contentEncoding = null; |
734 |
contentEncoding = null; |
746 |
} |
735 |
} |
747 |
|
736 |
|
Lines 787-797
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
787 |
|
776 |
|
788 |
// If the Multipart is repeatable, we can send it first to |
777 |
// If the Multipart is repeatable, we can send it first to |
789 |
// our own stream, without the actual file content, so we can return it |
778 |
// our own stream, without the actual file content, so we can return it |
790 |
if(multiPart.isRepeatable()) { |
779 |
if (multiPart.isRepeatable()) { |
791 |
// For all the file multiparts, we must tell it to not include |
780 |
// For all the file multiparts, we must tell it to not include |
792 |
// the actual file content |
781 |
// the actual file content |
793 |
for(int i = 0; i < partNo; i++) { |
782 |
for (int i = 0; i < partNo; i++) { |
794 |
if(parts[i] instanceof ViewableFilePart) { |
783 |
if (parts[i] instanceof ViewableFilePart) { |
795 |
((ViewableFilePart) parts[i]).setHideFileData(true); // .sendMultipartWithoutFileContent(bos); |
784 |
((ViewableFilePart) parts[i]).setHideFileData(true); // .sendMultipartWithoutFileContent(bos); |
796 |
} |
785 |
} |
797 |
} |
786 |
} |
Lines 807-814
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
807 |
|
796 |
|
808 |
// For all the file multiparts, we must revert the hiding of |
797 |
// For all the file multiparts, we must revert the hiding of |
809 |
// the actual file content |
798 |
// the actual file content |
810 |
for(int i = 0; i < partNo; i++) { |
799 |
for (int i = 0; i < partNo; i++) { |
811 |
if(parts[i] instanceof ViewableFilePart) { |
800 |
if (parts[i] instanceof ViewableFilePart) { |
812 |
((ViewableFilePart) parts[i]).setHideFileData(false); |
801 |
((ViewableFilePart) parts[i]).setHideFileData(false); |
813 |
} |
802 |
} |
814 |
} |
803 |
} |
Lines 823-835
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
823 |
Header contentTypeHeader = post.getRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE); |
812 |
Header contentTypeHeader = post.getRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE); |
824 |
boolean hasContentTypeHeader = contentTypeHeader != null && contentTypeHeader.getValue() != null && contentTypeHeader.getValue().length() > 0; |
813 |
boolean hasContentTypeHeader = contentTypeHeader != null && contentTypeHeader.getValue() != null && contentTypeHeader.getValue().length() > 0; |
825 |
// If there are no arguments, we can send a file as the body of the request |
814 |
// If there are no arguments, we can send a file as the body of the request |
826 |
// TODO: needs a multiple file upload scenerio |
815 |
// TODO: needs a multiple file upload scenario |
827 |
if(!hasArguments() && getSendFileAsPostBody()) { |
816 |
if (!hasArguments() && getSendFileAsPostBody()) { |
828 |
// If getSendFileAsPostBody returned true, it's sure that file is not null |
817 |
// If getSendFileAsPostBody returned true, it's sure that file is not null |
829 |
HTTPFileArg file = files[0]; |
818 |
HTTPFileArg file = files[0]; |
830 |
if(!hasContentTypeHeader) { |
819 |
if (!hasContentTypeHeader) { |
831 |
// Allow the mimetype of the file to control the content type |
820 |
// Allow the mimetype of the file to control the content type |
832 |
if(file.getMimeType() != null && file.getMimeType().length() > 0) { |
821 |
if (file.getMimeType() != null && file.getMimeType().length() > 0) { |
833 |
post.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE, file.getMimeType()); |
822 |
post.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE, file.getMimeType()); |
834 |
} |
823 |
} |
835 |
else { |
824 |
else { |
Lines 851-873
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
851 |
// the post body will be encoded in the specified content encoding |
840 |
// the post body will be encoded in the specified content encoding |
852 |
String contentEncoding = getContentEncoding(); |
841 |
String contentEncoding = getContentEncoding(); |
853 |
boolean haveContentEncoding = false; |
842 |
boolean haveContentEncoding = false; |
854 |
if(isNullOrEmptyTrimmed(contentEncoding)) { |
843 |
if (isNullOrEmptyTrimmed(contentEncoding)) { |
855 |
contentEncoding=null; |
844 |
contentEncoding = null; |
856 |
} else { |
845 |
} else { |
857 |
post.getParams().setContentCharset(contentEncoding); |
846 |
post.getParams().setContentCharset(contentEncoding); |
858 |
haveContentEncoding = true; |
847 |
haveContentEncoding = true; |
859 |
} |
848 |
} |
860 |
|
849 |
|
861 |
// If none of the arguments have a name specified, we |
850 |
// If none of the arguments have a name specified, we |
862 |
// just send all the values as the post body |
851 |
// just send all the values as the post body |
863 |
if(getSendParameterValuesAsPostBody()) { |
852 |
if (getSendParameterValuesAsPostBody()) { |
864 |
// Allow the mimetype of the file to control the content type |
853 |
// Allow the mimetype of the file to control the content type |
865 |
// This is not obvious in GUI if you are not uploading any files, |
854 |
// This is not obvious in GUI if you are not uploading any files, |
866 |
// but just sending the content of nameless parameters |
855 |
// but just sending the content of nameless parameters |
867 |
// TODO: needs a multiple file upload scenerio |
856 |
// TODO: needs a multiple file upload scenario |
868 |
if(!hasContentTypeHeader) { |
857 |
if (!hasContentTypeHeader) { |
869 |
HTTPFileArg file = files.length > 0? files[0] : null; |
858 |
HTTPFileArg file = files.length > 0? files[0] : null; |
870 |
if(file != null && file.getMimeType() != null && file.getMimeType().length() > 0) { |
859 |
if (file != null && file.getMimeType() != null && file.getMimeType().length() > 0) { |
871 |
post.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE, file.getMimeType()); |
860 |
post.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE, file.getMimeType()); |
872 |
} |
861 |
} |
873 |
else { |
862 |
else { |
Lines 896-902
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
896 |
// It is a normal post request, with parameter names and values |
885 |
// It is a normal post request, with parameter names and values |
897 |
|
886 |
|
898 |
// Set the content type |
887 |
// Set the content type |
899 |
if(!hasContentTypeHeader) { |
888 |
if (!hasContentTypeHeader) { |
900 |
post.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE, HTTPConstants.APPLICATION_X_WWW_FORM_URLENCODED); |
889 |
post.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE, HTTPConstants.APPLICATION_X_WWW_FORM_URLENCODED); |
901 |
} |
890 |
} |
902 |
// Add the parameters |
891 |
// Add the parameters |
Lines 911-923
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
911 |
continue; |
900 |
continue; |
912 |
} |
901 |
} |
913 |
String parameterValue = arg.getValue(); |
902 |
String parameterValue = arg.getValue(); |
914 |
if(!arg.isAlwaysEncoded()) { |
903 |
if (!arg.isAlwaysEncoded()) { |
915 |
// The value is already encoded by the user |
904 |
// The value is already encoded by the user |
916 |
// Must decode the value now, so that when the |
905 |
// Must decode the value now, so that when the |
917 |
// httpclient encodes it, we end up with the same value |
906 |
// httpclient encodes it, we end up with the same value |
918 |
// as the user had entered. |
907 |
// as the user had entered. |
919 |
String urlContentEncoding = contentEncoding; |
908 |
String urlContentEncoding = contentEncoding; |
920 |
if(urlContentEncoding == null || urlContentEncoding.length() == 0) { |
909 |
if (urlContentEncoding == null || urlContentEncoding.length() == 0) { |
921 |
// Use the default encoding for urls |
910 |
// Use the default encoding for urls |
922 |
urlContentEncoding = EncoderCache.URL_ARGUMENT_ENCODING; |
911 |
urlContentEncoding = EncoderCache.URL_ARGUMENT_ENCODING; |
923 |
} |
912 |
} |
Lines 927-951
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
927 |
// Add the parameter, httpclient will urlencode it |
916 |
// Add the parameter, httpclient will urlencode it |
928 |
post.addParameter(parameterName, parameterValue); |
917 |
post.addParameter(parameterName, parameterValue); |
929 |
} |
918 |
} |
930 |
|
|
|
931 |
/* |
932 |
// // Alternative implementation, to make sure that HTTPSampler and HTTPSampler2 |
933 |
// // sends the same post body. |
934 |
// |
935 |
// // Only include the content char set in the content-type header if it is not |
936 |
// // an APPLICATION_X_WWW_FORM_URLENCODED content type |
937 |
// String contentCharSet = null; |
938 |
// if(!post.getRequestHeader(HEADER_CONTENT_TYPE).getValue().equals(APPLICATION_X_WWW_FORM_URLENCODED)) { |
939 |
// contentCharSet = post.getRequestCharSet(); |
940 |
// } |
941 |
// StringRequestEntity requestEntity = new StringRequestEntity(getQueryString(contentEncoding), post.getRequestHeader(HEADER_CONTENT_TYPE).getValue(), contentCharSet); |
942 |
// post.setRequestEntity(requestEntity); |
943 |
*/ |
944 |
} |
919 |
} |
945 |
|
920 |
|
946 |
// If the request entity is repeatable, we can send it first to |
921 |
// If the request entity is repeatable, we can send it first to |
947 |
// our own stream, so we can return it |
922 |
// our own stream, so we can return it |
948 |
if(post.getRequestEntity().isRepeatable()) { |
923 |
if (post.getRequestEntity().isRepeatable()) { |
949 |
ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
924 |
ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
950 |
post.getRequestEntity().writeRequest(bos); |
925 |
post.getRequestEntity().writeRequest(bos); |
951 |
bos.flush(); |
926 |
bos.flush(); |
Lines 980-986
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
980 |
|
955 |
|
981 |
// If there are no arguments, we can send a file as the body of the request |
956 |
// If there are no arguments, we can send a file as the body of the request |
982 |
|
957 |
|
983 |
if(!hasArguments() && getSendFileAsPostBody()) { |
958 |
if (!hasArguments() && getSendFileAsPostBody()) { |
984 |
hasPutBody = true; |
959 |
hasPutBody = true; |
985 |
|
960 |
|
986 |
// If getSendFileAsPostBody returned true, it's sure that file is not null |
961 |
// If getSendFileAsPostBody returned true, it's sure that file is not null |
Lines 989-1002
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
989 |
} |
964 |
} |
990 |
// If none of the arguments have a name specified, we |
965 |
// If none of the arguments have a name specified, we |
991 |
// just send all the values as the put body |
966 |
// just send all the values as the put body |
992 |
else if(getSendParameterValuesAsPostBody()) { |
967 |
else if (getSendParameterValuesAsPostBody()) { |
993 |
hasPutBody = true; |
968 |
hasPutBody = true; |
994 |
|
969 |
|
995 |
// If a content encoding is specified, we set it as http parameter, so that |
970 |
// If a content encoding is specified, we set it as http parameter, so that |
996 |
// the post body will be encoded in the specified content encoding |
971 |
// the post body will be encoded in the specified content encoding |
997 |
String contentEncoding = getContentEncoding(); |
972 |
String contentEncoding = getContentEncoding(); |
998 |
boolean haveContentEncoding = false; |
973 |
boolean haveContentEncoding = false; |
999 |
if(isNullOrEmptyTrimmed(contentEncoding)) { |
974 |
if (isNullOrEmptyTrimmed(contentEncoding)) { |
1000 |
contentEncoding = null; |
975 |
contentEncoding = null; |
1001 |
} else { |
976 |
} else { |
1002 |
put.getParams().setContentCharset(contentEncoding); |
977 |
put.getParams().setContentCharset(contentEncoding); |
Lines 1017-1033
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
1017 |
putBodyContent.append(value); |
992 |
putBodyContent.append(value); |
1018 |
} |
993 |
} |
1019 |
String contentTypeValue = null; |
994 |
String contentTypeValue = null; |
1020 |
if(hasContentTypeHeader) { |
995 |
if (hasContentTypeHeader) { |
1021 |
contentTypeValue = put.getRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE).getValue(); |
996 |
contentTypeValue = put.getRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE).getValue(); |
1022 |
} |
997 |
} |
1023 |
StringRequestEntity requestEntity = new StringRequestEntity(putBodyContent.toString(), contentTypeValue, put.getRequestCharSet()); |
998 |
StringRequestEntity requestEntity = new StringRequestEntity(putBodyContent.toString(), contentTypeValue, put.getRequestCharSet()); |
1024 |
put.setRequestEntity(requestEntity); |
999 |
put.setRequestEntity(requestEntity); |
1025 |
} |
1000 |
} |
1026 |
// Check if we have any content to send for body |
1001 |
// Check if we have any content to send for body |
1027 |
if(hasPutBody) { |
1002 |
if (hasPutBody) { |
1028 |
// If the request entity is repeatable, we can send it first to |
1003 |
// If the request entity is repeatable, we can send it first to |
1029 |
// our own stream, so we can return it |
1004 |
// our own stream, so we can return it |
1030 |
if(put.getRequestEntity().isRepeatable()) { |
1005 |
if (put.getRequestEntity().isRepeatable()) { |
1031 |
ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
1006 |
ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
1032 |
put.getRequestEntity().writeRequest(bos); |
1007 |
put.getRequestEntity().writeRequest(bos); |
1033 |
bos.flush(); |
1008 |
bos.flush(); |
Lines 1038-1050
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
1038 |
else { |
1013 |
else { |
1039 |
putBody.append("<RequestEntity was not repeatable, cannot view what was sent>"); |
1014 |
putBody.append("<RequestEntity was not repeatable, cannot view what was sent>"); |
1040 |
} |
1015 |
} |
1041 |
if(!hasContentTypeHeader) { |
1016 |
if (!hasContentTypeHeader) { |
1042 |
// Allow the mimetype of the file to control the content type |
1017 |
// Allow the mimetype of the file to control the content type |
1043 |
// This is not obvious in GUI if you are not uploading any files, |
1018 |
// This is not obvious in GUI if you are not uploading any files, |
1044 |
// but just sending the content of nameless parameters |
1019 |
// but just sending the content of nameless parameters |
1045 |
// TODO: needs a multiple file upload scenerio |
1020 |
// TODO: needs a multiple file upload scenario |
1046 |
HTTPFileArg file = files.length > 0? files[0] : null; |
1021 |
HTTPFileArg file = files.length > 0? files[0] : null; |
1047 |
if(file != null && file.getMimeType() != null && file.getMimeType().length() > 0) { |
1022 |
if (file != null && file.getMimeType() != null && file.getMimeType().length() > 0) { |
1048 |
put.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE, file.getMimeType()); |
1023 |
put.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE, file.getMimeType()); |
1049 |
} |
1024 |
} |
1050 |
} |
1025 |
} |
Lines 1074-1081
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
1074 |
protected void sendData(OutputStream out) throws IOException { |
1049 |
protected void sendData(OutputStream out) throws IOException { |
1075 |
// Check if we should send only placeholder text for the |
1050 |
// Check if we should send only placeholder text for the |
1076 |
// file content, or the real file content |
1051 |
// file content, or the real file content |
1077 |
if(hideFileData) { |
1052 |
if (hideFileData) { |
1078 |
out.write("<actual file content, not shown here>".getBytes());// encoding does not really matter here |
1053 |
// encoding does not really matter here |
|
|
1054 |
out.write("<actual file content, not shown here>".getBytes()); |
1079 |
} |
1055 |
} |
1080 |
else { |
1056 |
else { |
1081 |
super.sendData(out); |
1057 |
super.sendData(out); |
Lines 1118-1136
public class HTTPHC3Impl extends HTTPHCAbstractImpl {
Link Here
|
1118 |
} |
1094 |
} |
1119 |
|
1095 |
|
1120 |
/** |
1096 |
/** |
1121 |
* |
1097 |
* |
1122 |
*/ |
1098 |
*/ |
1123 |
private void closeThreadLocalConnections() { |
1099 |
private void closeThreadLocalConnections() { |
1124 |
// Does not need to be synchronised, as all access is from same thread |
1100 |
// Does not need to be synchronised, as all access is from same thread |
1125 |
Map<HostConfiguration, HttpClient> map = httpClients.get(); |
1101 |
Map<HostConfiguration, HttpClient> map = httpClients.get(); |
1126 |
|
1102 |
|
1127 |
if ( map != null ) { |
1103 |
if (map != null) { |
1128 |
for (HttpClient cl : map.values()) |
1104 |
for (HttpClient cl : map.values()) |
1129 |
{ |
1105 |
{ |
1130 |
// Can cause NPE in HttpClient 3.1 |
1106 |
// Closes the connection. shutdown() can cause NPE |
1131 |
//((SimpleHttpConnectionManager)cl.getHttpConnectionManager()).shutdown();// Closes the connection |
1107 |
// in HttpClient 3.1, therefore using original method: |
1132 |
// Revert to original method: |
1108 |
cl.getHttpConnectionManager().closeIdleConnections(-1000); |
1133 |
cl.getHttpConnectionManager().closeIdleConnections(-1000);// Closes the connection |
|
|
1134 |
} |
1109 |
} |
1135 |
map.clear(); |
1110 |
map.clear(); |
1136 |
} |
1111 |
} |