get model.json while replicating page | Community
Skip to main content
Level 3
October 11, 2019
Solved

get model.json while replicating page

  • October 11, 2019
  • 8 replies
  • 4356 views

Hi all,

I have a requirement where I need page.model.json when someone clicks on the activate page button. I am able to see the model.json by directly accessing using chrome but not able to do so in JAVA code.

Thanks,

@ashokkumarmarni

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

Hi,

As suggested by Arpit, You can get JSON response in Java code, please check the reference code which I created in the past.

AEM - Get JSON response of an AEM Page

8 replies

Level 3
October 11, 2019
Ankur_Khare
Community Advisor
Community Advisor
October 11, 2019

Could you please bit more clear like what you are trying to achieve here-

1. Are you trying to replicate the page through java code?

2. If yes then you can access the page.mode.json and replicate the page through java

  Replicator replicator = ServiceUtil.getService(Replicator.class);

replicator.replicate(session,

                                            ReplicationActionType.ACTIVATE, path);

Level 3
October 11, 2019

Thanks for the reply.

Our requirement is to push ".model.json" code of a page on activation to Couchbase DB.

For that, we are using custom transport handler, In "doActivate" method of Custom Transport Handler, we are calling following code to get json of mypage:

HttpServletRequest req = requestResponseFactory.createRequest("GET", "/content/website/mypage.model.json");

ByteArrayOutputStream out = new ByteArrayOutputStream();

HttpServletResponse resp = requestResponseFactory.createResponse(out);

We are getting empty response. If i call the same url in browser then i am getting expected json response

Ankur_Khare
Community Advisor
Community Advisor
October 11, 2019

Just tried through postman, it is similar trying from code-

Few things to note it requires authentication

1. When you access mode.json what error are you getting ,is it unauthorized?, one more thing to add try absolute url like http://localhost:4502/contentpath

2. When i tried from postman with username and password as admin i am getting proper response as below for we retail page-

ArpitVarshney
Community Advisor
Community Advisor
October 11, 2019
arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
October 11, 2019

Hi,

As suggested by Arpit, You can get JSON response in Java code, please check the reference code which I created in the past.

AEM - Get JSON response of an AEM Page

Arun Patidar
Level 3
October 16, 2019

Request from postman or request from browser url are same, that is why it's working for you & us both.

But whenever we request it in java code through request - response way, we are getting empty response.

Out of box pages of we.retail & geometrix are giving proper json response either way.

Level 3
October 16, 2019

Thanks Arun, we have checked your code and it is working fine as it is a custom servlet and you are reading/iterating the node through code.

We are trying to get ".model.json" working as it is Out of Box and it works for we.retail & geometrix site.

Any help is appreciated. Thanks