use of javax.script.ScriptException in project dubbo by alibaba.
the class ScriptRouter method route.
@SuppressWarnings("unchecked")
public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException {
try {
List<Invoker<T>> invokersCopy = new ArrayList<Invoker<T>>(invokers);
Compilable compilable = (Compilable) engine;
Bindings bindings = engine.createBindings();
bindings.put("invokers", invokersCopy);
bindings.put("invocation", invocation);
bindings.put("context", RpcContext.getContext());
CompiledScript function = compilable.compile(rule);
Object obj = function.eval(bindings);
if (obj instanceof Invoker[]) {
invokersCopy = Arrays.asList((Invoker<T>[]) obj);
} else if (obj instanceof Object[]) {
invokersCopy = new ArrayList<Invoker<T>>();
for (Object inv : (Object[]) obj) {
invokersCopy.add((Invoker<T>) inv);
}
} else {
invokersCopy = (List<Invoker<T>>) obj;
}
return invokersCopy;
} catch (ScriptException e) {
// fail then ignore rule .invokers.
logger.error("route error , rule has been ignored. rule: " + rule + ", method:" + invocation.getMethodName() + ", url: " + RpcContext.getContext().getUrl(), e);
return invokers;
}
}
use of javax.script.ScriptException in project meecrowave by apache.
the class MeecrowaveRunMojo method scriptCustomization.
private void scriptCustomization(final List<String> customizers, final String ext, final Map<String, Object> customBindings) {
if (customizers == null || customizers.isEmpty()) {
return;
}
final ScriptEngine engine = new ScriptEngineManager().getEngineByExtension(ext);
if (engine == null) {
throw new IllegalStateException("No engine for " + ext + ". Maybe add the JSR223 implementation as plugin dependency.");
}
for (final String js : customizers) {
try {
final SimpleBindings bindings = new SimpleBindings();
bindings.put("project", project);
engine.eval(new StringReader(js), bindings);
bindings.putAll(customBindings);
} catch (final ScriptException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
}
use of javax.script.ScriptException in project scheduling by ow2-proactive.
the class AbstractIModeCommand method execute.
@Override
public void execute(ApplicationContext currentContext) throws CLIException {
currentContext.setProperty(IMODE, true);
ScriptEngine engine = currentContext.getEngine();
try {
// load supported functions
engine.eval(new InputStreamReader(script()));
} catch (ScriptException error) {
throw new CLIException(CLIException.REASON_OTHER, error);
}
while (!currentContext.getProperty(TERMINATE, Boolean.TYPE, false)) {
try {
String command = readLine(currentContext, "> ");
if (command == null) {
// EOF, exit interactive shell
break;
}
engine.eval(command);
} catch (ScriptException se) {
handleError(String.format("An error occurred while executing the script:"), se, currentContext);
}
}
}
use of javax.script.ScriptException in project scheduling by ow2-proactive.
the class EvalScriptCommand method execute.
@Override
public void execute(ApplicationContext currentContext) throws CLIException {
ScriptEngine engine = currentContext.getEngine();
Writer writer = currentContext.getDevice().getWriter();
if (scriptArgs != null) {
engine.getContext().getBindings(ScriptContext.ENGINE_SCOPE).putAll(bindings(scriptArgs));
}
String script = FileUtility.readFileToString(new File(scriptPathname));
try {
engine.eval(script);
} catch (ScriptException e) {
e.printStackTrace(new PrintWriter(writer, true));
}
}
use of javax.script.ScriptException in project tomee by apache.
the class ScriptLoginModule method login.
@Override
public boolean login() throws LoginException {
File script = getScriptFile((String) this.options.get("scriptURI"));
if (script == null) {
script = getScriptFile(JavaSecurityManagers.getSystemProperty("openejb.ScriptLoginModule.scriptURI"));
if (script == null) {
script = getScriptFile(null);
}
}
if (script == null) {
throw new LoginException("No login script defined");
}
final String scriptText;
try {
scriptText = new Scanner(script).useDelimiter("\\Z").next();
} catch (final FileNotFoundException e) {
throw new LoginException("Invalid login script URI.");
}
this.userData = getUserData();
final ScriptEngineManager manager = new ScriptEngineManager();
final ScriptEngine engine = manager.getEngineByName((String) this.options.get("engineName"));
// new context for the execution of this script
final ScriptContext newContext = new SimpleScriptContext();
// creating the bidings object for the current execution
final Bindings bindings = newContext.getBindings(ScriptContext.ENGINE_SCOPE);
bindings.put("user", this.userData.user);
bindings.put("password", this.userData.pass);
final List<String> myGroups;
try {
myGroups = (List) engine.eval(scriptText, newContext);
} catch (final ScriptException e) {
throw new LoginException("Cannot execute login script. Msg: " + e.getMessage());
}
this.userData.groups.addAll(myGroups);
return true;
}
Aggregations