AEM, debug does not catch SlingServletFilter | Community
Skip to main content
January 4, 2023
Solved

AEM, debug does not catch SlingServletFilter

  • January 4, 2023
  • 2 replies
  • 1129 views

I am trying to implement a Sling Servlet Filter which aims to be invoked when I upload any .json file into filtertest folder, following the tutorial on https://sling.apache.org/documentation/the-sling-engine/filters.html
Here is the annotations and attributes in it:

@SlingServletFilter(scope= {SlingServletFilterScope.REQUEST},
pattern = "/content/dam/filtertest/.*",
extensions = {"json"},
methods = {"GET", "HEAD", "PUT"})

However, debug does not catch the breakpoint in this class' doFilter method.
What is the problem in here? I could not figure it out.

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 Harishv31

Hi ,

 

Please check the status of the filter .

http://localhost:4502/system/console/status-slingfilter

 

Try checking the servlet filter component in OSGI components console and check if it is enabled and also reload once.

 

 

 

sample code:

@9944223
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException {

SlingHttpServletRequest request = (SlingHttpServletRequest) req;
SlingHttpServletResponse response = (SlingHttpServletResponse) res;
WCMMode mode = WCMMode.fromRequest(request);
if(WCMMode.EDIT!=mode) {
String requestURL = request.getRequestURI(); //page url
String extensions = request.getRequestPathInfo().getExtension(); //page extensions
if(extensions.contains("json")) {
//your logic here
}
}
}

2 replies

Suraj_Kamdi
Community Advisor
Community Advisor
January 4, 2023

@coderninja Just update your Service class with following code

 

@Component(
service = Filter.class,
immediate = true,
name = "Sample Filter for page request",
property = {
Constants.SERVICE_DESCRIPTION + "=Demo to filter incoming requests",
EngineConstants.SLING_FILTER_SCOPE + "=" + EngineConstants.FILTER_SCOPE_REQUEST,
Constants.SERVICE_RANKING + ":Integer=-100",
EngineConstants.SLING_FILTER_REQUEST_PATTERN + "=/content/dam/.*",
})
@SlingServletFilter(
resourceTypes = {
"dam:Asset"
})
Harishv31Accepted solution
Level 3
January 5, 2023

Hi ,

 

Please check the status of the filter .

http://localhost:4502/system/console/status-slingfilter

 

Try checking the servlet filter component in OSGI components console and check if it is enabled and also reload once.

 

 

 

sample code:

@9944223
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException {

SlingHttpServletRequest request = (SlingHttpServletRequest) req;
SlingHttpServletResponse response = (SlingHttpServletResponse) res;
WCMMode mode = WCMMode.fromRequest(request);
if(WCMMode.EDIT!=mode) {
String requestURL = request.getRequestURI(); //page url
String extensions = request.getRequestPathInfo().getExtension(); //page extensions
if(extensions.contains("json")) {
//your logic here
}
}
}