Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

PreProcessor full page URL

Avatar

Level 2

Can we get full page path in Preprocessor java class ?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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.

 

 

View solution in original post

2 Replies

Avatar

Community Advisor

@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
}
}

Avatar

Correct answer by
Community Advisor

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.