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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

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

ArunaSurukunta
Level 5
Level 5

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.

1 Accepted Solution
Asutosh_Jena_
Correct answer by
Community Advisor
Community Advisor

Hi @ArunaSurukunta 

 

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! 

View solution in original post

0 Replies
Ravi_Pampana
Community Advisor
Community Advisor

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.

 

Asutosh_Jena_
Correct answer by
Community Advisor
Community Advisor

Hi @ArunaSurukunta 

 

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! 

View solution in original post

shelly-goel
Community Advisor
Community Advisor

@ArunaSurukunta  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.