I'm trying to convert incoming encoded(RSA) string values to UTF-8 in the WSO2 EI 6.6.0 Script Mediator mediator.
Incoming Request:
{
"result": {
"message": ".eJwdy00OwiAQBtC7zFqS4Ufg8zLNUIaGDZjaxoXx7ja-_fvQc751X3qlB2Wp4kKCU47BZy4A7pa9uuitqNKN5t63PuToY1vO87-wri02gSlSiwloMKhcDZxoSClDAl-zj9exjHkFy0zfH5pUI3w.YfvMdQ.GcmMQuY3BN33JATAfFB3ZyeXO8U"
}
}
By using script mediator trying to convert above message content into utf-8.
Code:
<property expression="json-eval($.result.message)" name="input" scope="default" type="STRING"/>
<script language="js"><![CDATA[var id = parseInt(mc.getProperty("input"));
var encoded_id = utf8.encode(id);
mc.setProperty("encoded_id", encoded_id );]]></script>
<log level="custom">
<property expression="get-property('encoded_id')" name="encoded_id"/>
</log>
Facing below error:
[2022-02-07 13:05:32,279] ERROR {ScriptMediator} - {api:utf8enc} The script engine returned an error executing the inlined js script function mediate com.sun.phobos.script.util.ExtendedScriptException: org.mozilla.javascript.EcmaError: ReferenceError: "utf8" is not defined. (<Unknown Source>#2) in <Unknown Source> at line number 2
May I know the way to convert the encoded value to UTF-8 by using javascript functionality?
Note: expecting to shorten the above lengthy value(substring shouldn't be used here) after convert it into utf-8?