JMeterContext jmctx = JMeterContextService.getContext();
JMeterVariables vars = jmctx.getVariables();
try
{
Expression e = ExpressionFactory.createExpression(exp);
JexlContext jc = JexlHelper.createContext();
final Map jexlVars = jc.getVars();
jexlVars.put("ctx", jmctx); //$NON-NLS-1$
jexlVars.put("vars", vars); //$NON-NLS-1$
jexlVars.put("props", JMeterUtils.getJMeterProperties()); //$NON-NLS-1$
jexlVars.put("theadName", Thread.currentThread().getName()); //$NON-NLS-1$
jexlVars.put("sampler", currentSampler); //$NON-NLS-1$ (may be null)
jexlVars.put("sampleResult", previousResult); //$NON-NLS-1$ (may be null)
// Now evaluate the expression, getting the result
Object o = e.evaluate(jc);
if (o != null)
{
str = o.toString();
}
if (vars != null && varName.length() > 0) {// vars will be null on TestPlan