DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Is Enterprise Service Bus (ESB) Obsolete After Microservices?
  • API Development - Glossaries
  • Enterprise Integration Patterns From ESB to ESP and API
  • A Better Web3 Experience: Account Abstraction From Flow (Part 1)

Trending

  • The Ultimate Guide to API vs. SDK: What’s the Difference and How To Use Them
  • Breaking Down Silos: The Importance of Collaboration in Solution Architecture
  • Message Construction: Enhancing Enterprise Integration Patterns
  • Bad Software Examples: How Much Can Poor Code Hurt You?
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Creating Mock service in WSO2 ESB

Creating Mock service in WSO2 ESB

$$anonymous$$ user avatar by
$$anonymous$$
·
May. 22, 13 · Interview
Like (0)
Save
Tweet
Share
7.81K Views

Join the DZone community and get the full member experience.

Join For Free

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.


Web Service Enterprise service bus

Published at DZone with permission of $$anonymous$$. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Is Enterprise Service Bus (ESB) Obsolete After Microservices?
  • API Development - Glossaries
  • Enterprise Integration Patterns From ESB to ESP and API
  • A Better Web3 Experience: Account Abstraction From Flow (Part 1)

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: