Thursday, June 25, 2015

How to add a thread sleep to a Proxy Service

Here i am going to provide you a example on how we can create a mock service with WSO2 ESB and adding a sleep to that service.

In order to do that we need to use ;

  1. Payload Factory mediator to create the mock response
  2. script mediator to do a thread sleep
Here is the simple mock service proxy with a thread sleep.

<proxy xmlns=""
            <property name="===Before sleep===" value="===Before sleep==="/>
         <script language="js">java.lang.Thread.sleep(75000);</script>
            <property name="===After sleep===" value="===After sleep==="/>
         <payloadFactory media-type="xml">
               <Response xmlns="">
         <header name="To" action="remove"/>
         <property name="RESPONSE" value="true" scope="default" type="STRING"/>
         <property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>

I have used the blog of miyuru [1] to create this.


1 comment:

  1. If it is needed to have a thread sleep with a random number between 5000 to 20000, We can use following java script for that.

    var sleepTime = Math.ceil(Math.random() * 15000) + 5000;
    print("Sleeping "+ sleepTime + "ms");