Mohit Jagtiani
Mohit Jagtiani

Reputation: 1

How to Print all properties set in property mediator in WSO2?

In WSO2 ESB, I wish to print all properties set during the service chain in property mediators at the end of sequence in logs. Is there any convenient way of doing so without know name of the properties?

Thanks

Upvotes: 0

Views: 1004

Answers (2)

tmoasz
tmoasz

Reputation: 1340

There is simpler way, than implement custom class mediator. You can use Script mediator for that and print all the properties with values from message context using code like below. It is working on WSO2EI 6.6.0 and on WSO2ESB 4.9.0

<script language="js"><![CDATA[var keySet = mc.getPropertyKeySet();
        var i = 1;
        var it = keySet.iterator();       
       while(it.hasNext()){
         var prop = it.next();
         java.lang.System.out.println(i + ": " + prop + " = " + mc.getProperty(prop));
         i++;
    }]]></script>

Update: I discovered that, on linux system the System.out.println doesnt work well, so you can use mc.getServiceLog() method to get logger for printing the information

<script language="js"><![CDATA[
       var keySet = mc.getPropertyKeySet();
       var i = 1;
       var it = keySet.iterator();
       var log = "\n\r";
       while(it.hasNext()){
         var prop = it.next();
         log += i + ": " + prop + " = " + mc.getProperty(prop)+"\n\r";
         i++;
    }
    mc.getServiceLog().info(log);
]]></script>

Upvotes: 5

Pavan Andhukuri
Pavan Andhukuri

Reputation: 1617

I don't see a direct way of doing this. One work around I found is to write a custom class mediator where you can get the property keyset as part of the message context.

enter image description here

Upvotes: 1

Related Questions