Best way to get XML response of servlet in custom URL | Community
Skip to main content
Level 2
July 26, 2022
Solved

Best way to get XML response of servlet in custom URL

  • July 26, 2022
  • 2 replies
  • 1294 views

Hi,

I've got a servlet that returns an XML in response. Have control over registering servlet as path or resource based.

Now when I hit a custom URL like "www.sitename.com/abc/releases/result.xml"(not an existing page), the servlet should trigger and dump the XML response.

 

Approach 1: Use the logic of AEM sitemap.xml and achieve this with custom etc resource mapping and URL rewrite.

 

Any other best approaches?

 

Thanks.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Shashi_Mulugu

@vinayhegde It depends on the complexity of the business logic and frequency of date to be updated in that xml.

 

  • If it is too heavy execution and content is not too dynamic, i would prefer to run the logic offline maybe as scheduler once in a day and store the xml as physical asset in DAM path and i would point my dispatcher/rewrite rules to point to DAM location based on the public url you want to have.
  • If the content is dynamic in nature changes as and when requested, say price related etc.. no other option but to go with a servlet and execute logic at runtime.

 

2 replies

Shashi_Mulugu
Community Advisor
Shashi_MuluguCommunity AdvisorAccepted solution
Community Advisor
July 26, 2022

@vinayhegde It depends on the complexity of the business logic and frequency of date to be updated in that xml.

 

  • If it is too heavy execution and content is not too dynamic, i would prefer to run the logic offline maybe as scheduler once in a day and store the xml as physical asset in DAM path and i would point my dispatcher/rewrite rules to point to DAM location based on the public url you want to have.
  • If the content is dynamic in nature changes as and when requested, say price related etc.. no other option but to go with a servlet and execute logic at runtime.

 

Nikhil_Verma
Level 4
July 27, 2022

Agree with @shashi_mulugu .

If the XML is dynamic then you can follow the below steps to creating a custom servlet:

Create a custom servlet registered by resource type (recommended): https://aem.redquark.org/2019/07/sling-servlet-04-registration-via.html
For more understanding of how servlet by resource type works: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/how-to-configure-a-servlet-via-resource-type/td-p/404215