use of org.apache.jorphan.util.JMeterException in project jmeter by apache.
the class BeanShellTestElement method getBeanShellInterpreter.
/**
* Get the interpreter and set up standard script variables.
* <p>
* Sets the following script variables:
* <ul>
* <li>ctx</li>
* <li>Label</li>
* <li>prev</li>
* <li>props</li>
* <li>vars</li>
* </ul>
* @return the interpreter
*/
protected BeanShellInterpreter getBeanShellInterpreter() {
if (isResetInterpreter()) {
try {
bshInterpreter.reset();
} catch (ClassNotFoundException e) {
log.error("Cannot reset BeanShell: " + e.toString());
}
}
JMeterContext jmctx = JMeterContextService.getContext();
JMeterVariables vars = jmctx.getVariables();
try {
//$NON-NLS-1$
bshInterpreter.set("ctx", jmctx);
//$NON-NLS-1$
bshInterpreter.set("Label", getName());
//$NON-NLS-1$
bshInterpreter.set("prev", jmctx.getPreviousResult());
bshInterpreter.set("props", JMeterUtils.getJMeterProperties());
//$NON-NLS-1$
bshInterpreter.set("vars", vars);
} catch (JMeterException e) {
log.warn("Problem setting one or more BeanShell variables " + e);
}
return bshInterpreter;
}
use of org.apache.jorphan.util.JMeterException in project jmeter by apache.
the class BeanShellPostProcessor method process.
@Override
public void process() {
JMeterContext jmctx = JMeterContextService.getContext();
SampleResult prev = jmctx.getPreviousResult();
if (prev == null) {
// TODO - should we skip processing here?
return;
}
final BeanShellInterpreter bshInterpreter = getBeanShellInterpreter();
if (bshInterpreter == null) {
log.error("BeanShell not found");
return;
}
try {
// Add variables for access to context and variables
//$NON-NLS-1$
bshInterpreter.set("data", prev.getResponseData());
processFileOrScript(bshInterpreter);
} catch (JMeterException e) {
if (log.isWarnEnabled()) {
log.warn("Problem in BeanShell script: {}", e.toString());
}
}
}
use of org.apache.jorphan.util.JMeterException in project jmeter by apache.
the class BeanShellListener method sampleOccurred.
@Override
public void sampleOccurred(SampleEvent se) {
final BeanShellInterpreter bshInterpreter = getBeanShellInterpreter();
if (bshInterpreter == null) {
log.error("BeanShell not found");
return;
}
SampleResult samp = se.getResult();
try {
//$NON-NLS-1$
bshInterpreter.set("sampleEvent", se);
//$NON-NLS-1$
bshInterpreter.set("sampleResult", samp);
processFileOrScript(bshInterpreter);
} catch (JMeterException e) {
if (log.isWarnEnabled()) {
log.warn("Problem in BeanShell script. {}", e.toString());
}
}
}
Aggregations