get model.json while replicating page

Avatar

Avatar

ashish_mishra1

Avatar

ashish_mishra1

ashish_mishra1

11-10-2019

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

958

Correct Answer

820

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

958

Correct Answer

820
Arun_Patidar
MVP

11-10-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

Answers (7)

Answers (7)

Avatar

Avatar

ashish_mishra1

Avatar

ashish_mishra1

ashish_mishra1

16-10-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

Avatar

Avatar

ashish_mishra1

Avatar

ashish_mishra1

ashish_mishra1

16-10-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.

Avatar

Avatar

ArpitVarshney

MVP

Avatar

ArpitVarshney

MVP

ArpitVarshney
MVP

11-10-2019

Hi ashish_mishra

Have you got a chance to look into thise thread Is this possible to get .model.json from content path in Java class instead of hitting absolute url ...

It might help you.

Regards,

Arpit

Avatar

Avatar

Ankur_Khare

MVP

Avatar

Ankur_Khare

MVP

Ankur_Khare
MVP

11-10-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-

1843646_pastedImage_1.png

1843549_pastedImage_0.png

Avatar

Avatar

ashish_mishra1

Avatar

ashish_mishra1

ashish_mishra1

11-10-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

Avatar

Avatar

Ankur_Khare

MVP

Avatar

Ankur_Khare

MVP

Ankur_Khare
MVP

11-10-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);

Avatar

Avatar

ashish_mishra1

Avatar

ashish_mishra1

ashish_mishra1

11-10-2019