Search in sources :

Example 11 with JMeterException

use of org.apache.jorphan.util.JMeterException in project jmeter by apache.

the class BeanShellTestElement method getBeanShellInterpreter.

/**
     * Get the interpreter and set up standard script variables.
     * <p>
     * Sets the following script variables:
     * <ul>
     * <li>ctx</li>
     * <li>Label</li>
     * <li>prev</li>
     * <li>props</li>
     * <li>vars</li>
     * </ul>
     * @return the interpreter
     */
protected BeanShellInterpreter getBeanShellInterpreter() {
    if (isResetInterpreter()) {
        try {
            bshInterpreter.reset();
        } catch (ClassNotFoundException e) {
            log.error("Cannot reset BeanShell: " + e.toString());
        }
    }
    JMeterContext jmctx = JMeterContextService.getContext();
    JMeterVariables vars = jmctx.getVariables();
    try {
        //$NON-NLS-1$
        bshInterpreter.set("ctx", jmctx);
        //$NON-NLS-1$
        bshInterpreter.set("Label", getName());
        //$NON-NLS-1$
        bshInterpreter.set("prev", jmctx.getPreviousResult());
        bshInterpreter.set("props", JMeterUtils.getJMeterProperties());
        //$NON-NLS-1$
        bshInterpreter.set("vars", vars);
    } catch (JMeterException e) {
        log.warn("Problem setting one or more BeanShell variables " + e);
    }
    return bshInterpreter;
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterException(org.apache.jorphan.util.JMeterException) JMeterContext(org.apache.jmeter.threads.JMeterContext)

Example 12 with JMeterException

use of org.apache.jorphan.util.JMeterException 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 13 with JMeterException

use of org.apache.jorphan.util.JMeterException 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)

Aggregations

JMeterException (org.apache.jorphan.util.JMeterException)13 BeanShellInterpreter (org.apache.jmeter.util.BeanShellInterpreter)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 SampleResult (org.apache.jmeter.samplers.SampleResult)4 JMeterContext (org.apache.jmeter.threads.JMeterContext)3 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 UnknownHostException (java.net.UnknownHostException)1 IllegalCharsetNameException (java.nio.charset.IllegalCharsetNameException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 KeyStoreException (java.security.KeyStoreException)1 ArrayList (java.util.ArrayList)1 CookieManager (org.apache.jmeter.protocol.http.control.CookieManager)1 HeaderManager (org.apache.jmeter.protocol.http.control.HeaderManager)1 HTMLParseException (org.apache.jmeter.protocol.http.parser.HTMLParseException)1 HTTPSamplerBase (org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)1 Sampler (org.apache.jmeter.samplers.Sampler)1