RSS FEED default servlet for every page | Community
Skip to main content
New Participant
October 16, 2017
Solved

RSS FEED default servlet for every page

  • October 16, 2017
  • 6 replies
  • 3057 views

Hello guys,

I want to create a RSS component for every page.

Iam not sure I am thinking the right way.

I want to write a servlet which returns xml of the actual node and give the title, the description and the modify date as RSS-XML to the user. But I don't know how to write one servlet which is called for every page under:

  • example.com/examplepage.rss.xml
  • example.com/examplepage1.rss.xml
  • example.com/examplepage2.rss.xml
  • ...

the servlet should be callable as default for every page.

How can I achieve this? Can someone point me in the right direction.

up to now I have the following servlet which renders for a specific resoureType but I am searching for a wildcard or something to call it for every path or specific root path and all of its children.

@SuppressWarnings("serial")

@SlingServlet(resourceTypes = "geometrixx/components/homepage",
   selectors = "rss",
   extensions = "xml",
   methods = "GET",
   metatype =true)

public class SimpleServlet extends SlingSafeMethodsServlet {

   @Reference
   private Repository repository;
   @Override
   protected void doGet(final SlingHttpServletRequest req,
  final SlingHttpServletResponse resp) throws ServletException, IOException {

  resp.setContentType("application/json");
   String keys[] = repository.getDescriptorKeys();
   JSONObject jsonobject = new JSONObject();
  try {

  jsonobject.put("test", "testvalue");
   } catch (JSONException e) {

  e.printStackTrace();
   }

  resp.getWriter().println(jsonobject.toString());
   }

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 BrijeshYadav

One way to add multiple resources here

@SlingServlet(

    resourceTypes = {geometrixx/components/homepage,

                               geometrixx/components/productpage,

                              geometrixx/components/articlepage

    },

   selectors = "rss", 

   extensions = "xml", 

   methods = "GET", 

   metatype =true)

/Brijesh

6 replies

MC_Stuff
New Participant
October 17, 2017

Hi tim-schwalbe​,

Make sure to proxy the request.

Try with embeding jcr:content like [1] which includes jcr:content & it works. To avoid jcr:content in the url create a proxy  example Page.feed.jsp with text from [2].

[1]    example.com/examplepage/jcr:content.rss.xml

[2]    /libs/foundation/components/primary/cq/Page/proxy.jsp

smacdonald2008
New Participant
October 16, 2017

Whats your use case - why do you want to do this?

New Participant
October 16, 2017

I found a nice article which describes how to register a servlet for every page:

Registering a Servlet for every Page in AEM | TO THE NEW Blog

New Participant
October 16, 2017

Can you also tell me the best way to access node properties from a servlet?

BrijeshYadav
BrijeshYadavAccepted solution
New Participant
October 16, 2017

One way to add multiple resources here

@SlingServlet(

    resourceTypes = {geometrixx/components/homepage,

                               geometrixx/components/productpage,

                              geometrixx/components/articlepage

    },

   selectors = "rss", 

   extensions = "xml", 

   methods = "GET", 

   metatype =true)

/Brijesh

New Participant
October 16, 2017

Okay now i changed the resourceType to my Template resourceType so I can call every page which uses this template with the selector and extension.

Is this a good approach?