use of org.apache.bsf.xml.XMLHelper in project wso2-synapse by wso2.
the class ScriptMediator method mediateWithExternalScript.
/**
* Mediation implementation when the script to be executed should be loaded from the registry
*
* @param synCtx the message context
* @return script result
* @throws ScriptException For any errors , when compile, run the script
* @throws NoSuchMethodException If the function is not defined in the script
*/
private Object mediateWithExternalScript(MessageContext synCtx) throws ScriptException, NoSuchMethodException {
ScriptEngineWrapper sew = null;
Object obj;
try {
sew = prepareExternalScript(synCtx);
XMLHelper helper;
if (language.equalsIgnoreCase(JAVA_SCRIPT) || language.equals(NASHORN_JAVA_SCRIPT)) {
helper = xmlHelper;
} else {
helper = XMLHelper.getArgHelper(sew.getEngine());
}
ScriptMessageContext scriptMC;
scriptMC = getScriptMessageContext(synCtx, helper);
processJSONPayload(synCtx, scriptMC);
Invocable invocableScript = (Invocable) sew.getEngine();
obj = invocableScript.invokeFunction(function, new Object[] { scriptMC });
} finally {
if (sew != null) {
// return engine to front of queue or drop if queue is full (i.e. if getNewScriptEngine() spawns a new engine)
pool.offer(sew);
}
}
return obj;
}