I'm getting the following error when using a script mediator in WSO2 Integration Studio 8.1.0:
ERROR {ScriptMediator} - {api:BankApi:v1.0} The script engine returned an Exception executing the external js script : Value {name ='null', keyValue ='gov:scripts/replace-null-with-hyphen.js'} function replaceNullWithDashInPayload java.lang.RuntimeException: ContentID is null
at org.apache.axiom.om.impl.llom.OMTextImpl.getDataHandler(OMTextImpl.java:391)
at org.apache.synapse.mediators.bsf.ScriptMediator.prepareExternalScript(ScriptMediator.java:494)
at org.apache.synapse.mediators.bsf.ScriptMediator.mediateWithExternalScript(ScriptMediator.java:332)
at org.apache.synapse.mediators.bsf.ScriptMediator.invokeScript(ScriptMediator.java:288)
at org.apache.synapse.mediators.bsf.ScriptMediator.mediate(ScriptMediator.java:258)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:110)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:72)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.api.Resource.process(Resource.java:342)
at org.apache.synapse.api.API.process(API.java:477)
at org.apache.synapse.api.AbstractApiHandler.apiProcessNonDefaultStrategy(AbstractApiHandler.java:107)
at org.apache.synapse.api.AbstractApiHandler.identifyAPI(AbstractApiHandler.java:127)
at org.apache.synapse.api.AbstractApiHandler.dispatchToAPI(AbstractApiHandler.java:59)
at org.apache.synapse.api.rest.RestRequestHandler.dispatchToAPI(RestRequestHandler.java:90)
at org.apache.synapse.api.rest.RestRequestHandler.process(RestRequestHandler.java:76)
at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:54)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:344)
at org.apache.synapse.core.axis2.SynapseMessageReceiver.receive(SynapseMessageReceiver.java:101)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosingRESTHandler(ServerWorker.java:376)
at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:435)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:183)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
This is the script configuration and content:
function replaceNullWithDashInPayload(mc) {
var payload = mc.getPayloadJSON();
payload = replaceNullWithDash(payload);
mc.setPayloadJSON(payload);
}
function replaceNullWithDash(obj) {
if (Array.isArray(obj)) {
for (var i in obj) {
if (Array.isArray(obj[i]) || typeof obj[i] === 'object') {
obj[i] = replaceNullWithDash(obj[i]);
}
}
} else {
for(var prop in obj) {
if (obj[prop] == null || obj[prop] == 'null'){
obj[prop] = '-';
}
if (Array.isArray(obj[prop]) || typeof obj[prop] === 'object') {
obj[prop] = replaceNullWithDash(obj[prop])
}
}
}
return obj;
}
The thing is that this is running well on another system with the same configuration. Anyone encountered this too? Any ideas on how to fix it?