Friday, August 15, 2014

Determining the size of a SOAP message inside a proxy service of WSO2 ESB

Below are two methods that can be used to determine the SOAP message size inside a WSO2 ESB proxy service.

Method 1 - Using script mediator

you can use the scrip mediator to find the size of the complete message. Following is example how you can do it,

 <script language="js">var msgLength = mc.getEnvelopeXML().toString().length;
         mc.setProperty("MSG_LENGTH", msgLength);</script>

<log level="custom">
        <property name="MSG_LENGTH" expression="get-property('MSG_LENGTH')"/>

In this sample it gets the string length of message, and assign the value to a property. And then read the value from outside the script mediator and log it.

Also you can only get the length of the payload of the message by  calling mc.getPayloadXML() inside script mediator.

Refer [1] for more information on script mediator.

Method 2 - Read the Content-Length header

Note that this method can be only used if the header is since it's not a required header. Value of the Content-Length header can be read as follows,

<property name="Lang" expression="get-property('transport', 'Content-Length')"/>

Please reply if you have any alternative or better methods other than these to find the SOAP message size inside a proxy service.