Monday, October 7, 2013

Writing a Mock Service using WSO2 ESB

The following is WSO2 ESB configuration which will allow sending a mock response back to its caller.

<proxy xmlns="http://ws.apache.org/ns/synapse"
      name="testMockService"
      transports="https,http"
      statistics="disable"
      trace="disable"
      startOnLoad="true">
  <target>
     <inSequence>
        <log level="custom">
           <property name="MockService" value="Service Invoked"/>
        </log>
        <log level="full"/>
        <payloadFactory>
           <format>
               <response>
                    <response1>Sample Test Response</response1>
                    <info>http://www.wso2.com</info>
                 </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>

Note the following characteristics of the configuration,


      <payloadFactory>
           <format>
               <response>
                    <response1>Sample Test Response</response1>
                    <info>http://www.wso2.com</info>
                 </response>
           </format>
           <args/>
        </payloadFactory>


The above configuration snippet will allow constructing a new payload which should be sent, the xml elements listed between the <format/> tag will construct the new payload.

Note the following three properties,


        <header name="To" action="remove"/>
        <property name="RESPONSE" value="true" scope="default" type="STRING"/>
        <property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>

The above will allow the message to be set back to be transmitted to the caller who sent the message,

using the <send /> will result in sending the constructed message back to the caller.  







2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hi, I have a simple question.
    Is WSO2 able to respond a specific message based on the request message?
    For instance,
    if tagA contains value "123", respond tagZ has value "ABC".
    else,
    if tagA contains value "456", respond tagZ has value "DEF".

    Thanks in advance!

    ReplyDelete