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
BedrockMission!

Learn More

View all

Sign in to view all badges

How to modify or update the response of the page using default get servelt and send it to dispatcher on AEM publish

Avatar

Avatar
Validate 1
Level 1
annyreddy
Level 1

Like

1 like

Total Posts

19 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
annyreddy
Level 1

Like

1 like

Total Posts

19 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile
annyreddy
Level 1

22-04-2021

HI All,

 

I have to modify the response of the page on publish instance before I push it to dispatcher. For example I have a page called test page and Content Editor is going to add content in author instance to publish instance it and to dispatcher. I have to modify certian strings from the page response in publish and send it to dispatcher. 

 

I really appreciate suggestions or guidelines.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Affirm 100
Level 10
asutosh_jena
Level 10

Likes

373 likes

Total Posts

480 posts

Correct Reply

133 solutions
Top badges earned
Affirm 100
Ignite 1
Establish
Give Back 50
Give Back 5
View profile

Avatar
Affirm 100
Level 10
asutosh_jena
Level 10

Likes

373 likes

Total Posts

480 posts

Correct Reply

133 solutions
Top badges earned
Affirm 100
Ignite 1
Establish
Give Back 50
Give Back 5
View profile
asutosh_jena
Level 10

22-04-2021

Hi @annyreddy 

 

When you say you want to modify the response of a page before you push it to dispatcher, based on what condition you want to modify?

If the content is going to change based on certain condition, then it should not be cached at the dispatcher else user will always get a cached copy once the content is cached at dispatcher.

 

If it's based on certain query string, you can write a sling model which will be executed on the page component and the same will be displayed to the end user. For this you need to ensure the page is not cached at dispatcher, so you can add the below line in your Java class which will not cache the conent on your dispatcher for the complete page.

 

To handle which all page can be cached and which all cannot be cached, you can add a boolean property on the page template and using the boolean value you can control the Sling model execution something like below:

 

Page Component dialog:

<disablecache
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
name="./disableCache"
text="Disable Caching for the Current Page"
deleteHint="{Boolean}true"
fieldDescription="If checked, This Page will not be cached in the dispatcher"
value="true"/>

Page component, include the below line in HTL:

<sly data-sly-use.disableCache="com.aem.core.models.DisableCacheModel"/>

Sling Model:

@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class DisableCacheModel {

private static final Logger log = LoggerFactory.getLogger(DisableCacheModel.class);

@SlingObject
private SlingHttpServletRequest request;

@ScriptVariable
private Page currentPage;

@PostConstruct
protected void init() {
SlingBindings slingBindings = (SlingBindings) request.getAttribute(SlingBindings.class.getName());
SlingHttpServletResponse response = slingBindings.getResponse();
if (null != response) {
response.setHeader("Dispatcher", "no-cache");
}
}
}

 

If you want only certain section content to be dynamic, but the rest all page can be cached, you can use Sling Dynamic Include (SDI)

https://www.argildx.com/technology/sling-dynamic-include-sdi/

 

Thanks! 

Answers (2)

Answers (2)

Avatar

Avatar
Validate 1
MVP
shelly-goel
MVP

Likes

155 likes

Total Posts

301 posts

Correct Reply

82 solutions
Top badges earned
Validate 1
Shape 1
Ignite 1
Give Back 5
Give Back 3
View profile

Avatar
Validate 1
MVP
shelly-goel
MVP

Likes

155 likes

Total Posts

301 posts

Correct Reply

82 solutions
Top badges earned
Validate 1
Shape 1
Ignite 1
Give Back 5
Give Back 3
View profile
shelly-goel
MVP

22-04-2021

@annyreddy  You can leverage EventListener listening to Page Replicate event. On replication, make changes to the content as needed and then let it replicate the updated content. Replication will clear dispatcher cache and will cache the updated content.

Hope this is useful.

Avatar

Avatar
Establish
MVP
Ravi_Pampana
MVP

Likes

183 likes

Total Posts

234 posts

Correct Reply

70 solutions
Top badges earned
Establish
Contributor
Shape 1
Ignite 5
Ignite 3
View profile

Avatar
Establish
MVP
Ravi_Pampana
MVP

Likes

183 likes

Total Posts

234 posts

Correct Reply

70 solutions
Top badges earned
Establish
Contributor
Shape 1
Ignite 5
Ignite 3
View profile
Ravi_Pampana
MVP

22-04-2021

Hi,

 

You want to make changes to page on publisher but those changes will not be present on author page and content team won't make the changes ?

 

We can have logic in Java and based on the run mode you can update the content which will be displayed when accessing via dispatcher. 

 

Run mode for publisher will have a "publish" or you can add new run mode for publish instances and execute the logic.