Search in sources :

Example 6 with BeanShellInterpreter

use of org.apache.jmeter.util.BeanShellInterpreter 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());
        }
    }
}
Also used : JMeterException(org.apache.jorphan.util.JMeterException) JMeterContext(org.apache.jmeter.threads.JMeterContext) SampleResult(org.apache.jmeter.samplers.SampleResult) BeanShellInterpreter(org.apache.jmeter.util.BeanShellInterpreter)

Example 7 with BeanShellInterpreter

use of org.apache.jmeter.util.BeanShellInterpreter 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());
        }
    }
}
Also used : JMeterException(org.apache.jorphan.util.JMeterException) SampleResult(org.apache.jmeter.samplers.SampleResult) BeanShellInterpreter(org.apache.jmeter.util.BeanShellInterpreter)

Example 8 with BeanShellInterpreter

use of org.apache.jmeter.util.BeanShellInterpreter in project jmeter by apache.

the class BeanShell method setParameters.

/** {@inheritDoc} */
@Override
public synchronized void setParameters(Collection<CompoundVariable> parameters) throws InvalidVariableException {
    checkParameterCount(parameters, 1, 2);
    values = parameters.toArray();
    try {
        bshInterpreter = new BeanShellInterpreter(JMeterUtils.getProperty(INIT_FILE), log);
    } catch (ClassNotFoundException e) {
        throw new InvalidVariableException("BeanShell not found", e);
    }
}
Also used : BeanShellInterpreter(org.apache.jmeter.util.BeanShellInterpreter)

Aggregations

BeanShellInterpreter (org.apache.jmeter.util.BeanShellInterpreter)8 JMeterException (org.apache.jorphan.util.JMeterException)6 SampleResult (org.apache.jmeter.samplers.SampleResult)3 JMeterContext (org.apache.jmeter.threads.JMeterContext)2 Sampler (org.apache.jmeter.samplers.Sampler)1 BeanShellServer (org.apache.jmeter.util.BeanShellServer)1