If you are using String concatenation inside Javascript mediator, as the Rhino engine ( Rhino JavaScript engine (1.74) ) has been updated in WSO2 ESB5.0.0, the same concatenation functionality worked in ESB4.9.0 will not work in ESB5.0.0. As it is a problem in Rhino Engine, to overcome the issue you need to follow the below. To get more understanding you can refer [1] also.
[1] https://www-01.ibm.com/support/docview.wss?uid=swg1JR55739
When you set up proxy as below:
[1] https://www-01.ibm.com/support/docview.wss?uid=swg1JR55739
When you set up proxy as below:
<?xml version="1.0" encoding="UTF-8"?> <proxy xmlns="http://ws.apache.org/ns/synapse" name="StringConcatenationJS" startOnLoad="true" statistics="disable" trace="disable" transports="http,https"> <target> <inSequence> <property name="STATUS" value="--------------------StringConcatenationJS Proxy Invoked-------------------"/> <script language="js">var log = mc.getServiceLog(); log.info("-----------Executing Script Mediator-------------------- "); var name = 'ajanthan'; var addres = 'batticaloa'; var cconcatenatedString = name + addres; log.info("Concatenated string: " + cconcatenatedString); mc.setProperty('concatString',cconcatenatedString);</script> <log level="custom"> <property expression="get-property('concatString')" name="Concatenated String @ Property: "/> </log> </inSequence> </target> <description/> </proxy>
You will get and Empty Result as below:
[2017-01-28 14:20:29,382] INFO - ScriptMessageContext -----------Executing Script Mediator-------------------- [2017-01-28 14:20:29,383] INFO - ScriptMessageContext Concatenated string: ajanthanbatticaloa [2017-01-28 14:20:29,387] INFO - LogMediator Concatenated String @ Property: =
To overcome this when you set the property cconcatenatedString.toString().
Updated proxy as below:
<?xml version="1.0" encoding="UTF-8"?> <proxy xmlns="http://ws.apache.org/ns/synapse" name="StringConcatenationJS" startOnLoad="true" statistics="disable" trace="disable" transports="http,https"> <target> <inSequence> <property name="STATUS" value="--------------------StringConcatenationJS Proxy Invoked-------------------"/> <script language="js">var log = mc.getServiceLog(); log.info("-----------Executing Script Mediator-------------------- "); var name = 'ajanthan'; var addres = 'batticaloa'; var cconcatenatedString = name + addres; log.info("Concatenated string: " + cconcatenatedString); mc.setProperty('concatString',cconcatenatedString.toString());</script> <log level="custom"> <property expression="get-property('concatString')" name="Concatenated String @ Property: "/> </log> </inSequence> </target> <description/> </proxy>
The Result will be:
[2017-01-28 14:27:21,679] INFO - ScriptMessageContext -----------Executing Script Mediator-------------------- [2017-01-28 14:27:21,679] INFO - ScriptMessageContext Concatenated string: ajanthanbatticaloa [2017-01-28 14:27:21,680] INFO - LogMediator Concatenated String @ Property: = ajanthanbatticaloa
Thank you. Very helpful.Keep it up
ReplyDelete