Expand my Community achievements bar.

SOLVED

Create node By Json Data

Avatar

Level 5

Hi,

I need to write a servlet to hit the third party URL(its a open source url) and this URL returning data in json format.I need to store these data in node.Please suggest

 

 

Regards,

1 Accepted Solution

Avatar

Correct answer by
Level 3
Inside servlet  use HTTPClient (from apache commons) api to hit 3rd party url and get the data. If you response is in JSON format use JSONObject or JSONArray objects (from sling commons) and inject the response to the constructors of those objects. From those json objects you get the values by passing keys. Now to create new nodes use Node api (from javax.jcr) and set appropriate properties to the node and save the session by using session.save() method. PS: Your nodes will be created only after execution of session.save() method

View solution in original post

2 Replies

Avatar

Correct answer by
Level 3
Inside servlet  use HTTPClient (from apache commons) api to hit 3rd party url and get the data. If you response is in JSON format use JSONObject or JSONArray objects (from sling commons) and inject the response to the constructors of those objects. From those json objects you get the values by passing keys. Now to create new nodes use Node api (from javax.jcr) and set appropriate properties to the node and save the session by using session.save() method. PS: Your nodes will be created only after execution of session.save() method

Avatar

Level 10

See this AEM article that shows you how to use the JCR API to save data in the JCR -- 

http://scottsdigitalcommunity.blogspot.ca/2014/12/querying-adobe-experience-manager-6.html

In your servlet - after you get back the JSON data, create app logic to store the data in the JCR.