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="http://ws.apache.org/ns/synapse"
       name="MyMockProxy"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <log>
            <property name="===Before sleep===" value="===Before sleep==="/>
         </log>
         <script language="js">java.lang.Thread.sleep(75000);</script>
         <log>
            <property name="===After sleep===" value="===After sleep==="/>
         </log>
         <payloadFactory media-type="xml">
            <format>
               <Response xmlns="">
                  <status>OK</status>
                  <code>1</code>
               </Response>
            </format>
            <args/>
         </payloadFactory>
         <header name="To" action="remove"/>
         <property name="RESPONSE" value="true" scope="default" type="STRING"/>
         <property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
         <send/>
      </inSequence>
   </target>
   <description/>
</proxy>

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

[1] http://miyurudw.blogspot.com/2012/08/how-to-create-simple-mock-services.html

No comments:

Post a Comment