Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Creating Mock service in WSO2 ESB

DZone's Guide to

Creating Mock service in WSO2 ESB

· Integration Zone
Free Resource

Today’s data climate is fast-paced and it’s not slowing down. Here’s why your current integration solution is not enough. Brought to you in partnership with Liaison Technologies.

I posted before about how to create a mock service when you have a JDK 1.6 or higher available (for the interested you can find it here). Of course there are a lot more options to mock web services (one I used often is the option supplied by SoapUI). This post shows a way to mock a web service by using a WSO2 Proxy Service.

The way to do this is by using the PayloadFactory mediator. There is also an example of its general usage here.

To use this mediator for mocking a service see the following configuration:

<proxy xmlns="http://ws.apache.org/ns/synapse" name="MyMockService" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>
         <payloadFactory>
            <format>
               <ns0:myMessage xmlns:ns0="http://www.pascalalma.net/test">
                  <ns0:address>
                     <ns0:postalcode>$1</ns0:postalcode>
                     <ns0:number>$2</ns0:number>
                  </ns0:address>
               </ns0:myMessage>
            </format>
            <args>
               <arg xmlns:sel="http://www.pascalalma.net/input" expression="//sel:postalcode"/>
               <arg xmlns:sel="http://www.pascalalma.net/input" expression="//selectie:mynumber"/>
            </args>
         </payloadFactory>
         <header name="To" action="remove"/>
         <property name="RESPONSE" value="true" scope="default" type="STRING"/>
         <send/>
      </inSequence>
   </target>
   <description></description>
</proxy>    

The important parts here are the following:

Inside the ‘format’ element of the ‘PayloadFactory’ mediator we define inline the XML message we want to use as a response on every incoming request. In this inline XML we can use the syntax ‘$1′, ‘$2′ etc to refer to arguments we define after the ‘format’ element. These ‘arg’ elements contain XPath expressions which are executed against the incoming message. This way you can make the result of the mock service a little more dynamic and that way more useful in your testcases.

The other important parts are the ‘header‘ element and the ‘property‘ element. These lines avoids the proxy to wait for a response in the outSequence which would normally be the case with a proxy service.


Is iPaaS solving the right problems? Not knowing the fundamental difference between iPaaS and iPaaS+ could cost you down the road. Brought to you in partnership with Liaison Technologies.

Topics:

Published at DZone with permission of Pascal Alma. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}