3
votes

I've got a Script mediator where I've set a certain value (mc.setProperty("x",1)) and immediately after the script mediator I've set a PayloadFactory mediator where I'm trying to get the value x (get-property("x")). I used Log mediators in between my mediation logic to check if the property value is set. But the value isn't set. I'm using js for Script mediator.

2

2 Answers

3
votes

I have same problem. I solved it by add call function "String" in script.

Something like -

<script language="js"><![CDATA[
    mc.setProperty("x", String(1));
]]></script>
<log level="custom">
    <property expression="get-property('x')" name="x" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
1
votes

Can you try out the following? This is possible with WSO2 ESB 5.0.0

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="TestProxy"
       startOnLoad="true"
       statistics="disable"
       trace="disable"
       transports="http,https">
   <target>
      <inSequence>
         <script language="js">mc.setProperty("x", 1);</script>
         <log level="custom">
            <property expression="get-property('x')" name="x"/>
         </log>
         <payloadFactory media-type="xml">
            <format>
               <value xmlns="">$1</value>
            </format>
            <args>
               <arg evaluator="xml" expression="get-property('x')"/>
            </args>
         </payloadFactory>
         <respond/>
      </inSequence>
   </target>
   <description/>
</proxy>