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");
}
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;
}
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();
}
}
}
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();
}
}
}
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);
}
}
Aggregations