PreProcessor full page URL | Community
Skip to main content
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 Mahedi_Sabuj

Hi @nusrat_jahan
When publishing a page in AEM, the process involves publishing various associated nodes, including the template policy (/conf), assets (/content/dam), content (/content), and more. To exclusively target content pages within this process, you can incorporate a filter in your code. 

public class ReplicationPreprocessor implements Preprocessor { @Override public void preprocess(ReplicationAction action, ReplicationOptions options) throws ReplicationException { final String path = action.getPath(); if (path.contains(CONTENT_PATH)) { // Place your logic for content pages here if(inValid) { throw new ReplicationException("ERROR_MESSAGE"); } } } }

By using this filter, you guarantee that your logic is executed solely on nodes residing under any path specified by CONTENT_PATH.

 

 

2 replies

Jagadeesh_Prakash
Community Advisor
Community Advisor
September 6, 2023

@nusrat_jahan  Below is the sample code that gets the full page path 

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.apache.sling.engine.servlets.preprocessor.SlingRequestPreprocessor;

public class MyPreprocessor extends SlingSafeMethodsServlet implements SlingRequestPreprocessor {
@Override
public void preprocess(SlingHttpServletRequest request, SlingHttpServletResponse response) {
// Your preprocessing logic here
String fullPagePath = request.getRequestPathInfo().getSuffix();
// Now, fullPagePath contains the full page path
}
}

Mahedi_Sabuj
Community Advisor
Mahedi_SabujCommunity AdvisorAccepted solution
Community Advisor
September 6, 2023

Hi @nusrat_jahan
When publishing a page in AEM, the process involves publishing various associated nodes, including the template policy (/conf), assets (/content/dam), content (/content), and more. To exclusively target content pages within this process, you can incorporate a filter in your code. 

public class ReplicationPreprocessor implements Preprocessor { @Override public void preprocess(ReplicationAction action, ReplicationOptions options) throws ReplicationException { final String path = action.getPath(); if (path.contains(CONTENT_PATH)) { // Place your logic for content pages here if(inValid) { throw new ReplicationException("ERROR_MESSAGE"); } } } }

By using this filter, you guarantee that your logic is executed solely on nodes residing under any path specified by CONTENT_PATH.

 

 

Mahedi Sabuj