Expand my Community achievements bar.

SOLVED

RSS FEED default servlet for every page

Avatar

Level 4

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());
   }

1 Accepted Solution

Avatar

Correct answer by
Level 7

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

View solution in original post

6 Replies

Avatar

Level 4

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?

Avatar

Correct answer by
Level 7

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

Avatar

Level 4

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

Avatar

Level 4

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

Avatar

Level 10

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

Avatar

Level 9

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