{
throw new InvalidVariableException("BeanShell not found");
}
JMeterContext jmctx = JMeterContextService.getContext();
JMeterVariables vars = jmctx.getVariables();
String script = ((CompoundVariable) values[0]).execute();
String varName = ""; //$NON-NLS-1$
if (values.length > 1) {
varName = ((CompoundVariable) values[1]).execute().trim();
}
String resultStr = ""; //$NON-NLS-1$
log.debug("Script=" + script);
try {
// Pass in some variables
if (currentSampler != null) {
bshInterpreter.set("Sampler", currentSampler); //$NON-NLS-1$
}
if (previousResult != null) {
bshInterpreter.set("SampleResult", previousResult); //$NON-NLS-1$
}
// Allow access to context and variables directly
bshInterpreter.set("ctx", jmctx); //$NON-NLS-1$
bshInterpreter.set("vars", vars); //$NON-NLS-1$
bshInterpreter.set("props", JMeterUtils.getJMeterProperties()); //$NON-NLS-1$
bshInterpreter.set("threadName", Thread.currentThread().getName()); //$NON-NLS-1$
// Execute the script
Object bshOut = bshInterpreter.eval(script);
if (bshOut != null) {
resultStr = bshOut.toString();
}
if (vars != null && varName.length() > 0) {// vars will be null on TestPlan
vars.put(varName, resultStr);
}
} catch (Exception ex) // Mainly for bsh.EvalError
{
log.warn("Error running BSH script", ex);
}