AEM always returns 200 status code. | Community
Skip to main content
janellic4
Level 2
August 29, 2019
Solved

AEM always returns 200 status code.

  • August 29, 2019
  • 34 replies
  • 25985 views

Upon requesting non-existent pages, both aem author and publish instances return blank page with 200 status code. The default 404 error page is not showing.

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 leoberliant

Do you have any custom filters that can possibly massage the response? You might want to stop your custom bundles in OSGi and use /system/console/requests to track recent requests.

34 replies

October 8, 2019

Hi, janellic4!

I got the problem exactly like yours.

Can you tell what was wrong in your custom filter and how you fix it? How did you find any useful information by "/system/console/requests"? I can't see any changes of status-code here.

Also can you change status of response in custom filter when slice-model throws an exception?

Thank you,

Daria

janellic4
janellic4Author
Level 2
October 9, 2019

Hi DariaSuleimanova,

In my custom filter, there is a sling.filter.pattern property, but what I use is "pattern", so this filter cause the problem. After I changed it to "sling.filter.pattern", the 404 page shows correctly.

October 9, 2019

Thank you for your answer!

Can you please share your code?

I made Filter by @SlingFilter but didn't use sling.filter.pattern at all

Filter will not work without this property?

janellic4
janellic4Author
Level 2
October 9, 2019

Hi DariaSuleimanova,

Filter will work without this property. For my situation, I want to restrict my custom filter to certain servlet, so I use the sling.filter.pattern property.

@Component(service = Filter.class,

property = {

                    Constants.SERVICE_DESCRIPTION + "=My Filter",

             EngineConstants.SLING_FILTER_SCOPE + "=" + EngineConstants.FILTER_SCOPE_REQUEST,

                    EngineConstants.SLING_FILTER_PATTERN + "=" + "/my_path_pattern",

                   Constants.SERVICE_RANKING + ":Integer=-100"

           })

public class MyFilter implements Filter{

    private final Logger logger = LoggerFactory.getLogger(MyFilter.class);

    @Override

    public void doFilter(final ServletRequest request, final ServletResponse response,

final FilterChain filterChain) throws IOException, ServletException {

        final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;

        String requestURI = slingRequest.getRequestURI();

         //code to do something

filterChain.doFilter(request, response);

    }

    @Override

    public void init(FilterConfig filterConfig) {

    }

    @Override

    public void destroy() {

    }

}