use of org.apache.jmeter.samplers.Sampler in project jmeter by apache.
the class BeanShellPreProcessor method process.
@Override
public void process() {
final BeanShellInterpreter bshInterpreter = getBeanShellInterpreter();
if (bshInterpreter == null) {
log.error("BeanShell not found");
return;
}
JMeterContext jmctx = JMeterContextService.getContext();
Sampler sam = jmctx.getCurrentSampler();
try {
// Add variables for access to context and variables
//$NON-NLS-1$
bshInterpreter.set("sampler", sam);
processFileOrScript(bshInterpreter);
} catch (JMeterException e) {
if (log.isWarnEnabled()) {
log.warn("Problem in BeanShell script. {}", e.toString());
}
}
}
use of org.apache.jmeter.samplers.Sampler 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());
// config.parseArguments(url.getQueryString());
}
sampler.setProtocol(url.getProtocol());
} else {
log.debug("No matches found");
}
}
use of org.apache.jmeter.samplers.Sampler in project jmeter by apache.
the class RegExUserParameters method process.
@Override
public void process() {
if (log.isDebugEnabled()) {
//$NON-NLS-1$
log.debug(Thread.currentThread().getName() + " Running up named: " + getName());
}
Sampler entry = getThreadContext().getCurrentSampler();
if (!(entry instanceof HTTPSamplerBase)) {
return;
}
Map<String, String> paramMap = buildParamsMap();
if (paramMap == null || paramMap.isEmpty()) {
log.info("RegExUserParameters element:" + getName() + " => Referenced RegExp was not found, no parameter will be changed");
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:" + getName() + " => changed parameter: " + arg.getName() + " = " + arg.getValue() + ", was:" + oldValue);
}
}
}
use of org.apache.jmeter.samplers.Sampler 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);
}
use of org.apache.jmeter.samplers.Sampler in project jmeter by apache.
the class TestSwitchController method nextName.
// Get next sample and its name
private String nextName(GenericController c) {
Sampler s = c.next();
String n;
if (s == null) {
return null;
}
n = s.getName();
return n;
}
Aggregations