use of org.apache.jmeter.testelement.property.PropertyIterator in project jmeter by apache.
the class TestElementConverter method marshal.
/**
* {@inheritDoc}
*/
@Override
public void marshal(Object arg0, HierarchicalStreamWriter writer, MarshallingContext context) {
TestElement el = (TestElement) arg0;
ConversionHelp.saveSpecialProperties(el, writer);
PropertyIterator iter = el.propertyIterator();
while (iter.hasNext()) {
JMeterProperty jmp = iter.next();
// Skip special properties if required
if (!ConversionHelp.isSpecialProperty(jmp.getName())) {
// Don't save empty comments - except for the TestPlan (to maintain compatibility)
if (!(TestElement.COMMENTS.equals(jmp.getName()) && jmp.getStringValue().length() == 0 && !el.getClass().equals(TestPlan.class))) {
writeCompleteItem(jmp, context, writer);
}
}
}
}
use of org.apache.jmeter.testelement.property.PropertyIterator 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.isEmpty()) {
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: {} cannot be cast to HTTPArgument", objectValue.getClass().getName());
item = new HTTPArgument((Argument) objectValue);
}
final String encodedName = item.getEncodedName();
if (encodedName.isEmpty()) {
// 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 {}, parameter value not included in query string", lContentEncoding);
}
}
return buf.toString();
}
use of org.apache.jmeter.testelement.property.PropertyIterator in project jmeter by apache.
the class FunctionHelper method buildFunctionCallString.
private String buildFunctionCallString(String functionName, Arguments args) {
StringBuilder functionCall = new StringBuilder("${");
functionCall.append(functionName);
if (args.getArguments().size() > 0) {
functionCall.append("(");
PropertyIterator iter = args.iterator();
boolean first = true;
while (iter.hasNext()) {
Argument arg = (Argument) iter.next().getObjectValue();
if (!first) {
functionCall.append(",");
}
functionCall.append(escapeCommata(arg.getValue()));
first = false;
}
functionCall.append(")");
}
functionCall.append("}");
return functionCall.toString();
}
use of org.apache.jmeter.testelement.property.PropertyIterator in project jmeter by apache.
the class AbstractTestElement method mergeIn.
/**
* Add to this the properties of element (by reference)
* @param element {@link TestElement}
*/
protected void mergeIn(TestElement element) {
PropertyIterator iter = element.propertyIterator();
while (iter.hasNext()) {
JMeterProperty prop = iter.next();
addProperty(prop, false);
}
}
use of org.apache.jmeter.testelement.property.PropertyIterator in project jmeter by apache.
the class AbstractTestElement method logProperties.
/**
* Log the properties of the test element
*
* @see TestElement#setProperty(JMeterProperty)
*/
protected void logProperties() {
if (log.isDebugEnabled()) {
PropertyIterator iter = propertyIterator();
while (iter.hasNext()) {
JMeterProperty prop = iter.next();
log.debug("Property {} is temp? {} and is a {}", prop.getName(), isTemporary(prop), prop.getObjectValue());
}
}
}
Aggregations