use of org.apache.jmeter.protocol.http.util.HTTPArgument in project jmeter by apache.
the class UrlConfigGui method modifyTestElement.
/**
* Save the GUI values in the sampler.
*
* @param element {@link TestElement} to modify
*/
public void modifyTestElement(TestElement element) {
boolean useRaw = postContentTabbedPane.getSelectedIndex() == tabRawBodyIndex;
Arguments args;
if (useRaw) {
args = new Arguments();
String text = postBodyContent.getText();
/*
* Textfield uses \n (LF) to delimit lines; we need to send CRLF.
* Rather than change the way that arguments are processed by the
* samplers for raw data, it is easier to fix the data.
* On retrieval, CRLF is converted back to LF for storage in the text field.
* See
*/
HTTPArgument arg = new HTTPArgument("", text.replaceAll("\n", "\r\n"), false);
arg.setAlwaysEncoded(false);
args.addArgument(arg);
} else {
args = (Arguments) argsPanel.createTestElement();
HTTPArgument.convertArgumentsToHTTP(args);
if (showFileUploadPane) {
filesPanel.modifyTestElement(element);
}
}
element.setProperty(HTTPSamplerBase.POST_BODY_RAW, useRaw, HTTPSamplerBase.POST_BODY_RAW_DEFAULT);
element.setProperty(new TestElementProperty(HTTPSamplerBase.ARGUMENTS, args));
element.setProperty(HTTPSamplerBase.DOMAIN, domain.getText());
element.setProperty(HTTPSamplerBase.PORT, port.getText());
element.setProperty(HTTPSamplerBase.PROTOCOL, protocol.getText());
element.setProperty(HTTPSamplerBase.CONTENT_ENCODING, contentEncoding.getText());
element.setProperty(HTTPSamplerBase.PATH, path.getText());
if (notConfigOnly) {
element.setProperty(HTTPSamplerBase.METHOD, method.getText());
element.setProperty(new BooleanProperty(HTTPSamplerBase.FOLLOW_REDIRECTS, followRedirects.isSelected()));
element.setProperty(new BooleanProperty(HTTPSamplerBase.AUTO_REDIRECTS, autoRedirects.isSelected()));
element.setProperty(new BooleanProperty(HTTPSamplerBase.USE_KEEPALIVE, useKeepAlive.isSelected()));
element.setProperty(new BooleanProperty(HTTPSamplerBase.DO_MULTIPART_POST, useMultipartForPost.isSelected()));
element.setProperty(HTTPSamplerBase.BROWSER_COMPATIBLE_MULTIPART, useBrowserCompatibleMultipartMode.isSelected(), HTTPSamplerBase.BROWSER_COMPATIBLE_MULTIPART_MODE_DEFAULT);
}
}
use of org.apache.jmeter.protocol.http.util.HTTPArgument in project jmeter by apache.
the class MultipartUrlConfig method addArgument.
public void addArgument(String name, String value, String metadata) {
Arguments myArgs = this.getArguments();
myArgs.addArgument(new HTTPArgument(name, value, metadata));
}
use of org.apache.jmeter.protocol.http.util.HTTPArgument in project jmeter by apache.
the class MultipartUrlConfig method addNonEncodedArgument.
/**
* Add a value that is not URL encoded, and make sure it
* appears in the GUI that it will not be encoded when
* the request is sent.
*
* @param name
* @param value
*/
private void addNonEncodedArgument(String name, String value) {
Arguments myArgs = getArguments();
// The value is not encoded
HTTPArgument arg = new HTTPArgument(name, value, false);
// Let the GUI show that it will not be encoded
arg.setAlwaysEncoded(false);
myArgs.addArgument(arg);
}
use of org.apache.jmeter.protocol.http.util.HTTPArgument in project jmeter by apache.
the class TestHTTPSamplersAgainstHttpMirrorServer method testPostRequest_UrlEncoded.
private void testPostRequest_UrlEncoded(int samplerType, String samplerDefaultEncoding, int test) throws Exception {
String titleField = "title";
String titleValue = "mytitle";
String descriptionField = "description";
String descriptionValue = "mydescription";
HTTPSamplerBase sampler = createHttpSampler(samplerType);
HTTPSampleResult res;
String contentEncoding;
switch(test) {
case 0:
// Test sending data with default encoding
contentEncoding = "";
setupUrl(sampler, contentEncoding);
setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
res = executeSampler(sampler);
checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false);
break;
case 1:
// Test sending data as ISO-8859-1
contentEncoding = ISO_8859_1;
setupUrl(sampler, contentEncoding);
setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
res = executeSampler(sampler);
checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false);
break;
case 2:
// Test sending data as UTF-8
contentEncoding = "UTF-8";
titleValue = "mytitle2œ₡ĕÅ";
descriptionValue = "mydescription2œ₡ĕÅ";
setupUrl(sampler, contentEncoding);
setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
res = executeSampler(sampler);
checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false);
break;
case 3:
// Test sending data as UTF-8, with values that will change when urlencoded
contentEncoding = "UTF-8";
titleValue = "mytitle3/=";
descriptionValue = "mydescription3 /\\";
setupUrl(sampler, contentEncoding);
setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
res = executeSampler(sampler);
checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false);
break;
case 4:
// Test sending data as UTF-8, with values that have been urlencoded
contentEncoding = "UTF-8";
titleValue = "mytitle4%2F%3D";
descriptionValue = "mydescription4+++%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);
break;
case 5:
// Test sending data as UTF-8, with values similar to __VIEWSTATE parameter that .net uses
contentEncoding = "UTF-8";
titleValue = "/wEPDwULLTE2MzM2OTA0NTYPZBYCAgMPZ/rA+8DZ2dnZ2dnZ2d/GNDar6OshPwdJc=";
descriptionValue = "mydescription5";
setupUrl(sampler, contentEncoding);
setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
res = executeSampler(sampler);
checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false);
break;
case 6:
// 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
contentEncoding = "UTF-8";
titleValue = "%2FwEPDwULLTE2MzM2OTA0NTYPZBYCAgMPZ%2FrA%2B8DZ2dnZ2dnZ2d%2FGNDar6OshPwdJc%3D";
descriptionValue = "mydescription6";
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);
break;
case 7:
// 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Å");
vars.put("description_suffix", "the_end");
JMeterContextService.getContext().setVariables(vars);
JMeterContextService.getContext().setSamplingStarted(true);
ValueReplacer replacer = new ValueReplacer();
replacer.setUserDefinedVariables(testPlan.getUserDefinedVariables());
contentEncoding = "UTF-8";
titleValue = "${title_prefix}mytitle7œ₡ĕÅ";
descriptionValue = "mydescription7œ₡ĕÅ${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Åmytitle7œ₡ĕÅ";
String expectedDescriptionValue = "mydescription7œ₡ĕÅthe_end";
checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, expectedTitleValue, descriptionField, expectedDescriptionValue, false);
break;
case 8:
break;
case 9:
break;
case 10:
break;
default:
fail("Unexpected switch value: " + test);
}
}
use of org.apache.jmeter.protocol.http.util.HTTPArgument in project jmeter by apache.
the class TestHTTPSamplersAgainstHttpMirrorServer method testPostRequest_BodyFromParameterValues.
private void testPostRequest_BodyFromParameterValues(int samplerType, String samplerDefaultEncoding) throws Exception {
// ensure only values are used
final String titleField = "";
String titleValue = "mytitle";
// ensure only values are used
final 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);
((HTTPArgument) sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
((HTTPArgument) sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
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);
((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
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, 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);
((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, with values that will change when urlencoded, and where
// we tell the sampler to urlencode the parameter value
sampler = createHttpSampler(samplerType);
contentEncoding = "UTF-8";
titleValue = "mytitle/=";
descriptionValue = "mydescription /\\";
setupUrl(sampler, contentEncoding);
setupFormData(sampler, true, titleField, titleValue, descriptionField, descriptionValue);
res = executeSampler(sampler);
expectedPostBody = URLEncoder.encode(titleValue + descriptionValue, contentEncoding);
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, 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, with values that have been urlencoded, and
// where we tell the sampler to urlencode the parameter values
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 = titleValue + descriptionValue;
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);
((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, 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 HTTPConstants.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Å");
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œ₡ĕÅ";
descriptionValue = "mydescriptionœ₡ĕÅ${description_suffix}";
setupUrl(sampler, contentEncoding);
setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
((HTTPArgument) sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
((HTTPArgument) sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
// Replace the variables in the sampler
replacer.replaceValues(sampler);
res = executeSampler(sampler);
String expectedTitleValue = "a testÅmytitleœ₡ĕÅ";
String expectedDescriptionValue = "mydescriptionœ₡ĕÅthe_end";
expectedPostBody = expectedTitleValue + expectedDescriptionValue;
checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
}
Aggregations