Expand my Community achievements bar.

SOLVED

CUSTOM URL EXTENSIONS

Avatar

Level 2

I am relatively new to CQ5. How do we make our own extension in url like http://www.mywebsite.com/product/mypage.myextension instead of having .html in the last?
.html returns data in HTML format
.json returns data in JSON format
.xml returns data in XML format
.txt returns data in Plain txt format
.myextension returns data in MY format

1 Accepted Solution

Avatar

Correct answer by
Administrator

Hi

You can achieve this by:-

Link:- http://www.hsufengko.com/home/adobe-cq-renders-pages-with-custom-extension

//Adobe CQ Renders Pages with Custom Extension

In order to tell CQ to be able to deal with a custom request with a special page extension (e.g., .foo), you need to

    Implement a component JSP file to render the page with .foo extension, and
    Tell CQ that .foo extension is acceptable.


Here's the details of what you need to do:

#1) Implement component JSP to render page with .foo extension
Like many other CQ5 component, you should have known how to implement a CQ5 component in JSP, and what to name (according to url-to-script resolution rules) it so that it'll be used to render the page being requested. In our example case to render page with .foo extension, the JSP component can be named as foo.jsp. If you're not familiar with url-to-script resolution in Sling, please refer to other articles and tutorials first then come back to this article. In this post, I'd like to focus on the next step which is essential and is not quite clearly documented by Adobe.


#2) Tell CQ that .foo extension is acceptable
This has to be achieved by creating a file under /libs/foundation/components/primary/cq/Page/. Specifically, using our .foo extension example, we need to create the following file named Page.foo.jsp if you want request to pages of .foo extension to be acceptable by CQ:

  /libs/foundation/components/primary/cq/Page/Page.foo.jsp

Make the above file has the following one line content:

    <%@include file="/libs/foundation/components/primary/cq/Page/proxy.jsp" %>

Please note, for unknown reason, use the following line without the full path of proxy.jsp or with extra return characters at the end may lead you to some unknown 500 Error on rendering the page, so don't:

    <%@include file="proxy.jsp" %>
    [return]

Therefore, I highly suggest you to make sure you don't have extra carriage return at the end and use the full path to reference proxy.jsp in Page.foo.jsp if possible. Otherwise, you may encounter 500 Internal Server Error as I did using CQ 5.6.1.

 

I hope this would help you.

Thanks and Regards

Kautuk Sahni



Kautuk Sahni

View solution in original post

3 Replies

Avatar

Employee Advisor

You can register a servlet to handle any kind of extension.

 

You can implement like this:

@Component @Service @Properties({ @Property(name="sling.servlet.extensions",value="myextension") }) public class MyextensionHandler extends SlingAllMethodsServlet { ... }

Avatar

Correct answer by
Administrator

Hi

You can achieve this by:-

Link:- http://www.hsufengko.com/home/adobe-cq-renders-pages-with-custom-extension

//Adobe CQ Renders Pages with Custom Extension

In order to tell CQ to be able to deal with a custom request with a special page extension (e.g., .foo), you need to

    Implement a component JSP file to render the page with .foo extension, and
    Tell CQ that .foo extension is acceptable.


Here's the details of what you need to do:

#1) Implement component JSP to render page with .foo extension
Like many other CQ5 component, you should have known how to implement a CQ5 component in JSP, and what to name (according to url-to-script resolution rules) it so that it'll be used to render the page being requested. In our example case to render page with .foo extension, the JSP component can be named as foo.jsp. If you're not familiar with url-to-script resolution in Sling, please refer to other articles and tutorials first then come back to this article. In this post, I'd like to focus on the next step which is essential and is not quite clearly documented by Adobe.


#2) Tell CQ that .foo extension is acceptable
This has to be achieved by creating a file under /libs/foundation/components/primary/cq/Page/. Specifically, using our .foo extension example, we need to create the following file named Page.foo.jsp if you want request to pages of .foo extension to be acceptable by CQ:

  /libs/foundation/components/primary/cq/Page/Page.foo.jsp

Make the above file has the following one line content:

    <%@include file="/libs/foundation/components/primary/cq/Page/proxy.jsp" %>

Please note, for unknown reason, use the following line without the full path of proxy.jsp or with extra return characters at the end may lead you to some unknown 500 Error on rendering the page, so don't:

    <%@include file="proxy.jsp" %>
    [return]

Therefore, I highly suggest you to make sure you don't have extra carriage return at the end and use the full path to reference proxy.jsp in Page.foo.jsp if possible. Otherwise, you may encounter 500 Internal Server Error as I did using CQ 5.6.1.

 

I hope this would help you.

Thanks and Regards

Kautuk Sahni



Kautuk Sahni