@Override public void sampleOccurred(SampleEvent se) { final BeanShellInterpreter bshInterpreter = getBeanShellInterpreter(); if (bshInterpreter == null) { log.error("BeanShell not found"); return; } SampleResult samp=se.getResult(); try { bshInterpreter.set("sampleEvent", se);//$NON-NLS-1$ bshInterpreter.set("sampleResult", samp);//$NON-NLS-1$ processFileOrScript(bshInterpreter); } catch (JMeterException e) { if (log.isWarnEnabled()) { log.warn("Problem in BeanShell script. {}", e.toString()); } } }
set("log", logger);//$NON-NLS-1$ } catch (JMeterException e) { log.warn("Can't set logger variable", e);
bshInterpreter.set("ctx", jmctx);//$NON-NLS-1$ bshInterpreter.set("Label", getName()); //$NON-NLS-1$ bshInterpreter.set("prev", jmctx.getPreviousResult());//$NON-NLS-1$ bshInterpreter.set("props", JMeterUtils.getJMeterProperties()); bshInterpreter.set("vars", vars);//$NON-NLS-1$ } catch (JMeterException e) { log.warn("Problem setting one or more BeanShell variables "+e);
bshInterpreter.set("Sampler", currentSampler); //$NON-NLS-1$ bshInterpreter.set("SampleResult", previousResult); //$NON-NLS-1$ 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$
/** * Process the file or script from the test element. * <p> * Sets the following script variables: * <ul> * <li>FileName</li> * <li>Parameters</li> * <li>bsh.args</li> * </ul> * @param bsh the interpreter, not {@code null} * @return the result of the script, may be {@code null} * * @throws JMeterException when working with the bsh fails */ protected Object processFileOrScript(BeanShellInterpreter bsh) throws JMeterException{ String fileName = getFilename(); String params = getParameters(); bsh.set("FileName", fileName);//$NON-NLS-1$ // Set params as a single line bsh.set("Parameters", params); // $NON-NLS-1$ // and set as an array bsh.set("bsh.args",//$NON-NLS-1$ JOrphanUtils.split(params, " "));//$NON-NLS-1$ if (fileName.length() == 0) { return bsh.eval(getScript()); } return bsh.source(fileName); }
@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 bshInterpreter.set("sampler", sam);//$NON-NLS-1$ processFileOrScript(bshInterpreter); } catch (JMeterException e) { if (log.isWarnEnabled()) { log.warn("Problem in BeanShell script. {}", e.toString()); } } }
@Override public void process() { JMeterContext jmctx = JMeterContextService.getContext(); SampleResult prev = jmctx.getPreviousResult(); if (prev == null) { return; // TODO - should we skip processing here? } final BeanShellInterpreter bshInterpreter = getBeanShellInterpreter(); if (bshInterpreter == null) { log.error("BeanShell not found"); return; } try { // Add variables for access to context and variables bshInterpreter.set("data", prev.getResponseData());//$NON-NLS-1$ processFileOrScript(bshInterpreter); } catch (JMeterException e) { if (log.isWarnEnabled()) { log.warn("Problem in BeanShell script: {}", e.toString()); } } }
bshInterpreter.set("SampleResult", response); //$NON-NLS-1$ bshInterpreter.set("Response", response); //$NON-NLS-1$ bshInterpreter.set("ResponseData", response.getResponseData());//$NON-NLS-1$ bshInterpreter.set("ResponseCode", response.getResponseCode());//$NON-NLS-1$ bshInterpreter.set("ResponseMessage", response.getResponseMessage());//$NON-NLS-1$ bshInterpreter.set("ResponseHeaders", response.getResponseHeaders());//$NON-NLS-1$ bshInterpreter.set("RequestHeaders", response.getRequestHeaders());//$NON-NLS-1$ bshInterpreter.set("SampleLabel", response.getSampleLabel());//$NON-NLS-1$ bshInterpreter.set("SamplerData", response.getSamplerData());//$NON-NLS-1$ bshInterpreter.set("Successful", response.isSuccessful());//$NON-NLS-1$ bshInterpreter.set("FailureMessage", "");//$NON-NLS-1$ //$NON-NLS-2$ bshInterpreter.set("Failure", false);//$NON-NLS-1$