Expand my Community achievements bar.

SOLVED

Accessing CQ component

Avatar

Level 2

Hi,

Is it possible to access CQ component through HTTP call? My requirement is to create CQ component and display the same on 3rd party eCommerce front end.

Can anyone please suggest me what approach should I follow to achieve this?

Thanks,

Manju

1 Accepted Solution

Avatar

Correct answer by
Level 10

Now that you have a Page -- you can use methods that belong to the Page instance to get data:

http://dev.day.com/docs/en/cq/current/javadoc/com/day/cq/wcm/api/Page.html

For example - if you are interested in last mod date -- call getLastModified(). Use page methods to get all the data that you want. Place the data in JSON. You can use a JSON lib to do this from within an AEM Sling servlet. Then return the JSON as part of your Servlet return value. 

If you want to know how to construct JSON within an AEM Sling Servlet -- see this article:

http://helpx.adobe.com/adobe-cq/using/custom-sling-servlets.html.

View solution in original post

7 Replies

Avatar

Level 10

Yes -- you can access an AEM Sling Servlet from a standard HTTP call. Your CQ Servlet can return data that you can display in another client. For example - your Servlet can obtain data from the AEM JCR and return it within a data set (ie - JSON).

Avatar

Level 2

Hi,

I understood the approach you have mentioned about accessing Sling servlet with HTTP call, but I am little bit confused about how to create data set having CQ component. e.g. in below code I have retrieved CQ Page instance from JCR.

ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);
Resource res = resourceResolver.getResource(location);
Page page = res.adaptTo(Page.class);

But I am not getting how I can return it within data set or JSON. If I do something like following code, then how 3rd party eCommerce system will convert CQ page object?

JSONObject jsonObj = new JSONObject();
jsonObj.put("page", page);

Please guide me how I can create data set/JSON which will contain CQ component?

Thanks,

Manju

Avatar

Level 2

Can anyone please give me some hint on how I can send CQ component to 3rd party eCommerce system? Do I have to convert component into any other object and then send it through JSON? How can I create data set/JSON for CQ component?

Please reply.

Avatar

Level 5

Hello Manju,

You can create a sling servlet as well that will read data and return Modified JSON view of page (http://sling.apache.org/documentation/the-sling-engine/servlets.html)

If you want a component to to accessible like JSON then create json.jsp under your component, write logic to render json output for that component, create a node of type cq:Page under say /etc/something with default redering as JSON based on above resource type. And then from your e commerce system call /etc/something path.

I think servlet would be easy :D

Yogesh

Avatar

Level 2

Hi Yogesh,

As I am beginner to CQ I dont know sending JSON will be good approach or not. What I want to implement is to fetch CQ component from JCR and display it on 3rd party eCommerce system. About 2nd approach you have mentioned above, I dont think we can directly access CQ data by just mentioning URL /etc/something in eCommerce system. What about authentication?

I will prefer to use Sling servlet but I still didnt understand how to read component data. Lets take example mentioned below

ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);
Resource res = resourceResolver.getResource("/content/testSite/customPage");
Page page = res.adaptTo(Page.class);


I have retrieved Page component from JCR. Now how should I read its data?

Is there any standard approach for such type of integration (displaying CQ component on 3rd party system front end)?

Thanks,

Manju

Avatar

Correct answer by
Level 10

Now that you have a Page -- you can use methods that belong to the Page instance to get data:

http://dev.day.com/docs/en/cq/current/javadoc/com/day/cq/wcm/api/Page.html

For example - if you are interested in last mod date -- call getLastModified(). Use page methods to get all the data that you want. Place the data in JSON. You can use a JSON lib to do this from within an AEM Sling servlet. Then return the JSON as part of your Servlet return value. 

If you want to know how to construct JSON within an AEM Sling Servlet -- see this article:

http://helpx.adobe.com/adobe-cq/using/custom-sling-servlets.html.