RSS FEED default servlet for every page | Community
Skip to main content
Level 3
Oct 16, 2017 8:06 AM UTC
Solved

RSS FEED default servlet for every page

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.
BrijeshYadav
BrijeshYadavAccepted solution
Level 5
Oct 16, 2017 8:53 AM UTC

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
Level 10
Oct 17, 2017 5:46 AM UTC

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

Translate
smacdonald2008
Level 10
Oct 16, 2017 2:24 PM UTC

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

Translate
Level 3
Oct 16, 2017 9:57 AM UTC

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

Translate
Level 3
Oct 16, 2017 9:54 AM UTC

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

Translate
BrijeshYadav
BrijeshYadavAccepted solution
Level 5
Oct 16, 2017 8:53 AM UTC

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

Translate
Level 3
Oct 16, 2017 8:51 AM UTC

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?

Translate