use of javax.script.ScriptException in project hazelcast by hazelcast.
the class ScriptExecutorOperation method run.
@Override
public void run() throws Exception {
ScriptEngineManager scriptEngineManager = ScriptEngineManagerContext.getScriptEngineManager();
ScriptEngine engine = scriptEngineManager.getEngineByName(engineName);
if (engine == null) {
throw new IllegalArgumentException("Could not find ScriptEngine named '" + engineName + "'.");
}
engine.put("hazelcast", getNodeEngine().getHazelcastInstance());
if (bindings != null) {
Set<Map.Entry<String, Object>> entries = bindings.entrySet();
for (Map.Entry<String, Object> entry : entries) {
engine.put(entry.getKey(), entry.getValue());
}
}
try {
this.result = engine.eval(script);
} catch (ScriptException e) {
this.result = e.getMessage();
}
}
use of javax.script.ScriptException in project hazelcast by hazelcast.
the class ScriptCallable method call.
@Override
public Object call() {
final ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
ScriptEngine e = scriptEngineManager.getEngineByName("javascript");
if (map != null) {
for (Map.Entry<String, ?> entry : map.entrySet()) {
e.put(entry.getKey(), entry.getValue());
}
}
e.put("hazelcast", hazelcastInstance);
try {
// for new JavaScript engine called Nashorn we need the compatibility script
if (e.getFactory().getEngineName().toLowerCase().contains("nashorn")) {
e.eval("load('nashorn:mozilla_compat.js');");
}
e.eval("importPackage(java.lang);");
e.eval("importPackage(java.util);");
e.eval("importPackage(com.hazelcast.core);");
e.eval("importPackage(com.hazelcast.config);");
e.eval("importPackage(java.util.concurrent);");
e.eval("importPackage(org.junit);");
return e.eval(script);
} catch (ScriptException e1) {
throw new RuntimeException(e1);
}
}
use of javax.script.ScriptException in project hazelcast by hazelcast.
the class ScriptRunnable method run.
@Override
public void run() {
final ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
ScriptEngine e = scriptEngineManager.getEngineByName("javascript");
if (map != null) {
for (Map.Entry<String, ?> entry : map.entrySet()) {
e.put(entry.getKey(), entry.getValue());
}
}
e.put("hazelcast", hazelcastInstance);
try {
// for new JavaScript engine called Nashorn we need the compatibility script
if (e.getFactory().getEngineName().toLowerCase().contains("nashorn")) {
e.eval("load('nashorn:mozilla_compat.js');");
}
e.eval("importPackage(java.lang);");
e.eval("importPackage(java.util);");
e.eval("importPackage(com.hazelcast.core);");
e.eval("importPackage(com.hazelcast.config);");
e.eval("importPackage(java.util.concurrent);");
e.eval("importPackage(org.junit);");
e.eval(script);
} catch (ScriptException e1) {
throw new RuntimeException(e1);
}
}
use of javax.script.ScriptException in project groovy-core by groovy.
the class GroovyScriptEngineImpl method eval.
public Object eval(String script, ScriptContext ctx) throws ScriptException {
try {
String val = (String) ctx.getAttribute("#jsr223.groovy.engine.keep.globals", ScriptContext.ENGINE_SCOPE);
ReferenceBundle bundle = ReferenceBundle.getHardBundle();
if (val != null && val.length() > 0) {
if (val.equalsIgnoreCase("soft")) {
bundle = ReferenceBundle.getSoftBundle();
} else if (val.equalsIgnoreCase("weak")) {
bundle = ReferenceBundle.getWeakBundle();
} else if (val.equalsIgnoreCase("phantom")) {
bundle = ReferenceBundle.getPhantomBundle();
}
}
globalClosures.setBundle(bundle);
} catch (ClassCastException cce) {
/*ignore.*/
}
try {
Class clazz = getScriptClass(script);
if (clazz == null)
throw new ScriptException("Script class is null");
return eval(clazz, ctx);
} catch (SyntaxException e) {
throw new ScriptException(e.getMessage(), e.getSourceLocator(), e.getLine());
} catch (Exception e) {
if (debug)
e.printStackTrace();
throw new ScriptException(e);
}
}
use of javax.script.ScriptException in project OpenAM by OpenRock.
the class Scripted method process.
/**
* {@inheritDoc}
*/
@Override
public int process(Callback[] callbacks, int state) throws LoginException {
switch(state) {
case ISAuthConstants.LOGIN_START:
substituteUIStrings();
return STATE_RUN_SCRIPT;
case STATE_RUN_SCRIPT:
Bindings scriptVariables = new SimpleBindings();
scriptVariables.put(REQUEST_DATA_VARIABLE_NAME, getScriptHttpRequestWrapper());
String clientScriptOutputData = getClientScriptOutputData(callbacks);
scriptVariables.put(CLIENT_SCRIPT_OUTPUT_DATA_VARIABLE_NAME, clientScriptOutputData);
scriptVariables.put(LOGGER_VARIABLE_NAME, DEBUG);
scriptVariables.put(STATE_VARIABLE_NAME, state);
scriptVariables.put(SHARED_STATE, sharedState);
scriptVariables.put(USERNAME_VARIABLE_NAME, userName);
scriptVariables.put(SUCCESS_ATTR_NAME, SUCCESS_VALUE);
scriptVariables.put(FAILED_ATTR_NAME, FAILURE_VALUE);
scriptVariables.put(HTTP_CLIENT_VARIABLE_NAME, httpClient);
scriptVariables.put(IDENTITY_REPOSITORY, identityRepository);
try {
scriptEvaluator.evaluateScript(getServerSideScript(), scriptVariables);
} catch (ScriptException e) {
DEBUG.message("Error running server side scripts", e);
throw new AuthLoginException("Error running script", e);
}
state = ((Number) scriptVariables.get(STATE_VARIABLE_NAME)).intValue();
userName = (String) scriptVariables.get(USERNAME_VARIABLE_NAME);
sharedState.put(CLIENT_SCRIPT_OUTPUT_DATA_VARIABLE_NAME, clientScriptOutputData);
if (state != SUCCESS_VALUE) {
throw new AuthLoginException("Authentication failed");
}
return state;
default:
throw new AuthLoginException("Invalid state");
}
}
Aggregations