Package javax.script

Examples of javax.script.ScriptEngine.eval()


        jsEngine.getContext().setAttribute(ScriptEngine.FILENAME, scriptPath,
                ScriptContext.GLOBAL_SCOPE);

        try {
            LOG.info("importing transaction using script: " + scriptPath);
            jsEngine.eval(reader);
        } catch (Exception ex) {
            LOG.log(Level.SEVERE, "Error executing script number " + scriptnum
                    + " from " + scriptPath, ex);
            JOptionPane.showMessageDialog(null,
                    "Error executing user Import-Script #" + scriptnum
View Full Code Here


        perms.add(new PropertyPermission("*", "read"));
       
        ScriptEngine eng = new JsEngineInitializer().instantiate(Collections.<String>emptySet(), perms);
       
        try {
            eng.eval("java.lang.System.exit(1)");
        } catch (Exception e) {
            assertSecurityExceptionPresent(e);
        }
    }
   
View Full Code Here

        String script = "var m = require('rhq:/test-module1'); m.func1();";
       
        //first let's try to find the scripts with the default source provider...
        ScriptEngine eng = new JsEngineInitializer().instantiate(Collections.<String>emptySet(), null);
        try {
            eng.eval(script);
            fail("The module should not have been loaded using the default source provider.");
        } catch (ScriptException e) {
            //expected
        }
       
View Full Code Here

                return new InputStreamReader(src);
            }
        });

        try {
            eng.eval(script);
        } catch (ScriptException e) {
            fail("The module should have been loaded using the custom source provider. Error message: " + e.getMessage(), e);
        }
    }
   
View Full Code Here

       
        generateIndirectionMethods(initializer, eng, myObject, "myObject", "func1");
        generateIndirectionMethods(initializer, eng, myObject, "myObject", "func2");
        generateIndirectionMethods(initializer, eng, myObject, "myObject", "func3");
       
        eng.eval("func1(); func2(); func3(); func3(1, 1); func3('a', 'b'); func3(1, 1, 1);");
       
        assertTrue(myObject.functionsCalled[0], "Function func1() should have been called.");
        assertTrue(myObject.functionsCalled[1], "Function func2() should have been called.");
        assertTrue(myObject.functionsCalled[2], "Function func3() should have been called.");
        assertTrue(myObject.functionsCalled[3], "Function func3(int, int) should have been called.");
View Full Code Here

    @Test
    public void testSandbox_javascript() throws ScriptException, IOException {
        ScriptEngine sandbox = getSecuredScriptEngine();
       
        try {
            sandbox.eval("java.lang.System.exit(1);");
        } catch (Exception e) {
            assertSecurityExceptionPresent(e);
        }
       
        try {
View Full Code Here

            assertSecurityExceptionPresent(e);
        }
       
        try {
            //try hard to get to the System.exit()
            sandbox.eval(
                "cls = java.lang.Class.forName('java.lang.System');" +
                "params = java.lang.reflect.Array.newInstance(java.lang.Object, 1);" +
                "params[0] = java.lang.Integer.valueOf('1');" +
                "st = new java.beans.Statement(cls, 'exit', params);" +
                "st.execute()");
View Full Code Here

    @Test
    public void testSandbox_python() throws Exception {
        ScriptEngine sandbox = getSecuredScriptEngine();
       
        try {
            sandbox.eval("import java.lang as foo\nfoo.System.exit(1)");
        } catch (Exception e) {
            assertSecurityExceptionPresent(e);
        }
       
        try {           
View Full Code Here

            assertSecurityExceptionPresent(e);
        }
       
        try {           
            //try hard to get to the System.exit()
            sandbox.eval(
                "import java.lang as l\n" +
                "import java.lang.reflect as r\n" +
                "import java.beans as b\n" +
                "cls = l.Class.forName('java.lang.System')\n" +
                "params = r.Array.newInstance(l.Class.forName('java.lang.Object'), 1)\n" +
View Full Code Here

        //but we can't make it work perfectly either, so let's just
        //keep our fingers crossed..
        //http://www.jython.org/jythonbook/en/1.0/ModulesPackages.html#from-import-statements
        for (String pkg : packages) {
            try {
                eng.eval("from " + pkg + " import *\n");
            } catch (ScriptException e) {
                //well, let's just keep things going, this is not fatal...
                LOG.info("Python script engine could not pre-import members of package '" + pkg + "'.");
            }
        }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.