Handle Dynamic URL in CQ | Community
Skip to main content
October 16, 2015
Solved

Handle Dynamic URL in CQ

  • October 16, 2015
  • 9 replies
  • 3233 views

We need to handle Dynamic URL to generate XML based on users request. URL: localhost:4502/feed/[search-term].xml

Ex: localhost:4502/feed/webinar.xml

It should return an xml, which will be generated by system based on search-term mentioned in the URL.

How can we handle such request? I've tried using servlet but it seems sling servlet doesn't support wildcards in the sling.servlet.paths.

Thanks,

Punit Jindal

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 PaulMcMahon

Have you included the XML extension in you script name? .html is the default extension so you don't need to include it in script names, but when you need to support other script names they need to be included in the extension. So for example rather than just webinar.jsp you need to name your script webinar.xml.jsp. 

9 replies

joerghoh
Adobe Employee
Adobe Employee
October 16, 2015

A similar approach to the one orotas mentioned: Do not use selectors, but a suffix, then you could create URLs like http://localhost/feed.xml/searchterm; the implementation is quite identical to the use of selectors, but it might give you some more flexibility.

Jörg

Level 8
October 16, 2015

One approach I know will work is create a page at the URL you want to use and then pass the search term in as with a selector or a query string. The template you case your page off of could be implemented as a servlet - which would potentially be cleaner given you want to generate XML. 

October 16, 2015

Hi orotas,

I tried using selectors.

URL: "localhost:4502/feed/rss.webinar.html"

Selectors work alright when extension is .html. But, when we use .xml (which is acutally required) instead of .html, selectors do not find the resource.

Note: localhost:4502/feed/rss.xml displays the resource.

Any idea?

joerghoh
Adobe Employee
Adobe Employee
October 16, 2015

Pjindal,

how does your code look like? It should work irrespective of the extension.

Jörg

October 16, 2015

Hi Jörg,

As suggested, I created a page under /content/<site name>/us/en/public/test.

I am able to access the page using: http://localhost:4502/content/<site name>/us/en/public/test.webinar.html.

and http://localhost:4502/content/<site name>/us/en/public/test.xml.

But when I include selector in the 2nd URL, it doesn't return the page.

http://localhost:4502/content/<site name>/us/en/public/test.webinar.xml

-PJindal

Subba_Rao_Adavi
October 16, 2015

I think you should set response content type as xml like below.

 response.setContentType("text/xml;charset=utf-8");

- Subba Rao A

October 16, 2015

I tried to set Content Type but to no use. I think my problem can be solved by using suffix instead of selectors, like localhost:4502/feed.xml/[search-term].

But I would need to change extension from .xml to .html after request is submitted by the user. Can you please suggest how can I do that?

Thanks in advance.

PJindal

PaulMcMahonAccepted solution
Level 8
October 16, 2015

Have you included the XML extension in you script name? .html is the default extension so you don't need to include it in script names, but when you need to support other script names they need to be included in the extension. So for example rather than just webinar.jsp you need to name your script webinar.xml.jsp. 

October 16, 2015

Hi orotos,

It worked. Now am getting control on the required jsp. Thanks a lot for your input.

-PJindal