ASF Bugzilla – Attachment 19987 Details for
Bug 42156
HTTPRequest HTTPClient incorrectly urlencodes parameter value in POST
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Updated suggested patch
patch_for_42156.patch (text/plain), 38.22 KB, created by
Alf Hogemark
on 2007-04-18 04:12:59 UTC
(
hide
)
Description:
Updated suggested patch
Filename:
MIME Type:
Creator:
Alf Hogemark
Created:
2007-04-18 04:12:59 UTC
Size:
38.22 KB
patch
obsolete
>Index: C:/Documents and Settings/alf.hogemark/workspace/JMeter 2.2 official_2/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java >=================================================================== >--- C:/Documents and Settings/alf.hogemark/workspace/JMeter 2.2 official_2/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java (revision 529493) >+++ C:/Documents and Settings/alf.hogemark/workspace/JMeter 2.2 official_2/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java (working copy) >@@ -24,11 +24,11 @@ > import java.io.IOException; > import java.io.OutputStream; > import java.io.UnsupportedEncodingException; >+import java.net.URLDecoder; > import java.net.URLEncoder; > import java.net.URL; > import java.util.Locale; > >-import org.apache.jmeter.config.Arguments; > import org.apache.jmeter.engine.util.ValueReplacer; > import org.apache.jmeter.protocol.http.control.HttpMirrorControl; > import org.apache.jmeter.protocol.http.util.EncoderCache; >@@ -121,6 +121,16 @@ > testPostRequest_FileUpload(HTTP_SAMPLER2, samplerDefaultEncoding); > } > >+ public void testPostRequest_BodyFromParameterValues() throws Exception { >+ // Test HTTPSampler >+ String samplerDefaultEncoding = "ISO-8859-1"; >+ testPostRequest_BodyFromParameterValues(HTTP_SAMPLER, samplerDefaultEncoding); >+ >+ // Test HTTPSampler2 >+ samplerDefaultEncoding = "US-ASCII"; >+ testPostRequest_BodyFromParameterValues(HTTP_SAMPLER2, samplerDefaultEncoding); >+ } >+ > public void testGetRequest() throws Exception { > // Test HTTPSampler > testGetRequest(HTTP_SAMPLER); >@@ -149,7 +159,7 @@ > setupUrl(sampler, contentEncoding); > setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue); > HTTPSampleResult res = executeSampler(sampler); >- checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue); >+ checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false); > > // Test sending data as ISO-8859-1 > sampler = createHttpSampler(samplerType); >@@ -157,7 +167,7 @@ > setupUrl(sampler, contentEncoding); > setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue); > res = executeSampler(sampler); >- checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue); >+ checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false); > > // Test sending data as UTF-8 > sampler = createHttpSampler(samplerType); >@@ -167,8 +177,54 @@ > setupUrl(sampler, contentEncoding); > setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue); > res = executeSampler(sampler); >- checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue); >+ checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false); > >+ // Test sending data as UTF-8, with values that will change when urlencoded >+ sampler = createHttpSampler(samplerType); >+ contentEncoding = "UTF-8"; >+ titleValue = "mytitle/="; >+ descriptionValue = "mydescription /\\"; >+ setupUrl(sampler, contentEncoding); >+ setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue); >+ res = executeSampler(sampler); >+ checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false); >+ >+ // Test sending data as UTF-8, with values that have been urlencoded >+ sampler = createHttpSampler(samplerType); >+ contentEncoding = "UTF-8"; >+ titleValue = "mytitle%2F%3D"; >+ descriptionValue = "mydescription+++%2F%5C"; >+ setupUrl(sampler, contentEncoding); >+ setupFormData(sampler, true, titleField, titleValue, descriptionField, descriptionValue); >+ res = executeSampler(sampler); >+ checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, true); >+ >+ // Test sending data as UTF-8, with values similar to __VIEWSTATE parameter that .net uses >+ sampler = createHttpSampler(samplerType); >+ contentEncoding = "UTF-8"; >+ titleValue = "/wEPDwULLTE2MzM2OTA0NTYPZBYCAgMPZ/rA+8DZ2dnZ2dnZ2d/GNDar6OshPwdJc="; >+ descriptionValue = "mydescription"; >+ setupUrl(sampler, contentEncoding); >+ setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue); >+ res = executeSampler(sampler); >+ checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false); >+ >+ // Test sending data as UTF-8, with values similar to __VIEWSTATE parameter that .net uses, >+ // with values urlencoded, but the always encode set to false for the arguments >+ // This is how the HTTP Proxy server adds arguments to the sampler >+ sampler = createHttpSampler(samplerType); >+ contentEncoding = "UTF-8"; >+ titleValue = "%2FwEPDwULLTE2MzM2OTA0NTYPZBYCAgMPZ%2FrA%2B8DZ2dnZ2dnZ2d%2FGNDar6OshPwdJc%3D"; >+ descriptionValue = "mydescription"; >+ setupUrl(sampler, contentEncoding); >+ setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue); >+ ((HTTPArgument)sampler.getArguments().getArgument(0)).setAlwaysEncoded(false); >+ ((HTTPArgument)sampler.getArguments().getArgument(1)).setAlwaysEncoded(false); >+ res = executeSampler(sampler); >+ assertFalse(((HTTPArgument)sampler.getArguments().getArgument(0)).isAlwaysEncoded()); >+ assertFalse(((HTTPArgument)sampler.getArguments().getArgument(1)).isAlwaysEncoded()); >+ checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, true); >+ > // Test sending data as UTF-8, where user defined variables are used > // to set the value for form data > JMeterUtils.setLocale(Locale.ENGLISH); >@@ -192,7 +248,7 @@ > res = executeSampler(sampler); > String expectedTitleValue = "a test\u00c5mytitle\u0153\u20a1\u0115\u00c5"; > String expectedDescriptionValue = "mydescription\u0153\u20a1\u0115\u00c5the_end"; >- checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, expectedTitleValue, descriptionField, expectedDescriptionValue); >+ checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, expectedTitleValue, descriptionField, expectedDescriptionValue, false); > } > > private void testPostRequest_FormMultipart(int samplerType, String samplerDefaultEncoding) throws Exception { >@@ -234,14 +290,38 @@ > // if it was not sent as multipart > sampler = createHttpSampler(samplerType); > contentEncoding = "UTF-8"; >- titleValue = "mytitle\u0153+\u20a1 \u0115&yes\u00c5"; >- descriptionValue = "mydescription \u0153 \u20a1 \u0115 \u00c5"; >+ titleValue = "mytitle/="; >+ descriptionValue = "mydescription /\\"; > setupUrl(sampler, contentEncoding); > setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue); > sampler.setDoMultipartPost(true); > res = executeSampler(sampler); > checkPostRequestFormMultipart(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue); > >+ // Test sending data as UTF-8, with values that have been urlencoded >+ sampler = createHttpSampler(samplerType); >+ contentEncoding = "UTF-8"; >+ titleValue = "mytitle%2F%3D"; >+ descriptionValue = "mydescription+++%2F%5C"; >+ setupUrl(sampler, contentEncoding); >+ setupFormData(sampler, true, titleField, titleValue, descriptionField, descriptionValue); >+ sampler.setDoMultipartPost(true); >+ res = executeSampler(sampler); >+ String expectedTitleValue = "mytitle/="; >+ String expectedDescriptionValue = "mydescription /\\"; >+ checkPostRequestFormMultipart(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, expectedTitleValue, descriptionField, expectedDescriptionValue); >+ >+ // Test sending data as UTF-8, with values similar to __VIEWSTATE parameter that .net uses >+ sampler = createHttpSampler(samplerType); >+ contentEncoding = "UTF-8"; >+ titleValue = "/wEPDwULLTE2MzM2OTA0NTYPZBYCAgMPZ/rA+8DZ2dnZ2dnZ2d/GNDar6OshPwdJc="; >+ descriptionValue = "mydescription"; >+ setupUrl(sampler, contentEncoding); >+ setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue); >+ sampler.setDoMultipartPost(true); >+ res = executeSampler(sampler); >+ checkPostRequestFormMultipart(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue); >+ > // Test sending data as UTF-8, where user defined variables are used > // to set the value for form data > JMeterUtils.setLocale(Locale.ENGLISH); >@@ -264,8 +344,8 @@ > // Replace the variables in the sampler > replacer.replaceValues(sampler); > res = executeSampler(sampler); >- String expectedTitleValue = "a test\u00c5mytitle\u0153\u20a1\u0115\u00c5"; >- String expectedDescriptionValue = "mydescription\u0153\u20a1\u0115\u00c5the_end"; >+ expectedTitleValue = "a test\u00c5mytitle\u0153\u20a1\u0115\u00c5"; >+ expectedDescriptionValue = "mydescription\u0153\u20a1\u0115\u00c5the_end"; > checkPostRequestFormMultipart(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, expectedTitleValue, descriptionField, expectedDescriptionValue); > } > >@@ -303,7 +383,119 @@ > res = executeSampler(sampler); > checkPostRequestFileUpload(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, fileField, temporaryFile, fileMimeType, TEST_FILE_CONTENT); > } >- >+ >+ private void testPostRequest_BodyFromParameterValues(int samplerType, String samplerDefaultEncoding) throws Exception { >+ String titleField = ""; >+ String titleValue = "mytitle"; >+ String descriptionField = ""; >+ String descriptionValue = "mydescription"; >+ >+ // Test sending data with default encoding >+ HTTPSamplerBase sampler = createHttpSampler(samplerType); >+ String contentEncoding = ""; >+ setupUrl(sampler, contentEncoding); >+ setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue); >+ HTTPSampleResult res = executeSampler(sampler); >+ String expectedPostBody = titleValue + descriptionValue; >+ checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody); >+ >+ // Test sending data as ISO-8859-1 >+ sampler = createHttpSampler(samplerType); >+ contentEncoding = "ISO-8859-1"; >+ setupUrl(sampler, contentEncoding); >+ setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue); >+ res = executeSampler(sampler); >+ expectedPostBody = titleValue + descriptionValue; >+ checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody); >+ >+ // Test sending data as UTF-8 >+ sampler = createHttpSampler(samplerType); >+ contentEncoding = "UTF-8"; >+ titleValue = "mytitle\u0153\u20a1\u0115\u00c5"; >+ descriptionValue = "mydescription\u0153\u20a1\u0115\u00c5"; >+ setupUrl(sampler, contentEncoding); >+ setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue); >+ res = executeSampler(sampler); >+ expectedPostBody = titleValue + descriptionValue; >+ checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody); >+ >+ // Test sending data as UTF-8, with values that will change when urlencoded >+ sampler = createHttpSampler(samplerType); >+ contentEncoding = "UTF-8"; >+ titleValue = "mytitle/="; >+ descriptionValue = "mydescription /\\"; >+ setupUrl(sampler, contentEncoding); >+ setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue); >+ res = executeSampler(sampler); >+ expectedPostBody = titleValue + descriptionValue; >+ checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody); >+ >+ // Test sending data as UTF-8, with values that have been urlencoded >+ sampler = createHttpSampler(samplerType); >+ contentEncoding = "UTF-8"; >+ titleValue = "mytitle%2F%3D"; >+ descriptionValue = "mydescription+++%2F%5C"; >+ setupUrl(sampler, contentEncoding); >+ setupFormData(sampler, true, titleField, titleValue, descriptionField, descriptionValue); >+ res = executeSampler(sampler); >+ expectedPostBody = URLDecoder.decode(titleValue, contentEncoding) + URLDecoder.decode(descriptionValue, contentEncoding); >+ checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody); >+ >+ // Test sending data as UTF-8, with values similar to __VIEWSTATE parameter that .net uses >+ sampler = createHttpSampler(samplerType); >+ contentEncoding = "UTF-8"; >+ titleValue = "/wEPDwULLTE2MzM2OTA0NTYPZBYCAgMPZ/rA+8DZ2dnZ2dnZ2d/GNDar6OshPwdJc="; >+ descriptionValue = "mydescription"; >+ setupUrl(sampler, contentEncoding); >+ setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue); >+ res = executeSampler(sampler); >+ expectedPostBody = titleValue + descriptionValue; >+ checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody); >+ >+ // Test sending data as UTF-8, with + as part of the value, >+ // where the value is set in sampler as not urluencoded, but the >+ // isalwaysencoded flag of the argument is set to false. >+ // This mimics the HTTPSamplerBase.addNonEncodedArgument, which the >+ // Proxy server calls in some cases >+ sampler = createHttpSampler(samplerType); >+ contentEncoding = "UTF-8"; >+ titleValue = "mytitle++"; >+ descriptionValue = "mydescription+"; >+ setupUrl(sampler, contentEncoding); >+ setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue); >+ ((HTTPArgument)sampler.getArguments().getArgument(0)).setAlwaysEncoded(false); >+ ((HTTPArgument)sampler.getArguments().getArgument(1)).setAlwaysEncoded(false); >+ res = executeSampler(sampler); >+ expectedPostBody = titleValue + descriptionValue; >+ checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody); >+ >+ // Test sending data as UTF-8, where user defined variables are used >+ // to set the value for form data >+ JMeterUtils.setLocale(Locale.ENGLISH); >+ TestPlan testPlan = new TestPlan(); >+ JMeterVariables vars = new JMeterVariables(); >+ vars.put("title_prefix", "a test\u00c5"); >+ vars.put("description_suffix", "the_end"); >+ JMeterContextService.getContext().setVariables(vars); >+ JMeterContextService.getContext().setSamplingStarted(true); >+ ValueReplacer replacer = new ValueReplacer(); >+ replacer.setUserDefinedVariables(testPlan.getUserDefinedVariables()); >+ >+ sampler = createHttpSampler(samplerType); >+ contentEncoding = "UTF-8"; >+ titleValue = "${title_prefix}mytitle\u0153\u20a1\u0115\u00c5"; >+ descriptionValue = "mydescription\u0153\u20a1\u0115\u00c5${description_suffix}"; >+ setupUrl(sampler, contentEncoding); >+ setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue); >+ // Replace the variables in the sampler >+ replacer.replaceValues(sampler); >+ res = executeSampler(sampler); >+ String expectedTitleValue = "a test\u00c5mytitle\u0153\u20a1\u0115\u00c5"; >+ String expectedDescriptionValue = "mydescription\u0153\u20a1\u0115\u00c5the_end"; >+ expectedPostBody = expectedTitleValue+ expectedDescriptionValue; >+ checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody); >+ } >+ > private void testGetRequest(int samplerType) throws Exception { > // Test sending simple HTTP get > // Test sending data with default encoding >@@ -348,7 +540,7 @@ > sampler.setRunningVersion(true); > URL executedUrl = sampler.getUrl(); > sampler.setRunningVersion(false); >- checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, titleField, titleValue, descriptionField, descriptionValue); >+ checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, titleField, titleValue, descriptionField, descriptionValue, false); > > // Test sending data with ISO-8859-1 encoding > sampler = createHttpSampler(samplerType); >@@ -362,7 +554,7 @@ > sampler.setRunningVersion(true); > executedUrl = sampler.getUrl(); > sampler.setRunningVersion(false); >- checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, titleField, titleValue, descriptionField, descriptionValue); >+ checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, titleField, titleValue, descriptionField, descriptionValue, false); > > // Test sending data with UTF-8 encoding > sampler = createHttpSampler(samplerType); >@@ -376,7 +568,7 @@ > sampler.setRunningVersion(true); > executedUrl = sampler.getUrl(); > sampler.setRunningVersion(false); >- checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, titleField, titleValue, descriptionField, descriptionValue); >+ checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, titleField, titleValue, descriptionField, descriptionValue, false); > > // Test sending data as UTF-8, with values that changes when urlencoded > sampler = createHttpSampler(samplerType); >@@ -390,8 +582,24 @@ > sampler.setRunningVersion(true); > executedUrl = sampler.getUrl(); > sampler.setRunningVersion(false); >- checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, titleField, titleValue, descriptionField, descriptionValue); >+ String expectedTitleValue = "mytitle\u0153%2B\u20a1+\u0115%26yes\u00c5"; >+ String expectedDescriptionValue = "mydescription+\u0153+\u20a1+\u0115+\u00c5"; >+ checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, titleField, titleValue, descriptionField, descriptionValue, false); > >+ // Test sending data as UTF-8, with values that have been urlencoded >+ sampler = createHttpSampler(samplerType); >+ contentEncoding = "UTF-8"; >+ titleValue = "mytitle%2F%3D"; >+ descriptionValue = "mydescription+++%2F%5C"; >+ setupUrl(sampler, contentEncoding); >+ sampler.setMethod(HTTPSamplerBase.GET); >+ setupFormData(sampler, true, titleField, titleValue, descriptionField, descriptionValue); >+ res = executeSampler(sampler); >+ sampler.setRunningVersion(true); >+ executedUrl = sampler.getUrl(); >+ sampler.setRunningVersion(false); >+ checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, titleField, titleValue, descriptionField, descriptionValue, true); >+ > // Test sending data as UTF-8, where user defined variables are used > // to set the value for form data > JMeterUtils.setLocale(Locale.ENGLISH); >@@ -414,12 +622,12 @@ > // Replace the variables in the sampler > replacer.replaceValues(sampler); > res = executeSampler(sampler); >- String expectedTitleValue = "a test\u00c5mytitle\u0153\u20a1\u0115\u00c5"; >- String expectedDescriptionValue = "mydescription\u0153\u20a1\u0115\u00c5the_end"; >+ expectedTitleValue = "a test\u00c5mytitle\u0153\u20a1\u0115\u00c5"; >+ expectedDescriptionValue = "mydescription\u0153\u20a1\u0115\u00c5the_end"; > sampler.setRunningVersion(true); > executedUrl = sampler.getUrl(); > sampler.setRunningVersion(false); >- checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, titleField, expectedTitleValue, descriptionField, expectedDescriptionValue); >+ checkGetRequest_Parameters(sampler, res, contentEncoding, executedUrl, titleField, expectedTitleValue, descriptionField, expectedDescriptionValue, false); > } > > private HTTPSampleResult executeSampler(HTTPSamplerBase sampler) { >@@ -439,24 +647,60 @@ > String titleField, > String titleValue, > String descriptionField, >+ String descriptionValue, >+ boolean valuesAlreadyUrlEncoded) throws IOException { >+ if(contentEncoding == null || contentEncoding.length() == 0) { >+ contentEncoding = samplerDefaultEncoding; >+ } >+ // Check URL >+ assertEquals(sampler.getUrl(), res.getURL()); >+ String expectedPostBody = null; >+ if(!valuesAlreadyUrlEncoded) { >+ String expectedTitle = URLEncoder.encode(titleValue, contentEncoding); >+ String expectedDescription = URLEncoder.encode(descriptionValue, contentEncoding); >+ expectedPostBody = titleField + "=" + expectedTitle + "&" + descriptionField + "=" + expectedDescription; >+ } >+ else { >+ expectedPostBody = titleField + "=" + titleValue + "&" + descriptionField + "=" + descriptionValue; >+ } >+ // Check the request >+ checkPostRequestBody( >+ sampler, >+ res, >+ samplerDefaultEncoding, >+ contentEncoding, >+ expectedPostBody >+ ); >+ } >+ >+ private void checkPostRequestFormMultipart( >+ HTTPSamplerBase sampler, >+ HTTPSampleResult res, >+ String samplerDefaultEncoding, >+ String contentEncoding, >+ String titleField, >+ String titleValue, >+ String descriptionField, > String descriptionValue) throws IOException { > if(contentEncoding == null || contentEncoding.length() == 0) { > contentEncoding = samplerDefaultEncoding; > } > // Check URL > assertEquals(sampler.getUrl(), res.getURL()); >- String expectedPostBody = titleField + "=" + URLEncoder.encode(titleValue, contentEncoding) + "&" + descriptionField + "=" + URLEncoder.encode(descriptionValue, contentEncoding); >+ String boundaryString = getBoundaryStringFromContentType(res.getRequestHeaders()); >+ assertNotNull(boundaryString); >+ byte[] expectedPostBody = createExpectedFormdataOutput(boundaryString, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, true, true); > // Check request headers >- assertTrue(isInRequestHeaders(res.getRequestHeaders(), HTTPSamplerBase.HEADER_CONTENT_TYPE, HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED)); >+ assertTrue(isInRequestHeaders(res.getRequestHeaders(), HTTPSamplerBase.HEADER_CONTENT_TYPE, "multipart/form-data" + "; boundary=" + boundaryString)); > assertTrue( > isInRequestHeaders( > res.getRequestHeaders(), > HTTPSamplerBase.HEADER_CONTENT_LENGTH, >- Integer.toString(expectedPostBody.getBytes(contentEncoding).length) >+ Integer.toString(expectedPostBody.length) > ) > ); > // Check post body from the result query string >- checkArraysHaveSameContent(expectedPostBody.getBytes(contentEncoding), res.getQueryString().getBytes(contentEncoding)); >+ checkArraysHaveSameContent(expectedPostBody, res.getQueryString().getBytes(contentEncoding)); > > // Find the data sent to the mirror server, which the mirror server is sending back to us > String dataSentToMirrorServer = new String(res.getResponseData(), contentEncoding); >@@ -472,22 +716,22 @@ > fail("No header and body section found"); > } > // Check response headers >- assertTrue(isInRequestHeaders(headersSent, HTTPSamplerBase.HEADER_CONTENT_TYPE, HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED)); >+ assertTrue(isInRequestHeaders(headersSent, HTTPSamplerBase.HEADER_CONTENT_TYPE, "multipart/form-data" + "; boundary=" + boundaryString)); > assertTrue( > isInRequestHeaders( > headersSent, > HTTPSamplerBase.HEADER_CONTENT_LENGTH, >- Integer.toString(expectedPostBody.getBytes(contentEncoding).length) >+ Integer.toString(expectedPostBody.length) > ) > ); > // Check post body which was sent to the mirror server, and > // sent back by the mirror server >- checkArraysHaveSameContent(expectedPostBody.getBytes(contentEncoding), bodySent.getBytes(contentEncoding)); >+ checkArraysHaveSameContent(expectedPostBody, bodySent.getBytes(contentEncoding)); > // Check method, path and query sent > checkMethodPathQuery(headersSent, sampler.getMethod(), sampler.getPath(), null); > } >- >- private void checkPostRequestFormMultipart( >+ >+ private void checkPostRequestFileUpload( > HTTPSamplerBase sampler, > HTTPSampleResult res, > String samplerDefaultEncoding, >@@ -495,7 +739,11 @@ > String titleField, > String titleValue, > String descriptionField, >- String descriptionValue) throws IOException { >+ String descriptionValue, >+ String fileField, >+ File fileValue, >+ String fileMimeType, >+ byte[] fileContent) throws IOException { > if(contentEncoding == null || contentEncoding.length() == 0) { > contentEncoding = samplerDefaultEncoding; > } >@@ -503,7 +751,7 @@ > assertEquals(sampler.getUrl(), res.getURL()); > String boundaryString = getBoundaryStringFromContentType(res.getRequestHeaders()); > assertNotNull(boundaryString); >- byte[] expectedPostBody = createExpectedFormdataOutput(boundaryString, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, true, true); >+ byte[] expectedPostBody = createExpectedFormAndUploadOutput(boundaryString, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, fileField, fileValue, fileMimeType, fileContent); > // Check request headers > assertTrue(isInRequestHeaders(res.getRequestHeaders(), HTTPSamplerBase.HEADER_CONTENT_TYPE, "multipart/form-data" + "; boundary=" + boundaryString)); > assertTrue( >@@ -513,8 +761,9 @@ > Integer.toString(expectedPostBody.length) > ) > ); >- // Check post body from the result query string >- checkArraysHaveSameContent(expectedPostBody, res.getQueryString().getBytes(contentEncoding)); >+ // We cannot check post body from the result query string, since that will not contain >+ // the actual file content, but placeholder text for file content >+ //checkArraysHaveSameContent(expectedPostBody, res.getQueryString().getBytes(contentEncoding)); > > // Find the data sent to the mirror server, which the mirror server is sending back to us > String dataSentToMirrorServer = new String(res.getResponseData(), contentEncoding); >@@ -540,44 +789,35 @@ > ); > // Check post body which was sent to the mirror server, and > // sent back by the mirror server >- checkArraysHaveSameContent(expectedPostBody, bodySent.getBytes(contentEncoding)); >+ // We cannot check this merely by getting the body in the contentEncoding, >+ // since the actual file content is sent binary, without being encoded >+ //checkArraysHaveSameContent(expectedPostBody, bodySent.getBytes(contentEncoding)); > // Check method, path and query sent > checkMethodPathQuery(headersSent, sampler.getMethod(), sampler.getPath(), null); > } >- >- private void checkPostRequestFileUpload( >+ >+ private void checkPostRequestBody( > HTTPSamplerBase sampler, > HTTPSampleResult res, > String samplerDefaultEncoding, > String contentEncoding, >- String titleField, >- String titleValue, >- String descriptionField, >- String descriptionValue, >- String fileField, >- File fileValue, >- String fileMimeType, >- byte[] fileContent) throws IOException { >+ String expectedPostBody) throws IOException { > if(contentEncoding == null || contentEncoding.length() == 0) { > contentEncoding = samplerDefaultEncoding; > } > // Check URL > assertEquals(sampler.getUrl(), res.getURL()); >- String boundaryString = getBoundaryStringFromContentType(res.getRequestHeaders()); >- assertNotNull(boundaryString); >- byte[] expectedPostBody = createExpectedFormAndUploadOutput(boundaryString, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, fileField, fileValue, fileMimeType, fileContent); > // Check request headers >- assertTrue(isInRequestHeaders(res.getRequestHeaders(), HTTPSamplerBase.HEADER_CONTENT_TYPE, "multipart/form-data" + "; boundary=" + boundaryString)); >+ assertTrue(isInRequestHeaders(res.getRequestHeaders(), HTTPSamplerBase.HEADER_CONTENT_TYPE, HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED)); > assertTrue( > isInRequestHeaders( > res.getRequestHeaders(), > HTTPSamplerBase.HEADER_CONTENT_LENGTH, >- Integer.toString(expectedPostBody.length) >+ Integer.toString(expectedPostBody.getBytes(contentEncoding).length) > ) > ); >- // We cannot check post body from the result query string, since that will not contain >- // the actual file content, but placeholder text for file content >- //checkArraysHaveSameContent(expectedPostBody, res.getQueryString().getBytes(contentEncoding)); >+ // Check post body from the result query string >+ checkArraysHaveSameContent(expectedPostBody.getBytes(contentEncoding), res.getQueryString().getBytes(contentEncoding)); > > // Find the data sent to the mirror server, which the mirror server is sending back to us > String dataSentToMirrorServer = new String(res.getResponseData(), contentEncoding); >@@ -593,19 +833,17 @@ > fail("No header and body section found"); > } > // Check response headers >- assertTrue(isInRequestHeaders(headersSent, HTTPSamplerBase.HEADER_CONTENT_TYPE, "multipart/form-data" + "; boundary=" + boundaryString)); >+ assertTrue(isInRequestHeaders(headersSent, HTTPSamplerBase.HEADER_CONTENT_TYPE, HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED)); > assertTrue( > isInRequestHeaders( > headersSent, > HTTPSamplerBase.HEADER_CONTENT_LENGTH, >- Integer.toString(expectedPostBody.length) >+ Integer.toString(expectedPostBody.getBytes(contentEncoding).length) > ) > ); > // Check post body which was sent to the mirror server, and > // sent back by the mirror server >- // We cannot check this merely by getting the body in the contentEncoding, >- // since the actual file content is sent binary, without being encoded >- //checkArraysHaveSameContent(expectedPostBody, bodySent.getBytes(contentEncoding)); >+ checkArraysHaveSameContent(expectedPostBody.getBytes(contentEncoding), bodySent.getBytes(contentEncoding)); > // Check method, path and query sent > checkMethodPathQuery(headersSent, sampler.getMethod(), sampler.getPath(), null); > } >@@ -648,7 +886,8 @@ > String titleField, > String titleValue, > String descriptionField, >- String descriptionValue) throws IOException { >+ String descriptionValue, >+ boolean valuesAlreadyUrlEncoded) throws IOException { > if(contentEncoding == null || contentEncoding.length() == 0) { > contentEncoding = EncoderCache.URL_ARGUMENT_ENCODING; > } >@@ -658,7 +897,16 @@ > assertEquals(sampler.getMethod(), res.getHTTPMethod()); > // Cannot check the query string of the result, because the mirror server > // replies without including query string in URL >- String expectedQueryString = titleField + "=" + URLEncoder.encode(titleValue, contentEncoding) + "&" + descriptionField + "=" + URLEncoder.encode(descriptionValue, contentEncoding); >+ >+ String expectedQueryString = null; >+ if(!valuesAlreadyUrlEncoded) { >+ String expectedTitle = URLEncoder.encode(titleValue, contentEncoding); >+ String expectedDescription = URLEncoder.encode(descriptionValue, contentEncoding); >+ expectedQueryString = titleField + "=" + expectedTitle + "&" + descriptionField + "=" + expectedDescription; >+ } >+ else { >+ expectedQueryString = titleField + "=" + titleValue + "&" + descriptionField + "=" + descriptionValue; >+ } > > // Find the data sent to the mirror server, which the mirror server is sending back to us > String dataSentToMirrorServer = new String(res.getResponseData(), EncoderCache.URL_ARGUMENT_ENCODING); >@@ -782,12 +1030,14 @@ > * @param httpSampler > */ > private void setupFormData(HTTPSamplerBase httpSampler, boolean isEncoded, String titleField, String titleValue, String descriptionField, String descriptionValue) { >- Arguments args = new Arguments(); >- HTTPArgument argument1 = new HTTPArgument(titleField, titleValue, isEncoded); >- HTTPArgument argument2 = new HTTPArgument(descriptionField, descriptionValue, isEncoded); >- args.addArgument(argument1); >- args.addArgument(argument2); >- httpSampler.setArguments(args); >+ if(isEncoded) { >+ httpSampler.addEncodedArgument(titleField, titleValue); >+ httpSampler.addEncodedArgument(descriptionField, descriptionValue); >+ } >+ else { >+ httpSampler.addArgument(titleField, titleValue); >+ httpSampler.addArgument(descriptionField, descriptionValue); >+ } > } > > /** >Index: C:/Documents and Settings/alf.hogemark/workspace/JMeter 2.2 official_2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java >=================================================================== >--- C:/Documents and Settings/alf.hogemark/workspace/JMeter 2.2 official_2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java (revision 529493) >+++ C:/Documents and Settings/alf.hogemark/workspace/JMeter 2.2 official_2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java (working copy) >@@ -361,8 +361,41 @@ > PropertyIterator args = getArguments().iterator(); > while (args.hasNext()) { > HTTPArgument arg = (HTTPArgument) args.next().getObjectValue(); >- post.addParameter(arg.getName(), arg.getValue()); >+ // The HTTPClient always urlencodes both name and value, >+ // so if the argument is already encoded, we have to decode >+ // it before adding it to the post request >+ String parameterName = arg.getName(); >+ String parameterValue = arg.getValue(); >+ if(!arg.isAlwaysEncoded()) { >+ // The value is already encoded by the user >+ // Must decode the value now, so that when the >+ // httpclient encodes it, we end up with the same value >+ // as the user had entered. >+ String urlContentEncoding = contentEncoding; >+ if(urlContentEncoding == null || urlContentEncoding.length() == 0) { >+ // Use the default encoding for urls >+ urlContentEncoding = EncoderCache.URL_ARGUMENT_ENCODING; >+ } >+ parameterName = URLDecoder.decode(parameterName, urlContentEncoding); >+ parameterValue = URLDecoder.decode(parameterValue, urlContentEncoding); >+ } >+ // Add the parameter, httpclient will urlencode it >+ post.addParameter(parameterName, parameterValue); > } >+ >+/* >+ // Alternative implementation, to make sure that HTTPSampler and HTTPSampler2 >+ // sends the same post body. >+ >+ // Only include the content char set in the content-type header if it is not >+ // an APPLICATION_X_WWW_FORM_URLENCODED content type >+ String contentCharSet = null; >+ if(!post.getRequestHeader(HEADER_CONTENT_TYPE).getValue().equals(APPLICATION_X_WWW_FORM_URLENCODED)) { >+ contentCharSet = post.getRequestCharSet(); >+ } >+ StringRequestEntity requestEntity = new StringRequestEntity(getQueryString(contentEncoding), post.getRequestHeader(HEADER_CONTENT_TYPE).getValue(), contentCharSet); >+ post.setRequestEntity(requestEntity); >+*/ > } > else { > // Just append all the parameter values, and use that as the post body
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 42156
:
19986
| 19987