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
  • 25896 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

janellic4
janellic4Author
Level 2
September 3, 2019

Hi himanshusinghal,

I just tried to increase the size to different sizes. No matter how many size I increased, I still got the 200 status code and the blank page.

leoberliantAdobe EmployeeAccepted solution
Adobe Employee
September 3, 2019

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.

janellic4
janellic4Author
Level 2
September 3, 2019

Hi berliant,

Thank you for your reply. I have one custom filter that sets status code to 400 if the slinghttprequest does not satisfy certain condition. After I stopped the custom bundle, the 404 not found status code shows up correctly. However, this custom bundle is also needed in the project, is there any way to solve the issue instead of stopping the custom bundle?

Adobe Employee
September 3, 2019

You might need to add configuration properties, as such you can define only those URLs that required a specific status.

janellic4
janellic4Author
Level 2
September 3, 2019

Hi @berliant,

In the custom filter, I actually add the logic to check the request URI, if it is not the path of the target servlet, the filter won't do anything (I use filterChain.doFilter(request, response) for this situation). Somehow I don't know why the response status code is always 200. If I put the filter logic inside the servlet and delete the filter, the 404 page works correctly.  But with this way, the servlet will have a very long code. I also implemented another filter to add header options to servlet response, however, this filter does not affect the status code.

antoniom5495929
Level 7
September 4, 2019

Hi,

Have you already tryied to change the status into the ResponseStatus.java?

Just to check if a different status code is returned let's try to do this:

public void activate() throws Exception {

        getResponse().setStatus(407);

    }

Let us know.

Thanks,

Antonio

janellic4
janellic4Author
Level 2
September 4, 2019

Hi, antoniom54959291

Thank you for your response. Do you mean that use this method in the Filter.java?

antoniom5495929
Level 7
September 4, 2019

Hi,

I'm referring to your previous post:

6. Re: AEM always returns 200 status code.

yes, I created a 404.html and ResponseStatus.java under /apps/sling/servlet/errorhandler

In the 404.html, the code is as:

<sly data-sly-use.responseStatus="apps.sling.servlet.errorhandler.ResponseStatus">

    <sly data-sly-resource="/content/myproject/en/page-not-found.html"></sly>

</sly>

The code in ResponseStatus.java is:

package apps.sling.servlet.errorhandler;

import com.adobe.cq.sightly.WCMUsePojo;

public class ResponseStatus extends WCMUsePojo {

    @Override

    public void activate() throws Exception {

        getResponse().setStatus(404);

    }

}

If you have this implementation, you can try to change the setStatus in the ResponseStatus Pojo in order to check if you have an other different status code.

Let us know.

Thanks,

Antonio

janellic4
janellic4Author
Level 2
September 4, 2019

Hi antoniom54959291

I tried changing the setStatus code in the errorhandler, the response still gets 200 for invalid url. I then stop the bundle that includes a custom filter (as suggested by @berliantberliantTherefore, it is the custom filter that causes the issue. I am still struggling on fixing the filter's problem.

janellic4
janellic4Author
Level 2
September 4, 2019

I figure out the problem of the custom filter, the pattern that restricts the filter to the target servlet has a wrong setting. Now I change it to the correct setting, the 404 Page works correctly now. Thank you for all your help!