Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.
SOLVED

CQ serving content to another application

Avatar

Former Community Member

I'm pretty new to AEM.

We have an existing web app which currently extracts content 'fragments' from Sitefinity using REST calls. Fragments might be snippets of HTML, raw text, images, and so on.

AEM has become our strategic CMS platform and we want to provide the same capability but use AEM to serve the content.

I have seen that one can send a HTTP request to a content node and it will return basic details about that node (I guess resource is a better term since its is essentially a RESTful GET request). I note that I can ask that the response is sent in html, json and text formats.

My question is, rather than information about the jcr node, what is the best way to return [say] the actual rendered fragment associated with that resource/node (not sure if I'm using appropriate terminology here) ?

What if I wanted to retrieve the same content but as JSON ?

kind regards

Fraser

1 Accepted Solution

Avatar

Correct answer by
Level 8

I would suggest reading up on Sling Request processing - http://dev.day.com/docs/en/cq/current/developing/the_basics.html#Sling Request Processing. The easiest way to get back a rendition of a node is to make sure the node you are trying to access has a sling resource type. Then you can associate scripts based on extension, HTTP method, or selectors to get the right snippet rendering. 

In AEM (CQ) terms this means generally that what you can effectively target are nodes representing components or pages. You can see how this works in the Geometrixx Demo site. For example if you look at http://localhost:4502/content/geometrixx/en/services.html you see a whole page. However you can access HTML renditions of any of the components if you know the path to the content - so for example http://localhost:4502/content/geometrixx/en/services/_jcr_content/par.html gives just the HTML for the center well of the page. If we wanted just a single component's HTML you can look at something like http://localhost:4502/content/geometrixx/en/services/_jcr_content/par/text_1.html

You can also create different renditions of a page/component if needed for you integration using selectors. So for example let's say you know you want a different HTML rendition for a component when it is pulled into your existing application. 

  • Assume your component is located at /apps/myapp/components/mycomp. 
  • The normal HTML rendering of the component for inclusion in a page would be handled by /apps/myapp/components/mycomp/mycomp.jsp. 
  • You could have another JSP - say /apps/myapp/components/mycomp/portal.jsp that rendered the output as required by your other app. 
  • Then your other app would use a URL that looks like http://localhost:4502/content/mysite/services/_jcr_content/par/mycomp.portal.html (that only works if the selector matches the name of the JSP). 

As someone else pointed out you should also consider how you other application accesses CQ - you can run those request through say Dispatcher and they will be cached. 

View solution in original post

6 Replies

Avatar

Level 10

If you are looking to get content in CQ then use external component [1].   If external application like portal needs data from cq the use portal integration[2].  This should answer what you are looking. If not provide more details.

[1]   http://dev.day.com/docs/en/cq/5-5/wcm/default_components/editmode.html#External

[2]   http://dev.day.com/docs/en/cq/current/administering/cq_as_portal.html

Avatar

Former Community Member

Thanks for the links. I'm not sure if they help me or not. Let me try and describe a simple use case :-

We design a [partial] site in CQ to enable content authors to create/edit some text to be displayed.

That text is to be used by a web application built in a non-CQ technology (lets say .Net). So that .Net application needs to request the content from CQ. I had assumed that one way of doing that would be via Sling (i.e. an HTTP GET pointing to a resource which resolves to the text content entered by the author).

Is that possible ?

If so, can you give me a few pointers to how ?

Thanks

Fraser.

Avatar

Correct answer by
Level 8

I would suggest reading up on Sling Request processing - http://dev.day.com/docs/en/cq/current/developing/the_basics.html#Sling Request Processing. The easiest way to get back a rendition of a node is to make sure the node you are trying to access has a sling resource type. Then you can associate scripts based on extension, HTTP method, or selectors to get the right snippet rendering. 

In AEM (CQ) terms this means generally that what you can effectively target are nodes representing components or pages. You can see how this works in the Geometrixx Demo site. For example if you look at http://localhost:4502/content/geometrixx/en/services.html you see a whole page. However you can access HTML renditions of any of the components if you know the path to the content - so for example http://localhost:4502/content/geometrixx/en/services/_jcr_content/par.html gives just the HTML for the center well of the page. If we wanted just a single component's HTML you can look at something like http://localhost:4502/content/geometrixx/en/services/_jcr_content/par/text_1.html

You can also create different renditions of a page/component if needed for you integration using selectors. So for example let's say you know you want a different HTML rendition for a component when it is pulled into your existing application. 

  • Assume your component is located at /apps/myapp/components/mycomp. 
  • The normal HTML rendering of the component for inclusion in a page would be handled by /apps/myapp/components/mycomp/mycomp.jsp. 
  • You could have another JSP - say /apps/myapp/components/mycomp/portal.jsp that rendered the output as required by your other app. 
  • Then your other app would use a URL that looks like http://localhost:4502/content/mysite/services/_jcr_content/par/mycomp.portal.html (that only works if the selector matches the name of the JSP). 

As someone else pointed out you should also consider how you other application accesses CQ - you can run those request through say Dispatcher and they will be cached. 

Avatar

Community Advisor

Hi Fraser,

It really depends on the architecture of your application,

Integrating CQ with quite a few applciations using Rest is a real Joy. JSON is an excellent way to provide API's, every resource in JCR can be viewed as html and json.

We open sourced https://github.com/IG-Group/RESTdoclet to allow the beautifull integration documentation.

You can create a service that exposes sling servlet with certain selectors and produces clean json output. .net will consume it later.

Given half of your page may be .net and half CQ you may create a mock page consisting of static images(components generated by .net) and dynamic parts represented with custom parsys where you can drop CQ components.

Remember to consult with Adobe before implementing your solution to make sure will do the right integration design.

Hope this helps,

Peter

Avatar

Former Community Member

Are you aware of technologies like mod_proxy that help pull content from different web servers?

I would recommend the following:

  1. Have a dispatcher in front of your publish instance
  2. Use mod_proxy to pull the HTMLs from your dispatcher to your Dot Net App

I think there is nothing else that needs to be done to your CQ instance to achieve this.

Other way as others have suggested is to use the REST calls from your app to the your JCR.

Avatar

Former Community Member

Thanks to everyone. Thats given me a really good starting point.

kind regards

Fraser.