Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

CQ calling REST Service

Sudhin_Baru
Level 2
Level 2

Hi,

 Is there any article/post which can guide me with CQ calling rest service to get JSON data back?

I see the below is CQ calling web service. Something similar?

http://scottsdigitalcommunity.blogspot.com/2012/05/creating-adobe-cq-bundles-that-consume.html

 

Thanks,

Sudhin

1 Accepted Solution
smacdonald2008
Correct answer by
Level 10
Level 10

A new article has been created that shows how to perform this use case. In this article, the distance between 2 cities is calculated by invoking a third party Restful web service:

[img]App.png[/img]

To read this article, see http://scottsdigitalcommunity.blogspot.ca/2013/11/creating-adobe-experience-manager.html.

View solution in original post

5 Replies
smacdonald2008
Level 10
Level 10

I have expedited this community article -- i will post this article early next week. Maybe even on Mon or Tues. It will show how to build a Restful service within CQ and display the results in a page component. I will post the link on this thread once done. 

smacdonald2008
Correct answer by
Level 10
Level 10

A new article has been created that shows how to perform this use case. In this article, the distance between 2 cities is calculated by invoking a third party Restful web service:

[img]App.png[/img]

To read this article, see http://scottsdigitalcommunity.blogspot.ca/2013/11/creating-adobe-experience-manager.html.

View solution in original post

smacdonald2008
Level 10
Level 10

That use case is on the community article list  - however - it's has not been written yet. That use case is scheduled for early 2014. 

However - to build this -- follow similar steps as the web services one. That is -- create a JAR lib that performs a Restful call to another service/server. Wrap that JAR into an OSGi bundle using an Eclipse plug-in project. Deploy the OSGi and get it into an active state.

Depending on what lib you use - you may have to created another OSGi bundle fragment that contains the Java classes you use and that are not part of CQ -- for example if you use a JSON JAR lib to encode data as JSON. To see a community article that wraps a JSON lib and deploy to CQ within an OSGi bundle -- See:

http://scottsdigitalcommunity.blogspot.ca/2013/06/posting-form-data-to-adobe-cq-using.html

Once the OSGi bundle is active - you can invoke the OSGi that will result in the Restful call being made. Have the OSGi bundle return the data. For example - if the OSGi bundle returns JSON data -- you can display the JSON data in a CQ web page. See the above link for an example of how the page component parsed JSON data and displayed the data in a CQ web page. 

Hope this helps 

Sudhin_Baru
Level 2
Level 2

Hi Scott,

 Thank you and appreciate your quick turn around time. I've a question though, do we always have to encompass the REST urls in a JAR (Java project <-> OSGI) or is there a way we can directly consume these services from CQ5?

Thanks,

Sudhin

smacdonald2008
Level 10
Level 10

For best practices -- keep the data operations hidden at the OSGi layer. Let the page components call the OSGi bundle operations and display the data.

However -- having said that  -- you can invoke a 3rd party Restful web service via JavaScript as opposed to Java.