use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class AbstractTestElement method addProperty.
/**
* Add property to test element
* @param property {@link JMeterProperty} to add to current Test Element
* @param clone clone property
*/
protected void addProperty(JMeterProperty property, boolean clone) {
JMeterProperty propertyToPut = property;
if (clone) {
propertyToPut = property.clone();
}
if (isRunningVersion()) {
setTemporary(propertyToPut);
} else {
clearTemporary(property);
}
JMeterProperty prop = getProperty(property.getName());
if (prop instanceof NullProperty || (prop instanceof StringProperty && prop.getStringValue().isEmpty())) {
propMap.put(property.getName(), propertyToPut);
} else {
prop.mergeIn(propertyToPut);
}
}
use of org.apache.jmeter.testelement.property.JMeterProperty 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.JMeterProperty in project jmeter by apache.
the class MultiPropertyConverter method marshal.
/** {@inheritDoc} */
@Override
public void marshal(Object arg0, HierarchicalStreamWriter writer, MarshallingContext context) {
MultiProperty prop = (MultiProperty) arg0;
writer.addAttribute(ConversionHelp.ATT_NAME, ConversionHelp.encode(prop.getName()));
for (JMeterProperty jMeterProperty : prop) {
writeItem(jMeterProperty, context, writer);
}
}
use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class HC4CookieHandler method getCookiesForUrl.
/**
* Get array of valid HttpClient cookies for the URL
*
* @param cookiesCP property with all available cookies
* @param url the target URL
* @param allowVariableCookie flag whether cookies may contain jmeter variables
* @return array of HttpClient cookies
*
*/
List<org.apache.http.cookie.Cookie> getCookiesForUrl(CollectionProperty cookiesCP, URL url, boolean allowVariableCookie) {
List<org.apache.http.cookie.Cookie> cookies = new ArrayList<>();
for (JMeterProperty jMeterProperty : cookiesCP) {
Cookie jmcookie = (Cookie) jMeterProperty.getObjectValue();
// Set to running version, to allow function evaluation for the cookie values (bug 28715)
if (allowVariableCookie) {
jmcookie.setRunningVersion(true);
}
cookies.add(makeCookie(jmcookie));
if (allowVariableCookie) {
jmcookie.setRunningVersion(false);
}
}
String host = url.getHost();
String protocol = url.getProtocol();
int port = HTTPSamplerBase.getDefaultPort(protocol, url.getPort());
String path = url.getPath();
boolean secure = HTTPSamplerBase.isSecure(protocol);
CookieOrigin cookieOrigin = new CookieOrigin(host, port, path, secure);
List<org.apache.http.cookie.Cookie> cookiesValid = new ArrayList<>();
for (org.apache.http.cookie.Cookie cookie : cookies) {
if (cookieSpec.match(cookie, cookieOrigin)) {
cookiesValid.add(cookie);
}
}
return cookiesValid;
}
use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class HeaderManager method replace.
@Override
public int replace(String regex, String replaceBy, boolean caseSensitive) throws Exception {
final CollectionProperty hdrs = getHeaders();
int totalReplaced = 0;
for (int i = 0; i < hdrs.size(); i++) {
final JMeterProperty hdr = hdrs.get(i);
Header head = (Header) hdr.getObjectValue();
String value = head.getValue();
if (!StringUtils.isEmpty(value)) {
Object[] result = JOrphanUtils.replaceAllWithRegex(value, regex, replaceBy, caseSensitive);
// check if there is anything to replace
int nbReplaced = ((Integer) result[1]).intValue();
if (nbReplaced > 0) {
String replacedText = (String) result[0];
head.setValue(replacedText);
totalReplaced += nbReplaced;
}
}
}
return totalReplaced;
}
Aggregations