use of org.apache.jmeter.protocol.http.util.HTTPArgument in project jmeter by apache.
the class HTTPSamplerBase method addNonEncodedArgument.
public void addNonEncodedArgument(String name, String value, String metadata) {
HTTPArgument arg = new HTTPArgument(name, value, metadata, false);
arg.setAlwaysEncoded(false);
this.getArguments().addArgument(arg);
}
use of org.apache.jmeter.protocol.http.util.HTTPArgument in project jmeter by apache.
the class HTTPSamplerBase method getQueryString.
/**
* Gets the QueryString attribute of the UrlConfig object, using the
* specified encoding to encode the parameter values put into the URL
*
* @param contentEncoding the encoding to use for encoding parameter values
* @return the QueryString value
*/
public String getQueryString(final String contentEncoding) {
CollectionProperty arguments = getArguments().getArguments();
// Optimisation : avoid building useless objects if empty arguments
if (arguments.size() == 0) {
return "";
}
String lContentEncoding = contentEncoding;
// Check if the sampler has a specified content encoding
if (JOrphanUtils.isBlank(lContentEncoding)) {
// We use the encoding which should be used according to the HTTP spec, which is UTF-8
lContentEncoding = EncoderCache.URL_ARGUMENT_ENCODING;
}
StringBuilder buf = new StringBuilder(arguments.size() * 15);
PropertyIterator iter = arguments.iterator();
boolean first = true;
while (iter.hasNext()) {
HTTPArgument item = null;
/*
* N.B. Revision 323346 introduced the ClassCast check, but then used iter.next()
* to fetch the item to be cast, thus skipping the element that did not cast.
* Reverted to work more like the original code, but with the check in place.
* Added a warning message so can track whether it is necessary
*/
Object objectValue = iter.next().getObjectValue();
try {
item = (HTTPArgument) objectValue;
} catch (ClassCastException e) {
// NOSONAR
log.warn("Unexpected argument type: " + objectValue.getClass().getName() + " cannot be cast to HTTPArgument");
item = new HTTPArgument((Argument) objectValue);
}
final String encodedName = item.getEncodedName();
if (encodedName.length() == 0) {
// Skip parameters with a blank name (allows use of optional variables in parameter lists)
continue;
}
if (!first) {
buf.append(QRY_SEP);
} else {
first = false;
}
buf.append(encodedName);
if (item.getMetaData() == null) {
buf.append(ARG_VAL_SEP);
} else {
buf.append(item.getMetaData());
}
// Encode the parameter value in the specified content encoding
try {
buf.append(item.getEncodedValue(lContentEncoding));
} catch (UnsupportedEncodingException e) {
// NOSONAR
log.warn("Unable to encode parameter in encoding " + lContentEncoding + ", parameter value not included in query string");
}
}
return buf.toString();
}
use of org.apache.jmeter.protocol.http.util.HTTPArgument in project jmeter by apache.
the class HTTPArgumentsPanel method makeNewArgument.
@Override
protected HTTPArgument makeNewArgument() {
HTTPArgument arg = new HTTPArgument("", "");
arg.setAlwaysEncoded(false);
arg.setUseEquals(true);
return arg;
}
Aggregations