RESTifying SOAP Service Using Kumologica
Building a REST-based interface for your existing SOAP service and deploying as a serverless integration flow using Kumologica.
Join the DZone community and get the full member experience.
Join For FreeSOAP (Simple Object Access Protocol) is a standards-based web services access protocol that has been ruling the integration world for a long time. SOAP-based web services were the de facto standard for SOA (Service Oriented Architecture). As the architecture moved from SOA to Microservices the enterprise started embracing the new philosophy from Roy Fielding, which we call today REST (Representational State Transfer). REST is an architectural style that relies on HTTP protocol without any support of higher level protocol like SOAP.
Below are major reasons for the popularity and motivation for moving from SOAP to REST:
1. It was easy to represent any enterprise entity CRUD operations using REST principles as it uses HTTP protocol resource and methods.Ex: CRUD operation on database table named “Customer” can be represented as GET /customer, PUT /customer, DELETE /customer.
2. REST is relying on HTTP protocol directly rather than having a higher-level protocol on top of it (like in the case of SOAP). This reduces the network footprint during service invocation.
Ex: For retrieving “customer” data from a database we use GET /customer/<<customerid>> whereas in the case of SOAP, we need a SOAP XML payload, which is sent to the server as HTTP POST call.
3. SOAP can only work with XML whereas REST standard permits different data formats such as Plain text, HTML, XML, JSON, etc.
SaaS or cloud-native-based platforms mostly use REST endpoints as the standard interfacing mechanism, be it for exposing the product features, or for enabling webhooks based integration. In order for integrating these platforms with the legacy systems running on enterprises that use SOAP-based interfaces, it becomes difficult and hence we need RESTify the existing SOAP services.
In this article, we will show you how easy it is to RESTify your SOAP service using Kumologica.
Use Case
We have SOAP based calculator web service hosted by a third party service provider (http://www.dneonline.com/calculator.asmx?WSDL). The service provides add, divide, multiply, and subtract operations. This service needs to be RESTified for client consumption. The REST operations should be represented as given below.
Add operation
[GET] /calculator/add/1/2
subtract operation
xxxxxxxxxx
[GET] /calculator/sub/1/2
Prerequisites
- Kumologica designer installed in your machine. https://kumologica.com/download.html
- Able to access the WSDL endpoint http://www.dneonline.com/calculator.asmx?WSDL
Implementation
- Open Kumologica Designer, click the Home button, and choose to Create New Kumologica Project.
- Enter the name (for example CalculatorFlow), select directory for the project, and switch Source into From Existing Flow…
- Copy and Paste the following flow
- Press the Create Button
You should be seeing the flow as given below on the designer canvas.
Understanding the Flow
Add Flow
- GET /add is the EventListener node. It is configured to have the EventSource as Amazon API gateway. The node will have the following configuration.
xxxxxxxxxx
verb: GET
URL : /calculator/add/:num1/:num2
2. Log is the Logger node to print the message in Amazon CloudWatch on entry of the flow.
xxxxxxxxxx
Message: 'Request received ' & msg.header.event.Records[0].pathParameters.num1 & msg.header.event.Records[0].pathParameters.num2
3. Set-Property is the property node which is configured to prepare the payload to be send to the SOAP service. We will be using JSONata expression option from the drop down to set the payload.
xxxxxxxxxx
Rules
Set
msg.payload
to
{ "intA" : msg.header.event.Records[0].pathParameters.num1, "intB" : msg.header.event.Records[0].pathParameters.num2 }
4. Add is the SOAP node which will be invoking the SOAP service to add given two numbers and provide the result.
xxxxxxxxxx
WSDL Url: http://www.dneonline.com/calculator.asmx
Method: Add
Timeout: 10000
Security: None
5. Success is the EventListener End node, the final node to complete the flow.
xxxxxxxxxx
Status Code : 200
Content-Type : application/json
Payload : msg.payload
Subtraction flow
1. GET /sub is the EventListener node. It is configured to have the EventSource as Amazon API gateway. The node will have the following configuration.xxxxxxxxxx
verb: GET
URL : /calculator/sub/:num1/:num2
2. Log is the Logger node to print the message in Amazon CloudWatch on entry of the flow.
xxxxxxxxxx
Message: 'Request received ' & msg.header.event.Records[0].pathParameters.num1 & msg.header.event.Records[0].pathParameters.num2
3. Set-Property is the property node which is configured to prepare the payload to be send to the SOAP service. We will be using JSONata expression option from the drop down to set the payload.
xxxxxxxxxx
Rules
Set
msg.payload
to
{ "intA" : msg.header.event.Records[0].pathParameters.num1, "intB" : msg.header.event.Records[0].pathParameters.num2 }
4. Add is the SOAP node which will be invoking the SOAP service to add given two numbers and provide the result.
xxxxxxxxxx
WSDL Url: http://www.dneonline.com/calculator.asmx
Method: Subtract
Timeout: 10000
Security: None
5. Success is the EventListener End node, the final node to complete the flow.
xxxxxxxxxx
Status Code : 200
Content-Type : application/json
Payload : msg.payload
Deployment
- Select CLOUD tab on the right panel of Kumologica designer, select your AWS Profile.
- Set the Memory to 512mb and Timeout as 20 seconds.
- Go to “Trigger” section under cloud tab and select the Amazon API Gateway trigger.
Try It
- Invoke the following endpoint using any REST client of your choice.
xxxxxxxxxx
https://<<gateway instance id>>.execute-api.ap-southeast-2.amazonaws.com/test//calculator/add/1/2
You should get the response as given below:
xxxxxxxxxx
{
"AddResult" : 3
}
Opinions expressed by DZone contributors are their own.
Comments