@Test public void testFilterTransformationExecution() throws ScriptException, IOException, NoSuchMethodException, URISyntaxException { String filterFunc = resourceFileToString("filter.js"); transformationFunction = new TransformationFunction("1", filterFunc); JsonNode result = executionEngine.execute(jsonData, transformationFunction); System.out.println(result); Assert.assertTrue(result.get("stringValues").isArray()); ArrayNode arrayNode = new ArrayNode(JsonNodeFactory.instance); arrayNode.add("uuid"); arrayNode.add("number"); arrayNode.add("shortname"); arrayNode.add("longname"); arrayNode.add("agency"); Assert.assertEquals(arrayNode, result.get("stringValues")); }
@Override public ObjectNode execute(ObjectNode data, TransformationFunction transformationFunction) throws ScriptException, IOException, NoSuchMethodException { initNashornSandbox(); try { String script = wrapperScript + transformationFunction.getTransformFunction(); nashornSandbox.eval(script); Invocable sandboxedInvocable = nashornSandbox.getSandboxedInvocable(); String result = (String) sandboxedInvocable.invokeFunction(WRAPPER_FUNCTION, data.toString()); return (ObjectNode) JsonMapper.getInstance().readTree(result); } finally { ExecutorService executor = nashornSandbox.getExecutor(); executor.shutdown(); } }
NashornExecutionEngine extends AbstractExecutionEngine { @Override public ObjectNode execute(ObjectNode data, TransformationFunction transformationFunction) throws ScriptException, IOException, NoSuchMethodException { initNashornSandbox(); try { String script = wrapperScript + transformationFunction.getTransformFunction(); nashornSandbox.eval(script); Invocable sandboxedInvocable = nashornSandbox.getSandboxedInvocable(); String result = (String) sandboxedInvocable.invokeFunction(WRAPPER_FUNCTION, data.toString()); return (ObjectNode) JsonMapper.getInstance().readTree(result); } finally { ExecutorService executor = nashornSandbox.getExecutor(); executor.shutdown(); } } }
NashornExecutionEngine extends AbstractExecutionEngine { @Override public ObjectNode execute(ObjectNode data, TransformationFunction transformationFunction) throws ScriptException, IOException, NoSuchMethodException { initNashornSandbox(); try { String script = wrapperScript + transformationFunction.getTransformFunction(); nashornSandbox.eval(script); Invocable sandboxedInvocable = nashornSandbox.getSandboxedInvocable(); String result = (String) sandboxedInvocable.invokeFunction(WRAPPER_FUNCTION, data.toString()); return (ObjectNode) JsonMapper.getInstance().readTree(result); } finally { ExecutorService executor = nashornSandbox.getExecutor(); executor.shutdown(); } } NashornExecutionEngine(); }
NashornExecutionEngine extends AbstractExecutionEngine { @Override public ObjectNode execute(ObjectNode data, TransformationFunction transformationFunction) throws ScriptException, IOException, NoSuchMethodException { initNashornSandbox(); try { String script = wrapperScript + transformationFunction.getTransformFunction(); nashornSandbox.eval(script); Invocable sandboxedInvocable = nashornSandbox.getSandboxedInvocable(); String result = (String) sandboxedInvocable.invokeFunction(WRAPPER_FUNCTION, data.toString()); return (ObjectNode) JsonMapper.getInstance().readTree(result); } finally { ExecutorService executor = nashornSandbox.getExecutor(); executor.shutdown(); } } NashornExecutionEngine(); @Override ObjectNode execute(ObjectNode data, TransformationFunction transformationFunction); }
NashornExecutionEngine extends AbstractExecutionEngine { @Override public ObjectNode execute(ObjectNode data, TransformationFunction transformationFunction) throws ScriptException, IOException, NoSuchMethodException { initNashornSandbox(); try { String script = wrapperScript + transformationFunction.getTransformFunction(); nashornSandbox.eval(script); Invocable sandboxedInvocable = nashornSandbox.getSandboxedInvocable(); String result = (String) sandboxedInvocable.invokeFunction(WRAPPER_FUNCTION, data.toString()); return (ObjectNode) JsonMapper.getInstance().readTree(result); } finally { ExecutorService executor = nashornSandbox.getExecutor(); executor.shutdown(); } } NashornExecutionEngine(); @Override ObjectNode execute(ObjectNode data, TransformationFunction transformationFunction);  }