Search in sources :

Example 1 with JMeterException

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

the class JMeter method startOptionalServers.

/**
     *
     */
private void startOptionalServers() {
    // $NON-NLS-1$
    int bshport = JMeterUtils.getPropDefault("beanshell.server.port", 0);
    // $NON-NLS-1$ $NON-NLS-2$
    String bshfile = JMeterUtils.getPropDefault("beanshell.server.file", "");
    if (bshport > 0) {
        log.info("Starting Beanshell server ({},{})", bshport, bshfile);
        Runnable t = new BeanShellServer(bshport, bshfile);
        // NOSONAR we just evaluate some code here
        t.run();
    }
    // Should we run a beanshell script on startup?
    // $NON-NLS-1$
    String bshinit = JMeterUtils.getProperty("beanshell.init.file");
    if (bshinit != null) {
        log.info("Run Beanshell on file: {}", bshinit);
        try {
            BeanShellInterpreter bsi = new BeanShellInterpreter();
            bsi.source(bshinit);
        } catch (ClassNotFoundException e) {
            if (log.isWarnEnabled()) {
                log.warn("Could not start Beanshell: {}", e.getLocalizedMessage());
            }
        } catch (JMeterException e) {
            if (log.isWarnEnabled()) {
                log.warn("Could not process Beanshell file: {}", e.getLocalizedMessage());
            }
        }
    }
    // $NON-NLS-1$
    int mirrorPort = JMeterUtils.getPropDefault("mirror.server.port", 0);
    if (mirrorPort > 0) {
        log.info("Starting Mirror server ({})", mirrorPort);
        try {
            Object instance = ClassTools.construct(// $NON-NLS-1$
            "org.apache.jmeter.protocol.http.control.HttpMirrorControl", mirrorPort);
            ClassTools.invoke(instance, "startHttpMirror");
        } catch (JMeterException e) {
            log.warn("Could not start Mirror server", e);
        }
    }
}
Also used : JMeterException(org.apache.jorphan.util.JMeterException) BeanShellServer(org.apache.jmeter.util.BeanShellServer) BeanShellInterpreter(org.apache.jmeter.util.BeanShellInterpreter)

Example 2 with JMeterException

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

the class AccessLogSampler method sampleWithParser.

/**
 * sample gets a new HTTPSampler from the generator and calls it's sample()
 * method.
 *
 * @return newly generated and called sample
 */
public SampleResult sampleWithParser() {
    initFilter();
    instantiateParser();
    SampleResult res = null;
    try {
        if (parser == null) {
            throw new JMeterException("No Parser available");
        }
        // we call parse with 1 to get only one.
        // this also means if we change the implementation
        // to use 2, it would use every other entry and
        // so on. Not that it is really useful, but a
        // person could use it that way if they have a
        // huge gigabyte log file and they only want to
        // use a quarter of the entries.
        int thisCount = parser.parseAndConfigure(1, this);
        if (// Was there an error?
        thisCount < 0) {
            return errorResult(new Error("Problem parsing the log file"), new HTTPSampleResult());
        }
        if (thisCount == 0) {
            if (count == 0 || filter == null) {
                log.info("Stopping current thread");
                JMeterContextService.getContext().getThread().stop();
            }
            if (filter != null) {
                filter.reset();
            }
            CookieManager cm = getCookieManager();
            if (cm != null) {
                cm.clear();
            }
            count = 0;
            return errorResult(new Error("No entries found"), new HTTPSampleResult());
        }
        count = thisCount;
        res = sample();
        if (res != null) {
            res.setSampleLabel(toString());
        }
    } catch (Exception e) {
        log.warn("Sampling failure", e);
        return errorResult(e, new HTTPSampleResult());
    }
    return res;
}
Also used : JMeterException(org.apache.jorphan.util.JMeterException) SampleResult(org.apache.jmeter.samplers.SampleResult) CookieManager(org.apache.jmeter.protocol.http.control.CookieManager) JMeterException(org.apache.jorphan.util.JMeterException)

Example 3 with JMeterException

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

the class BeanShellPreProcessor method process.

@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
        // $NON-NLS-1$
        bshInterpreter.set("sampler", sam);
        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) Sampler(org.apache.jmeter.samplers.Sampler) BeanShellInterpreter(org.apache.jmeter.util.BeanShellInterpreter)

Example 4 with JMeterException

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

the class BeanShellTimer method delay.

/**
 * {@inheritDoc}
 */
@Override
public long delay() {
    String ret = "0";
    final BeanShellInterpreter bshInterpreter = getBeanShellInterpreter();
    if (bshInterpreter == null) {
        log.error("BeanShell not found");
        return 0;
    }
    try {
        Object o = processFileOrScript(bshInterpreter);
        if (o != null) {
            ret = o.toString();
        }
    } catch (JMeterException e) {
        if (log.isWarnEnabled()) {
            log.warn("Problem in BeanShell script. {}", e.toString());
        }
    }
    try {
        return Long.decode(ret);
    } catch (NumberFormatException e) {
        log.warn("Number format exception while decoding number: '{}'", ret);
        return 0;
    }
}
Also used : JMeterException(org.apache.jorphan.util.JMeterException) BeanShellInterpreter(org.apache.jmeter.util.BeanShellInterpreter)

Example 5 with JMeterException

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

the class BeanShellInterpreter method bshInvoke.

private Object bshInvoke(Method m, Object[] o, boolean shouldLog) throws JMeterException {
    Object r = null;
    final String errorString = "Error invoking bsh method: ";
    try {
        r = m.invoke(bshInstance, o);
    } catch (IllegalArgumentException | IllegalAccessException e) {
        // Programming error
        final String message = errorString + m.getName();
        log.error(message);
        throw new JMeterError(message, e);
    } catch (InvocationTargetException e) {
        // Can occur at run-time
        // could be caused by the bsh Exceptions:
        // EvalError, ParseException or TargetError
        String message = errorString + m.getName();
        Throwable cause = e.getCause();
        if (cause != null) {
            message += "\t" + cause.getLocalizedMessage();
        }
        if (shouldLog) {
            log.error(message);
        }
        throw new JMeterException(message, e);
    }
    return r;
}
Also used : JMeterError(org.apache.jorphan.util.JMeterError) JMeterException(org.apache.jorphan.util.JMeterException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

JMeterException (org.apache.jorphan.util.JMeterException)14 BeanShellInterpreter (org.apache.jmeter.util.BeanShellInterpreter)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 SampleResult (org.apache.jmeter.samplers.SampleResult)4 JMeterContext (org.apache.jmeter.threads.JMeterContext)3 File (java.io.File)2 IOException (java.io.IOException)2 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 OutputStream (java.io.OutputStream)1 Reader (java.io.Reader)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 Properties (java.util.Properties)1