use of org.apache.jmeter.threads.JMeterContext in project jmeter by apache.
the class BSFTestElement method initManager.
protected void initManager(BSFManager mgr) throws BSFException {
final String label = getName();
final String fileName = getFilename();
final String scriptParameters = getParameters();
// Use actual class name for log
final Logger logger = LoggerFactory.getLogger(getClass());
// $NON-NLS-1$
mgr.declareBean("log", logger, Logger.class);
// $NON-NLS-1$
mgr.declareBean("Label", label, String.class);
// $NON-NLS-1$
mgr.declareBean("FileName", fileName, String.class);
// $NON-NLS-1$
mgr.declareBean("Parameters", scriptParameters, String.class);
//$NON-NLS-1$
String[] args = JOrphanUtils.split(scriptParameters, " ");
//$NON-NLS-1$
mgr.declareBean("args", args, args.getClass());
// Add variables for access to context and variables
JMeterContext jmctx = JMeterContextService.getContext();
JMeterVariables vars = jmctx.getVariables();
Properties props = JMeterUtils.getJMeterProperties();
// $NON-NLS-1$
mgr.declareBean("ctx", jmctx, jmctx.getClass());
// $NON-NLS-1$
mgr.declareBean("vars", vars, vars.getClass());
// $NON-NLS-1$
mgr.declareBean("props", props, props.getClass());
// For use in debugging:
// $NON-NLS-1$
mgr.declareBean("OUT", System.out, PrintStream.class);
// Most subclasses will need these:
Sampler sampler = jmctx.getCurrentSampler();
mgr.declareBean("sampler", sampler, Sampler.class);
SampleResult prev = jmctx.getPreviousResult();
mgr.declareBean("prev", prev, SampleResult.class);
}
use of org.apache.jmeter.threads.JMeterContext 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.threads.JMeterContext in project jmeter by apache.
the class TestResultAction method setUp.
@Before
public void setUp() {
JMeterContext jmctx = JMeterContextService.getContext();
resultAction = new ResultAction();
resultAction.setThreadContext(jmctx);
JMeterVariables vars = new JMeterVariables();
jmctx.setVariables(vars);
sampleResult = new SampleResult();
sampleResult.setResponseData(data, null);
}
use of org.apache.jmeter.threads.JMeterContext in project jmeter by apache.
the class TestResultSaver method setUp.
@Before
public void setUp() {
JMeterContext jmctx = JMeterContextService.getContext();
resultSaver = new ResultSaver();
resultSaver.setThreadContext(jmctx);
jmctx.setVariables(vars);
sampleResult = new SampleResult();
sampleResult.setResponseData(data, null);
}
use of org.apache.jmeter.threads.JMeterContext 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");
}
}
Aggregations