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 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
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
Partner Zones AWS Cloud
by AWS Developer Relations
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
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Create Mock REST services, or Proxy REST services and mediate them, through the UltraESB

Create Mock REST services, or Proxy REST services and mediate them, through the UltraESB

Asankha Perera user avatar by
Asankha Perera
·
Jan. 21, 10 · Interview
Like (0)
Save
Tweet
Share
12.35K Views

Join the DZone community and get the full member experience.

Join For Free

The UltraESB from AdroitLogic includes full support for REST - so that uses could easily use it as a Proxy Service to front existing REST services of an enterprise. This allows the UltraESB to perform SSL decryption, HTTP basic/digest authentication etc, and then proxy the calls received from outside, safely to the real services. The UltraESB supports GET, POST, PUT, DELETE, HEAD and OPTIONS proxying, and performs 'Location' header re-writing on responses, so that the end-clients will always be directed to the proxy services as the entry point.

The UltraESB ships a sample RESTful service in ready-to-run state, and an easy to use graphical toolkit that support all forms of REST interactions. Thus it is trivial for a user to start the sample configuration, and use the ToolBox HTTP/S client to interact with the REST proxy service. A full article "RESTFul Proxy Services with the UltraESB" shows complete steps to interact with the REST service or its Proxy service interactively. Here is a full configuration for REST proxy service with the UltraESB. The Proxy service directs all REST requests to the RESTeasy sample service hosted at the http://localhost:9000/rest-services URL.

    <u:proxy id="rest-proxy">
<u:transport id="http-8280"/>
<u:target>
<u:inDestination>
<u:address type="prefix">http://localhost:9000/rest-services</u:address>
<u:property name="switchLocationHeadersTo" value="http://localhost:8280/service/rest-proxy"/>
</u:inDestination>
<u:outDestination>
<u:address type="response"/>
</u:outDestination>
</u:target>
</u:proxy>

The Mock Services support of the UltraESB allows one to easily write Mock services for REST! Mock responses maybe selected by Content Based Routing [CBR] on the request or its headers, and maybe even picked up from sample files on the file system. The article "Mock RESTfully with the UltraESB" shows how one could run the sample. Mock Service. As a reference, the following is the full configuration used to implement the Mock REST service used in the example.

    <u:proxy id="rest-mock">
<u:transport id="http-8280"/>
<u:target>
<u:inSequence>
<u:java import="org.adroitlogic.ultraesb.transport.http.*;"><![CDATA[
if ("GET".equals(msg.getMessageProperty(HttpConstants.HTTP_METHOD))) {
msg = msg.createDefaultResponseMessage();
if (msg.getDestinationURL().endsWith("customers/1")) {
Mediation.setPayloadFromFile(msg, "samples/resources/mock-response-1.xml");
} else if (msg.getDestinationURL().endsWith("customers/2")) {
Mediation.setPayloadFromFile(msg, "samples/resources/mock-response-2.xml");
} else {
Mediation.setPayloadFromFile(msg, "samples/resources/mock-response-3.xml");
}
Mediation.sendResponse(msg, 200);
} else if ("POST".equals(msg.getMessageProperty(HttpConstants.HTTP_METHOD))) {
msg = msg.createDefaultResponseMessage();
msg.addTransportHeader("Location", "http://localhost:8280/service/rest-mock/customers/1");
Mediation.sendResponse(msg, 201);
} else if ("PUT".equals(msg.getMessageProperty(HttpConstants.HTTP_METHOD))) {
msg = msg.createDefaultResponseMessage();
Mediation.sendResponse(msg, 204);
} else if ("DELETE".equals(msg.getMessageProperty(HttpConstants.HTTP_METHOD))) {
msg = msg.createDefaultResponseMessage();
Mediation.sendResponse(msg, 204);
} else {
msg.createDefaultResponseMessage();
Mediation.sendResponse(msg, 500);
}
]]></u:java>
</u:inSequence>
</u:target>
</u:proxy>

The service shows how mock responses are read from the file system and returned to the user for GET, POST, PUT and DELETE requests. The mediation within the "inSequence" though written as a Java fragment - does not need to be compiled, bundled or deployed. The UltraESB considers it as "configuration" and compiles the code at runtime into byte code and executes with extreme performance. The user may specify mediation as Java code, a Sping bean, or any JSR 233 scripting language such as Javascript, Groovy, Ruby etc.

The full article explains how one could easily start the sample, and try out the scenarios end-to-end within less than 10 minutes. REST is only one of the message formats supported by the UltraESB. It can proxy and mediate SOAP, POX, Hessian, Text, HTML or any other form of payload over HTTP/. It also allows the user to switch between any of its transports such as HTTP/S, JMS, Email, File, S/FTP, FTPS etc or even to-or-from AS2 for B2B messaging such as with EDI. Read more about it at http://adroitlogic.org. 

REST Web Protocols UltraESB

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Create Spider Chart With ReactJS
  • Top 5 Data Streaming Trends for 2023
  • Microservices Testing
  • 11 Observability Tools You Should Know

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

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: