Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WSO2 ESB - Unable to access properties set in script mediator in a payload mediator

Tags:

wso2

wso2-esb

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.

like image 921
StO Avatar asked Oct 28 '25 08:10

StO


2 Answers

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>
like image 61
inem88 Avatar answered Oct 30 '25 10:10

inem88


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>
like image 44
Asitha Avatar answered Oct 30 '25 09:10

Asitha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!