Search in sources :

Example 21 with BSFException

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

the class BSFTestElement method processFileOrScript.

protected void processFileOrScript(BSFManager mgr) throws BSFException {
    BSFEngine bsfEngine = mgr.loadScriptingEngine(getScriptLanguage());
    final String scriptFile = getFilename();
    if (scriptFile.length() == 0) {
        bsfEngine.exec("[script]", 0, 0, getScript());
    } else {
        // we have a file, read and process it
        try {
            String script = FileUtils.readFileToString(new File(scriptFile), Charset.defaultCharset());
            bsfEngine.exec(scriptFile, 0, 0, script);
        } catch (IOException e) {
            if (log.isWarnEnabled()) {
                log.warn("Exception executing script. {}", e.getLocalizedMessage());
            }
            throw new BSFException(BSFException.REASON_IO_ERROR, "Problem reading script file", e);
        }
    }
}
Also used : BSFEngine(org.apache.bsf.BSFEngine) BSFException(org.apache.bsf.BSFException) IOException(java.io.IOException) File(java.io.File)

Example 22 with BSFException

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

the class BSFTestElement method evalFileOrScript.

protected Object evalFileOrScript(BSFManager mgr) throws BSFException {
    BSFEngine bsfEngine = mgr.loadScriptingEngine(getScriptLanguage());
    final String scriptFile = getFilename();
    if (scriptFile.length() == 0) {
        return bsfEngine.eval("[script]", 0, 0, getScript());
    } else {
        // we have a file, read and process it
        try {
            String script = FileUtils.readFileToString(new File(scriptFile), Charset.defaultCharset());
            return bsfEngine.eval(scriptFile, 0, 0, script);
        } catch (IOException e) {
            if (log.isWarnEnabled()) {
                log.warn("Exception evaluating script. {}", e.getLocalizedMessage());
            }
            throw new BSFException(BSFException.REASON_IO_ERROR, "Problem reading script file", e);
        }
    }
}
Also used : BSFEngine(org.apache.bsf.BSFEngine) BSFException(org.apache.bsf.BSFException) IOException(java.io.IOException) File(java.io.File)

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