use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.
the class RegExUserParameters method process.
@Override
public void process() {
if (log.isDebugEnabled()) {
// $NON-NLS-1$
log.debug("{} Running up named: {}", Thread.currentThread().getName(), getName());
}
Sampler entry = getThreadContext().getCurrentSampler();
if (!(entry instanceof HTTPSamplerBase)) {
return;
}
Map<String, String> paramMap = buildParamsMap();
if (paramMap == null || paramMap.isEmpty()) {
log.info("RegExUserParameters element: {} => Referenced RegExp was not found, no parameter will be changed", getName());
return;
}
HTTPSamplerBase sampler = (HTTPSamplerBase) entry;
for (JMeterProperty jMeterProperty : sampler.getArguments()) {
Argument arg = (Argument) jMeterProperty.getObjectValue();
String oldValue = arg.getValue();
// if parameter name exists in http request
// then change its value with value obtained with regular expression
String val = paramMap.get(arg.getName());
if (val != null) {
arg.setValue(val);
}
if (log.isDebugEnabled()) {
log.debug("RegExUserParameters element: {} => changed parameter: {} = {}, was: {}", getName(), arg.getName(), arg.getValue(), oldValue);
}
}
}
use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.
the class AbstractSamplerCreator method createAndPopulateSampler.
/**
* @see org.apache.jmeter.protocol.http.proxy.SamplerCreator#createAndPopulateSampler(org.apache.jmeter.protocol.http.proxy.HttpRequestHdr,
* java.util.Map, java.util.Map)
*/
@Override
public HTTPSamplerBase createAndPopulateSampler(HttpRequestHdr request, Map<String, String> pageEncodings, Map<String, String> formEncodings) throws Exception {
HTTPSamplerBase sampler = createSampler(request, pageEncodings, formEncodings);
populateSampler(sampler, request, pageEncodings, formEncodings);
return sampler;
}
use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.
the class AnchorModifier method process.
/**
* Modifies an Entry object based on HTML response text.
*/
@Override
public void process() {
JMeterContext context = getThreadContext();
Sampler sam = context.getCurrentSampler();
SampleResult res = context.getPreviousResult();
HTTPSamplerBase sampler;
HTTPSampleResult result;
if (!(sam instanceof HTTPSamplerBase) || !(res instanceof HTTPSampleResult)) {
log.info("Can't apply HTML Link Parser when the previous" + " sampler run is not an HTTP Request.");
return;
} else {
sampler = (HTTPSamplerBase) sam;
result = (HTTPSampleResult) res;
}
List<HTTPSamplerBase> potentialLinks = new ArrayList<>();
String responseText = result.getResponseDataAsString();
// $NON-NLS-1$
int index = responseText.indexOf('<');
if (index == -1) {
index = 0;
}
if (log.isDebugEnabled()) {
log.debug("Check for matches against: " + sampler.toString());
}
Document html = (Document) HtmlParsingUtils.getDOM(responseText.substring(index));
addAnchorUrls(html, result, sampler, potentialLinks);
addFormUrls(html, result, sampler, potentialLinks);
addFramesetUrls(html, result, sampler, potentialLinks);
if (!potentialLinks.isEmpty()) {
HTTPSamplerBase url = potentialLinks.get(ThreadLocalRandom.current().nextInt(potentialLinks.size()));
if (log.isDebugEnabled()) {
log.debug("Selected: " + url.toString());
}
sampler.setDomain(url.getDomain());
sampler.setPath(url.getPath());
if (url.getMethod().equals(HTTPConstants.POST)) {
for (JMeterProperty jMeterProperty : sampler.getArguments()) {
Argument arg = (Argument) jMeterProperty.getObjectValue();
modifyArgument(arg, url.getArguments());
}
} else {
sampler.setArguments(url.getArguments());
}
sampler.setProtocol(url.getProtocol());
} else {
log.debug("No matches found");
}
}
use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.
the class AnchorModifier method addFramesetUrls.
private void addFramesetUrls(Document html, HTTPSampleResult result, HTTPSamplerBase config, List<HTTPSamplerBase> potentialLinks) {
String base = "";
// $NON-NLS-1$
NodeList baseList = html.getElementsByTagName("base");
if (baseList.getLength() > 0) {
base = // $NON-NLS-1$
baseList.item(0).getAttributes().getNamedItem("href").getNodeValue();
}
// $NON-NLS-1$
NodeList nodeList = html.getElementsByTagName("frame");
for (int i = 0; i < nodeList.getLength(); i++) {
Node tempNode = nodeList.item(i);
NamedNodeMap nnm = tempNode.getAttributes();
// $NON-NLS-1$
Node namedItem = nnm.getNamedItem("src");
if (namedItem == null) {
continue;
}
String hrefStr = namedItem.getNodeValue();
try {
HTTPSamplerBase newUrl = HtmlParsingUtils.createUrlFromAnchor(hrefStr, ConversionUtils.makeRelativeURL(result.getURL(), base));
newUrl.setMethod(HTTPConstants.GET);
if (log.isDebugEnabled()) {
log.debug("Potential <frame src> match: " + newUrl);
}
if (HtmlParsingUtils.isAnchorMatched(newUrl, config)) {
log.debug("Matched!");
potentialLinks.add(newUrl);
}
} catch (MalformedURLException e) {
log.warn("Bad URL " + e);
}
}
}
use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.
the class URLRewritingModifier method process.
@Override
public void process() {
JMeterContext ctx = getThreadContext();
Sampler sampler = ctx.getCurrentSampler();
if (!(sampler instanceof HTTPSamplerBase)) {
// Ignore non-HTTP samplers
return;
}
SampleResult responseText = ctx.getPreviousResult();
if (responseText == null) {
return;
}
initRegex(getArgumentName());
String text = responseText.getResponseDataAsString();
Perl5Matcher matcher = JMeterUtils.getMatcher();
String value = "";
if (isPathExtension() && isPathExtensionNoEquals() && isPathExtensionNoQuestionmark()) {
if (matcher.contains(text, pathExtensionNoEqualsNoQuestionmarkRegexp)) {
MatchResult result = matcher.getMatch();
value = result.group(1);
}
} else if (// && !isPathExtensionNoQuestionmark()
isPathExtension() && isPathExtensionNoEquals()) {
if (matcher.contains(text, pathExtensionNoEqualsQuestionmarkRegexp)) {
MatchResult result = matcher.getMatch();
value = result.group(1);
}
} else if (// && !isPathExtensionNoEquals()
isPathExtension() && isPathExtensionNoQuestionmark()) {
if (matcher.contains(text, pathExtensionEqualsNoQuestionmarkRegexp)) {
MatchResult result = matcher.getMatch();
value = result.group(1);
}
} else if (// && !isPathExtensionNoEquals() && !isPathExtensionNoQuestionmark()
isPathExtension()) {
if (matcher.contains(text, pathExtensionEqualsQuestionmarkRegexp)) {
MatchResult result = matcher.getMatch();
value = result.group(1);
}
} else // if ! isPathExtension()
{
if (matcher.contains(text, parameterRegexp)) {
MatchResult result = matcher.getMatch();
for (int i = 1; i < result.groups(); i++) {
value = result.group(i);
if (value != null) {
break;
}
}
}
}
// Bug 15025 - save session value across samplers
if (shouldCache()) {
if (value == null || value.length() == 0) {
value = savedValue;
} else {
savedValue = value;
}
}
modify((HTTPSamplerBase) sampler, value);
}
Aggregations