Search code examples
wso2wso2-esbwso2-api-managerwso2-enterprise-integrator

How to perform Arithmetic Operation in wso2 7.2.0 sequence mediator in mi server 4.0.0


Currently I was trying to fetch the Long values from database and use it my sequence and need to update it back to the data base by Incrementing by 1, but in wso2 I was not able to achieve that by adding the property and performing addition. I tried with Long dataype and integer as well it was not working. I need to update same to my DB as an Integer datatype. I was trying with script mediator with js it was giving as excepted response.

<property name="count" scope="default" type="INTEGER" value="10"/>
<property name="increment" scope="default" type="INTEGER" value="1"/>
<property expression="$ctx:count + $ctx:increment" name="result" scope="default" type="INTEGER"/>
<log>
  <property expression="$ctx:result" name="result"/>
</log>

Can anyone please help me out to fix this?


Solution

  • Here is how you can do this.

    <?xml version="1.0" encoding="UTF-8"?>
    <api context="/hell0" name="HelloWorld" statistics="enable" trace="enable" xmlns="http://ws.apache.org/ns/synapse">
        <resource methods="GET">
            <inSequence> 
                <property name="initial" scope="default" type="STRING" value="10"/>
                <property name="incre" scope="default" type="STRING" value="1"/>
                <property name="incremented" expression="number($ctx:initial) + number($ctx:incre)" type="STRING"/>
                <property name="intVal" expression="fn:substring-before($ctx:incremented, '.')" type="INTEGER"/>
                <log level="custom">
                    <property name="Ini" expression="$ctx:initial"/>
                    <property name="Incremented" expression="$ctx:incremented"/>
                    <property name="Int" expression="$ctx:intVal"/>
                </log>
                <respond/>
            </inSequence>
            <outSequence/>
            <faultSequence/>
        </resource>
    </api>