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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
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

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Unlocking the Benefits of a Private API in AWS API Gateway
  • Building a Scalable ML Pipeline and API in AWS
  • Container Checkpointing in Kubernetes With a Custom API
  • Serverless NLP: Implementing Sentiment Analysis Using Serverless Technologies

Trending

  • Build Your First AI Model in Python: A Beginner's Guide (1 of 3)
  • Analyzing Techniques to Provision Access via IDAM Models During Emergency and Disaster Response
  • Unlocking the Benefits of a Private API in AWS API Gateway
  • Role of Cloud Architecture in Conversational AI
  1. DZone
  2. Data Engineering
  3. Databases
  4. Our Tryst With AWS API Gateway and XML Transformation

Our Tryst With AWS API Gateway and XML Transformation

See a solution to the issue of not being able to transform XML to JSON with AWS API Gateway.

By 
Arvind singh user avatar
Arvind singh
·
Sep. 11, 19 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
24.7K Views

Join the DZone community and get the full member experience.

Join For Free

Image title

AWS API Gateway

Unfortunately, the world has not yet upgraded itself to JSON, and a considerable amount of the world still uses XML-based SOAP services.

You might also enjoy:  Payload Transformation: JSON to XML

Background

Our tryst with XML and AWS API Gateway began when our client wanted to replace a Java-based middle layer application, which was proxying legacy SOAP services with AWS API Gateway. The middle layer application was calling the SOAP services using Apache axis2 client. Our use case looked like this:

  • Consumers will communicate with Gateway using only JSON.
  • Gateway will communicate with legacy backend SOAP services only using application/XML.

The Problem

At first, everything looked fine. We quickly integrated the backend SOAP service from Gateway. But then, we realized some great limitations of AWS API GW for our use case:

  • It does not support XML to JSON transformation.
  • It does not parse XML content to modify it, though velocity scripting language provides a great deal of flexibility to modifying JSON.

With the limitations provided, all the great capabilities of AWS API Gateway were not enough for us.

Possible Solutions

  1. Use Lambda — Call SOAP service and data transformation in lambda and integrate it into GW. We found quite a few blogs suggesting using Lambda for this kind of transformation. Though lambdas are great, in our use case, it meant:

    • Write code for data transformation for 100+ backend SOAP services. Maintaining JSON to SOAP request transformation for every service at Lambda meant more code upkeep and not leveraging the power of GW.

    • Also, AWS API GW does not support sending XML in raw format to lambda. XML can be put into a JSON by escaping all spaces and double quotes making JSON difficult to manage and understand.

With the approach looking difficult, we landed on the below solution.

Actual Solution

Beanstalk to the Rescue

We created a generic POST type REST service that accepts application/XML and:

  • Calls a SOAP service using Spring Boot and Apache HTTP client.
  • Converts the response SOAP response from the backend service to JSON, using Jackson fasterxml.

We deployed this service on a beanstalk. Luckily, we had other applications on beanstalk, and adding another service was not a roadblock for us.

@PostMapping(path="generic/rest")
       public ResponseEntity<?> getBusinessValue(@RequestBody String soapRequest, @PathVariable("service") String service) throws ClientProtocolException, IOException {
              HttpClient client = HttpClients.custom().build();
              HttpEntity httpEntity = new StringEntity(soapRequest);
              HttpPost postRequest = new HttpPost(service_path);
              postRequest.setEntity(httpEntity);
              HttpResponse httpResponse = client.execute(postRequest);
              HttpEntity responseEntity = httpResponse.getEntity();
              String entiryString = EntityUtils.toString(responseEntity);
              JsonNode response = fetchFromSoapResponse(entiryString);
           return new ResponseEntity<>(response, responseHeaders, HttpStatus.OK);
       }

       public static JsonNode fetchFromSoapResponse(String xmlString) throws IOException {
              XmlMapper xmlMapper = new XmlMapper();
              JsonNode node = xmlMapper.readTree(xmlString.getBytes());
              return node;
       }

Our solution looked like:

Beanstalk solution

GW accepts the JSON, and using the mapping template transforms the JSON into XML. GW integrates the above-mentioned REST Service deployed on beanstalk with the transformed XML as payload. This beanstalk does the magic of calling the backend SOAP service and converts the SOAP response to JSON. GW receives this JSON and passes it back to the consumers.

The following is a sample model:

The following is the sample mapping transformation of XML, which is sent to a POST type REST service deployed on beanstalk:

The following response is returned by GW:

Conclusion

The solution we used is no silver bullet, but given the limitations provided by AWS API Gateway, this is what we could offer.

Further Reading

API Gateway to the Rescue

XML API AWS

Opinions expressed by DZone contributors are their own.

Related

  • Unlocking the Benefits of a Private API in AWS API Gateway
  • Building a Scalable ML Pipeline and API in AWS
  • Container Checkpointing in Kubernetes With a Custom API
  • Serverless NLP: Implementing Sentiment Analysis Using Serverless Technologies

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!