Uploaded image for project: 'Infinispan'
  1. Infinispan
  2. ISPN-6413

cache and marshaller are not passed to javascript in case of inner script running

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Minor
    • Resolution: Rejected
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Tasks
    • Labels:
      None
    • Workaround Description:
      Hide

      Workaround is to get the cache and marshaller from cacheManager.

      Show
      Workaround is to get the cache and marshaller from cacheManager.

      Description

      The cache and marshaller objects are not passed to javascript when it is run from another javascript.

      //testInnerScriptCall.js
      //mode=local,language=javascript,parameters=[a]
      var TaskContext = Java.type("org.infinispan.tasks.TaskContext")
      cache.put("processValue", "script1");
      
      scriptingManager.runScript("testExecWithoutProp.js");
      cache.get("processValue");
      
      
      //testExecWithoutProp.js
      // mode=local,language=javascript
      var val = cache.get("processValue");
      cache.put("processValue", val + ":additionFromJavascript");
      

      This code gives the following exception:

      org.infinispan.commons.CacheException: ISPN026003: Script execution error
      
      	at org.infinispan.scripting.impl.ScriptingManagerImpl.execute(ScriptingManagerImpl.java:206)
      	at org.infinispan.scripting.impl.LocalRunner.runScript(LocalRunner.java:19)
      	at org.infinispan.scripting.impl.ScriptingManagerImpl.runScript(ScriptingManagerImpl.java:181)
      	at org.infinispan.scripting.impl.ScriptingManagerImpl.runScript(ScriptingManagerImpl.java:143)
      	at jdk.nashorn.internal.scripts.Script$36$\^eval\_.:program(<eval>:6)
      	at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:640)
      	at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:228)
      	at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
      	at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:418)
      	at jdk.nashorn.api.scripting.NashornScriptEngine.access$300(NashornScriptEngine.java:73)
      	at jdk.nashorn.api.scripting.NashornScriptEngine$3.eval(NashornScriptEngine.java:511)
      	at javax.script.CompiledScript.eval(CompiledScript.java:92)
      	at org.infinispan.scripting.impl.ScriptingManagerImpl.execute(ScriptingManagerImpl.java:198)
      	at org.infinispan.scripting.impl.LocalRunner.runScript(LocalRunner.java:19)
      	at org.infinispan.scripting.impl.ScriptingManagerImpl.runScript(ScriptingManagerImpl.java:181)
      	at org.infinispan.scripting.ScriptingTest.testScriptCallFromJavascript(ScriptingTest.java:126)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:497)
      	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
      	at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
      	at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
      	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
      	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
      	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
      	at org.testng.TestRunner.privateRun(TestRunner.java:767)
      	at org.testng.TestRunner.run(TestRunner.java:617)
      	at org.testng.SuiteRunner.runTest(SuiteRunner.java:348)
      	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:343)
      	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:305)
      	at org.testng.SuiteRunner.run(SuiteRunner.java:254)
      	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
      	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
      	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
      	at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
      	at org.testng.TestNG.run(TestNG.java:1057)
      	at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
      	at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:122)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:497)
      	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
      Caused by: javax.script.ScriptException: ReferenceError: "cache" is not defined in <eval> at line number 2
      	at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:467)
      	at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:423)
      	at jdk.nashorn.api.scripting.NashornScriptEngine.access$300(NashornScriptEngine.java:73)
      	at jdk.nashorn.api.scripting.NashornScriptEngine$3.eval(NashornScriptEngine.java:511)
      	at javax.script.CompiledScript.eval(CompiledScript.java:92)
      	at org.infinispan.scripting.impl.ScriptingManagerImpl.execute(ScriptingManagerImpl.java:198)
      	... 43 more
      Caused by: <eval>:2 ReferenceError: "cache" is not defined
      	at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57)
      	at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:319)
      	at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:291)
      	at jdk.nashorn.internal.objects.Global.__noSuchProperty__(Global.java:1432)
      	at jdk.nashorn.internal.scripts.Script$35$\^eval\_.:program(<eval>:2)
      	at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:640)
      	at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:228)
      	at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
      	at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:418)
      	... 47 more
      

      The test for this javascript is:

      public void testScriptCallFromJavascript() throws Exception {
            String result = (String) scriptingManager.runScript("testInnerScriptCall.js",
                    new TaskContext().cache(cacheManager.getCache("test_cache")).addParameter("a", "ahoj")).get();
      
            assertEquals("script1:additionFromJavascript", result);
         }
      

      The same error is given for marshaller. The issue appears for both simple use as well as for execution over hotrod-client.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  NadirX Tristan Tarrant
                  Reporter:
                  amanukyan Anna Manukyan
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  1 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: