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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Spring Boot - How To Use Native SQL Queries | Restful Web Services
  • How to Consume REST Web Service (GET/POST) in Java 11 or Above
  • Breaking Up a Monolithic Database with Kong
  • RESTful Web Services: How To Create a Context Path for Spring Boot Application or Web Service

Trending

  • Agentic Systems and Design Patterns
  • Building a Software Factory With AI Agents and Workflows
  • AI-Era Cybersecurity, Part 1: Mapping Glasswing, Daybreak, Lightwell and the Tools Racing to Find and Fix Bugs
  • AI Coding Agent Guardrails: Finding Gaps in Tool Permissions

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. REST JSON to SOAP conversion tutorial

REST JSON to SOAP conversion tutorial

By 
Francois Lascelles
·
Aug. 04, 11 · News
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
37.8K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Spring Boot - How To Use Native SQL Queries | Restful Web Services
  • How to Consume REST Web Service (GET/POST) in Java 11 or Above
  • Breaking Up a Monolithic Database with Kong
  • RESTful Web Services: How To Create a Context Path for Spring Boot Application or Web Service

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook