Search in sources :

Example 16 with BSFException

use of org.apache.bsf.BSFException in project opennms by OpenNMS.

the class Executor method stop.

public synchronized void stop() {
    // Shut down the event listener
    if (m_broadcastEventProcessor != null) {
        m_broadcastEventProcessor.close();
    }
    m_broadcastEventProcessor = null;
    // Shut down the thread pool
    m_executorService.shutdown();
    // Run all stop scripts
    for (final StopScript stopScript : m_config.getStopScripts()) {
        if (stopScript.getContent().isPresent()) {
            try {
                m_scriptManager.exec(stopScript.getLanguage(), "", 0, 0, stopScript.getContent().get());
            } catch (BSFException e) {
                LOG.error("Stop script failed: " + stopScript, e);
            }
        } else {
            LOG.warn("Stop script has no script contents: " + stopScript);
        }
    }
    LOG.debug("Scriptd executor stopped");
}
Also used : BSFException(org.apache.bsf.BSFException) StopScript(org.opennms.netmgt.config.scriptd.StopScript)

Example 17 with BSFException

use of org.apache.bsf.BSFException in project jmeter by apache.

the class BSFAssertion method getResult.

@Override
public AssertionResult getResult(SampleResult response) {
    AssertionResult result = new AssertionResult(getName());
    BSFManager mgr = null;
    try {
        mgr = getManager();
        mgr.declareBean("SampleResult", response, SampleResult.class);
        mgr.declareBean("AssertionResult", result, AssertionResult.class);
        processFileOrScript(mgr);
        result.setError(false);
    } catch (BSFException e) {
        if (log.isWarnEnabled()) {
            log.warn("Problem in BSF script {}", e.toString());
        }
        result.setFailure(true);
        result.setError(true);
        result.setFailureMessage(e.toString());
    } finally {
        if (mgr != null) {
            mgr.terminate();
        }
    }
    return result;
}
Also used : BSFException(org.apache.bsf.BSFException) BSFManager(org.apache.bsf.BSFManager)

Example 18 with BSFException

use of org.apache.bsf.BSFException in project jmeter by apache.

the class BSFPostProcessor method process.

@Override
public void process() {
    BSFManager mgr = null;
    try {
        mgr = getManager();
        processFileOrScript(mgr);
    } catch (BSFException e) {
        if (log.isWarnEnabled()) {
            log.warn("Problem in BSF script: {}", e.toString());
        }
    } finally {
        if (mgr != null) {
            mgr.terminate();
        }
    }
}
Also used : BSFException(org.apache.bsf.BSFException) BSFManager(org.apache.bsf.BSFManager)

Example 19 with BSFException

use of org.apache.bsf.BSFException in project jmeter by apache.

the class BSFListener method sampleOccurred.

@Override
public void sampleOccurred(SampleEvent event) {
    BSFManager mgr = null;
    try {
        mgr = getManager();
        if (mgr == null) {
            log.error("Problem creating BSF manager");
            return;
        }
        mgr.declareBean("sampleEvent", event, SampleEvent.class);
        SampleResult result = event.getResult();
        mgr.declareBean("sampleResult", result, SampleResult.class);
        processFileOrScript(mgr);
    } catch (BSFException e) {
        if (log.isWarnEnabled()) {
            log.warn("Problem in BSF script. {}", e.toString());
        }
    } finally {
        if (mgr != null) {
            mgr.terminate();
        }
    }
}
Also used : BSFException(org.apache.bsf.BSFException) SampleResult(org.apache.jmeter.samplers.SampleResult) BSFManager(org.apache.bsf.BSFManager)

Example 20 with BSFException

use of org.apache.bsf.BSFException in project jmeter by apache.

the class BSFJavaScriptEngine method handleError.

/**
     * @param t {@link Throwable}
     * @throws BSFException
     */
private void handleError(Throwable t) throws BSFException {
    Throwable target = t;
    if (t instanceof WrappedException) {
        target = ((WrappedException) t).getWrappedException();
    }
    String message = null;
    if (target instanceof JavaScriptException) {
        message = target.getLocalizedMessage();
        // Is it an exception wrapped in a JavaScriptException?
        Object value = ((JavaScriptException) target).getValue();
        if (value instanceof Throwable) {
            // likely a wrapped exception from a LiveConnect call.
            // Display its stack trace as a diagnostic
            target = (Throwable) value;
        }
    } else if (target instanceof EvaluatorException || target instanceof SecurityException) {
        message = target.getLocalizedMessage();
    } else if (target instanceof RuntimeException) {
        message = "Internal Error: " + target.toString();
    } else if (target instanceof StackOverflowError) {
        message = "Stack Overflow";
    }
    if (message == null) {
        message = target.toString();
    }
    if (target instanceof Error && !(target instanceof StackOverflowError)) {
        // a long stacktrace would end up on the user's console
        throw (Error) target;
    } else {
        throw new BSFException(BSFException.REASON_OTHER_ERROR, "JavaScript Error: " + message, target);
    }
}
Also used : WrappedException(org.mozilla.javascript.WrappedException) BSFException(org.apache.bsf.BSFException) EvaluatorException(org.mozilla.javascript.EvaluatorException) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) JavaScriptException(org.mozilla.javascript.JavaScriptException)

Aggregations

BSFException (org.apache.bsf.BSFException)22 BSFManager (org.apache.bsf.BSFManager)8 File (java.io.File)5 IOException (java.io.IOException)5 FileInputStream (java.io.FileInputStream)4 FileNotFoundException (java.io.FileNotFoundException)3 InputStreamReader (java.io.InputStreamReader)3 BSFEngine (org.apache.bsf.BSFEngine)3 Script (groovy.lang.Script)2 HashMap (java.util.HashMap)2 SampleResult (org.apache.jmeter.samplers.SampleResult)2 NorthbounderException (org.opennms.netmgt.alarmd.api.NorthbounderException)2 BufferedInputStream (java.io.BufferedInputStream)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 LinkedHashMap (java.util.LinkedHashMap)1 StringTokenizer (java.util.StringTokenizer)1 EvaluatorException (org.mozilla.javascript.EvaluatorException)1 JavaScriptException (org.mozilla.javascript.JavaScriptException)1 NativeJavaObject (org.mozilla.javascript.NativeJavaObject)1 WrappedException (org.mozilla.javascript.WrappedException)1