// log.info(getLabel()+" "+getFilename());
SampleResult res = new SampleResult();
boolean isSuccessful = false;
res.setSampleLabel(getLabel());
res.sampleStart();
final BeanShellInterpreter bshInterpreter = getBeanShellInterpreter();
if (bshInterpreter == null) {
res.sampleEnd();
res.setResponseCode("503");//$NON-NLS-1$
res.setResponseMessage("BeanShell Interpreter not found");
res.setSuccessful(false);
return res;
}
try {
String request = getScript();
String fileName = getFilename();
if (fileName.length() == 0) {
res.setSamplerData(request);
} else {
res.setSamplerData(fileName);
}
bshInterpreter.set("Label", getLabel()); //$NON-NLS-1$
bshInterpreter.set("FileName", getFilename()); //$NON-NLS-1$
bshInterpreter.set("SampleResult", res); //$NON-NLS-1$
// Save parameters as single line and as string array
bshInterpreter.set("Parameters", getParameters());//$NON-NLS-1$
bshInterpreter.set("bsh.args", //$NON-NLS-1$
JOrphanUtils.split(getParameters(), " "));//$NON-NLS-1$
// Set default values
bshInterpreter.set("ResponseCode", "200"); //$NON-NLS-1$
bshInterpreter.set("ResponseMessage", "OK");//$NON-NLS-1$
bshInterpreter.set("IsSuccess", true);//$NON-NLS-1$
// Add variables for access to context and variables
JMeterContext jmctx = JMeterContextService.getContext();
JMeterVariables vars = jmctx.getVariables();
bshInterpreter.set("ctx", jmctx);//$NON-NLS-1$
bshInterpreter.set("vars", vars);//$NON-NLS-1$
res.setDataType(SampleResult.TEXT); // assume text output - script can override if necessary
Object bshOut;
if (fileName.length() == 0) {
bshOut = bshInterpreter.eval(request);
} else {
bshOut = bshInterpreter.source(fileName);
}
if (bshOut != null) {// Set response data
String out = bshOut.toString();
res.setResponseData(out.getBytes());
}
// script can also use setResponseData() so long as it returns null
res.setResponseCode(bshInterpreter.get("ResponseCode").toString());//$NON-NLS-1$
res.setResponseMessage(bshInterpreter.get("ResponseMessage").toString());//$NON-NLS-1$
isSuccessful = Boolean.valueOf(bshInterpreter.get("IsSuccess") //$NON-NLS-1$
.toString()).booleanValue();
}
/*
* To avoid class loading problems when bsh,jar is missing, we don't try
* to catch this error separately catch (bsh.EvalError ex) {