RhinoPipe extends FixedForwardPipe { @Override public PipeRunResult doPipe(Message message, IPipeLineSession session) throws PipeRunException { String eol = System.getProperty("line.separator"); if (message==null || message.isEmpty()) { if ((StringUtils.isEmpty(fileInput)) && inputString==null && isLookupAtRuntime()) { throw new PipeRunException(this,getLogPrefix(session)+"No input specified anywhere. No string input, no file input and no previous pipe input"); } } if (StringUtils.isNotEmpty(getFileName()) && isLookupAtRuntime()) { URL resource = null; try { resource = ClassUtils.getResourceURL(getConfigurationClassLoader(), getFileName()); } catch (Throwable e) { throw new PipeRunException(this,getLogPrefix(session)+"got exception searching for ["+getFileName()+"]", e); } if (resource==null) { throw new PipeRunException(this,getLogPrefix(session)+"cannot find resource ["+getFileName()+"]"); } try { fileInput = Misc.resourceToString(resource, SystemUtils.LINE_SEPARATOR); } catch (Throwable e) { throw new PipeRunException(this,getLogPrefix(session)+"got exception loading ["+getFileName()+"]", e); } } if (getParameterList()!=null) { ParameterValueList pvl; try { pvl = getParameterList().getValues(message, session); } catch (ParameterException e) { throw new PipeRunException(this,getLogPrefix(session)+"exception extracting parameters",e); } for (int i=0; i<pvl.size(); i++) { ParameterValue pv = pvl.getParameterValue(i); paramsInput = pv.asStringValue("") + eol + paramsInput ; } } String javascriptcode = "Packages.java;" + eol; if (fileInput != null) { javascriptcode = javascriptcode + fileInput; } if (paramsInput != null) { javascriptcode = paramsInput + eol + javascriptcode; } String stringResult = (String) javascriptcode; stringResult = "INPUTSTREAM used in case of ERROR" + eol + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + eol + stringResult; Context cx = Context.enter(); Scriptable scope = cx.initStandardObjects(); if(isDebug()) { log.debug("debug active"); cx.setLanguageVersion(Context.VERSION_1_2); cx.setGeneratingDebug(true); } String jsResult = ""; try { cx.evaluateString(scope, javascriptcode, "jsScript", 1, null); Function fct = (Function) scope.get(jsfunctionName, scope); Object result = fct.call(cx, scope, scope, new Object[] { message.asObject() }); jsResult = (String) Context.jsToJava(result, String.class); if (isDebug() && log.isDebugEnabled()) { log.debug(getLogPrefix(session)+"jsResult ["+ jsResult+"]"); } } catch (EcmaError ex) { throw new PipeRunException(this, "org.mozilla.javascript.EcmaError -> ", ex); } finally { Context.exit(); } if ( jsResult != null) { stringResult =jsResult; } if (StringUtils.isEmpty(getSessionKey())) { return new PipeRunResult(getForward(), stringResult); } else { session.put(getSessionKey(), stringResult); return new PipeRunResult(getForward(), message); } }  @Override void configure(); @Override PipeRunResult doPipe(Message message, IPipeLineSession session); @IbisDoc({"when set <code>true</code> or set to something else then \"true\", (even set to the empty string), the debugging is not active", "true"}) void setDebug(boolean b); boolean isDebug(); @IbisDoc({"name of the file containing the Java-script Functions as base input", ""}) void setFileName(String fileName); String getFileName(); @IbisDoc({"The name of the function in the java-script library to run", ""}) void setjsfunctionName(String jsfunctionName); String getjsfunctionName(); @IbisDoc({"The arguments to run the function in the java-script library to run", ""}) void setjsfunctionArguments(String jsfunctionArguments); String getjsfunctionArguments(); @IbisDoc({"when set <code>true</code>, the lookup of the file will be done at runtime instead of at configuration time", "false"}) void setLookupAtRuntime(boolean b); boolean isLookupAtRuntime(); void setSessionKey(String newSessionKey); String getSessionKey();  }
@Test public void testDoPipe() throws Exception { pipe.setFileName(fileName); pipe.setjsfunctionName("giveNumber"); pipe.setjsfunctionArguments("3"); pipe.configure(); PipeRunResult res = doPipe(pipe, "3", session); assertEquals("9", res.getResult().asString()); }