intercepting the page request in AEM-6.4 | Community
Skip to main content
Level 4
July 15, 2019

intercepting the page request in AEM-6.4

  • July 15, 2019
  • 1 reply
  • 9660 views
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

joerghoh
Adobe Employee
Adobe Employee
July 16, 2019

What do you mean with "intercept"? You can register a request filter (standard servlet API) and then filter according to all your requirements.

Or are you looking for something different?

Jörg

Level 4
July 16, 2019

Dear Joerg,

Thanks for your help.

Actually My requirement is below.

Intercept HTTP request from thirdparty  (endpoint is abc-services/jax-rs/participant-service/secure/participant/search) to AEM 

Level 4
July 17, 2019

If it's a HTTP request coming into AEM, you can also use a servlet filter. Then you have the raw request object, but not a structured object (for the payload of this request) yet.

When you mention that path, is it the thirdparty system or a path living in AEM (and using JAX-RS in AEM)?

Jörg


Hi Joerg,

Thanks a lot for your help and appreciated.

Currently the path is living in AEM and now I have written the below logic for my below requirement using sling filter.

Now my requirement is that when somebody will hit the PlanA (/content/trainingproject/Plan/PlanA) then it will redirect to SunitaFirst.html ( http://localhost:4502/content/trainingproject/Plan/PlanA/Location1/SunitaFirst.html ).

I have written the below code for this. But when I am trying to redirect then I am getting below error.

@SlingFilter(label = "Sample Filter", description = "Sample Description", metatype = true, generateComponent = true, // True if you want to leverage activate/deactivate

generateService = true, order = 0, // The smaller the number, the earlier in the Filter chain (can go negative);

scope = SlingFilterScope.REQUEST) // REQUEST, INCLUDE, FORWARD, ERROR, COMPONENT (REQUEST, INCLUDE, COMPONENT)

public class CustomRedirectFilter implements Filter {

Logger log = LoggerFactory.getLogger(this.getClass());

@Override

public void init(FilterConfig filterConfig) throws ServletException {

// Usually, do nothing

}

@Override

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

if (!(request instanceof SlingHttpServletRequest) || !(response instanceof SlingHttpServletResponse)) {

// Not a SlingHttpServletRequest/Response, so ignore.

chain.doFilter(request, response); // This line would let you proceed to the rest of the filters.

return;

}

final SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) response;

final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;

final Resource resource = slingRequest.getResource();

log.info("resource is ----------- ====**** " + resource);

//String rootContentPath="/content/trainingproject/Plan/PlanA";

if (resource.getPath().startsWith("/content/trainingproject/Plan/PlanA")) {

// Is the SlingFilterScope is REQUEST, redirects can be issued.

// Write your custom code here.

slingResponse.sendRedirect("/Location1/SunitaFirst.html");

return;

}

// to proceed with the rest of the Filter chain

chain.doFilter(request, response);

}

@Override

public void destroy() {

// Usually, do Nothing

}

}

ERROR IS BELOW