Expand my Community achievements bar.

SOLVED

get model.json while replicating page

Avatar

Level 4

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

8 Replies

Avatar

Community Advisor

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

Level 4

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

Community Advisor

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

Correct answer by
Community Advisor

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

Avatar

Level 4

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

Level 4

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