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

  • API Development - Glossaries
  • Why Is REST API Architecture Gaining Popularity in the Digital Industry?
  • WSDL vs REST/JSON — The Troll Fight
  • The Evolution of Systems Integration

Trending

  • How to Migrate Vector Data from PostgreSQL to MyScale
  • Exploring the Evolution and Impact of Computer Networks
  • A Continuous Testing Approach to Performance
  • Automate Your Quarkus Deployment Using Ansible
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. REST JSON to SOAP conversion tutorial

REST JSON to SOAP conversion tutorial

Francois Lascelles user avatar by
Francois Lascelles
·
Aug. 04, 11 · News
Like (0)
Save
Tweet
Share
35.25K Views

Join the DZone community and get the full member experience.

Join For Free

i often get asked about ‘rest to soap’ transformation use cases these days. using an soa gateway like securespan to perform this type of transformation at runtime is trivial to setup. with securespan in front of any existing web service (in the dmz for example), you can virtualize a rest version of this same service. using an example, here is a description of the steps to perform this conversion.

imagine the geoloc web service for recording geographical locations. it has two methods, one for setting a location and one for getting a location. see below what this would look like in soap.

request:

<?xml version="1.0" encoding="utf-8"?>
<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:body>
<geo:getposition xmlns:geo="http://test.layer7tech.com/geolocws">
<geo:trackerid>34802398402</geo:trackerid>
</geo:getposition>
</soapenv:body>
</soapenv:envelope>

response:

<?xml version="1.0" encoding="utf-8"?>
<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:body>
<geo:getpositionres xmlns:geo="http://test.layer7tech.com/geolocws">
<geo:latitude>52.37706</geo:latitude>
<geo:longitude>4.889721</geo:longitude>
</geo:getpositionres>
</soapenv:body>
</soapenv:envelope>

request:

<?xml version="1.0" encoding="utf-8"?>
<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:body>
<geo:setposition xmlns:geo="http://test.layer7tech.com/geolocws">
<geo:trackerid>34802398402</geo:trackerid>
<geo:latitude>52.37706</geo:latitude>
<geo:longitude>4.889721</geo:longitude>
</geo:setposition>
</soapenv:body>
</soapenv:envelope>

response:

<?xml version="1.0" encoding="utf-8"?>
<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:body>
<geo:setpositionres xmlns:geo="http://test.layer7tech.com/geolocws">ok</geo:setpositionres>
</soapenv:body>
</soapenv:envelope>

here is the equivalent rest target that i want to support at the edge. payloads could be xml, but let’s use json to make it more interesting.

get /position/34802398402

http 200 ok
content-type: text/json

{
'latitude' : 52.37706
'longitude' : 4.889721
}
post /position/34802398402
content-type: text/json

{
'latitude' : 52.37706
'longitude' : 4.889721
}

http 200 ok

ok

now let’s implement this rest version of the service using securespan. i’m assuming that you already have a securespan gateway deployed between the potential rest requesters and the existing soap web service.

first, i will create a new service endpoint on the gateway for this service and assign anything that comes at the uri pattern /position/* to this service. i will also allow the http verbs get and post for this service.

rest geoloc service properties

next, let’s isolate the resource id from the uri and save this as a context variable named ‘trackerid’. we can use a simple regex assertion to accomplish this. also, i will branch on the incoming http verb using an or statement. i am just focusing on get and post for this example but you could add additional logic for other http verbs that you want to support for this rest service.

regex for rest service resource identification

policy branching for get vs post

for get requests, the transformation is very simple, we just declare a message variable using a soap skeleton into which we refer to the trackerid variable.

soap request template

this soap message is routed to the existing web service and the essential elements are isolated using xpath assertions.

processing soap response

the rest response is then constructed back using a template response.

template json response

a similar logic is performed for the post message. see below for the full policy logic.

complete policy

you’re done for virtualizing the rest service. setting this up with securespan took less than an hour, did not require any change on the existing soap web service and did not require the deployment of an additional component. from there, you would probably enrich the policy to perform some json schema validation , some url and query parameter validation, perhaps some authentication, authorization , etc.

JSON SOAP REST Web Protocols Web Service

Published at DZone with permission of Francois Lascelles, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • API Development - Glossaries
  • Why Is REST API Architecture Gaining Popularity in the Digital Industry?
  • WSDL vs REST/JSON — The Troll Fight
  • The Evolution of Systems Integration

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: