Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

AEM always returns 200 status code.

Avatar

Level 2

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.

1 Accepted Solution

Avatar

Correct answer by
Employee

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.

View solution in original post

34 Replies

Avatar

Level 2

Thank you for your response. I tried the custom error handler, but the results are the same. The aem just returns blank page with 200 status code even if the request url is invalid. Not sure what is wrong?

Avatar

Level 2

I never got the default 404 not found page working in my local author and publish instances. If the request url is invalid, the response would be a black page with 0 content length, while the HTTP status code is 200. Anyone met with the same problem?

Avatar

Level 2

Sorry, a typo. The response is blank page.

Avatar

Level 10

Do you see 404.html or 404.jsp in your AEM instance under  /apps/sling/servlet/errorhandler/?

http://localhost:4502/crx/de/index.jsp#/apps/sling/servlet/errorhandler/404.html

Avatar

Level 2

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);

    }

}

Avatar

Level 2

"/content/myproject/en/page-not-found.html" is a custom 404 error page.

Avatar

Employee Advisor

That does not look like a deafult behavior. AEM should give you a 404 for non existing nodes:

jbrar-macOS:~ jbrar$ curl -u admin:admin http://localhost:6333/content/geometrixx-outdoors/en/men/pants/fulani-noma -I

HTTP/1.1 404 Not Found

Date: Thu, 29 Aug 2019 21:08:49 GMT

X-Content-Type-Options: nosniff

Set-Cookie: cq-authoring-mode=TOUCH;Path=/;Expires=Thu, 05-Sep-2019 21:08:49 GMT;Max-Age=604800

Expires: Thu, 01 Jan 1970 00:00:00 GMT

Content-Type: text/html;charset=utf-8

Transfer-Encoding: chunked

Can you check if you get the 404 response when running a curl command? If yes, the error handler implementation is wrong

Avatar

Level 2

I am not able to get the 404 response when running a curl command to request a non-existent page. Nothing shows up in the terminal, however, I am able to get the correct page for a valid url using curl.

For example, requesting http://localhost:4503/content/myproject/en/search-results shows the html page content, however, requesting http://localhost:4503/content/myproject/en/no-page did not get any response.

Avatar

Level 2

I never get a 404 response from the AEM, either in Author or in Publisher. That is very strange.

Avatar

Level 2

Update for the curl command: I get 200 status for both the valid and invalid url request.

Response for requesting the valid url : http://localhost:4503/content/myproject/en/search-results.html

HTTP/1.1 200 OK

Date: Thu, 29 Aug 2019 21:45:38 GMT

X-Content-Type-Options: nosniff

Set-Cookie: cq-authoring-mode=TOUCH;Path=/;Expires=Thu, 05-Sep-2019 21:45:38 GMT

Expires: Thu, 01 Jan 1970 00:00:00 GMT

Content-Type: text/html;charset=utf-8

Transfer-Encoding: chunked

Response for the invalid url: http://localhost:4503/content/myproject/en/no-page.html

HTTP/1.1 200 OK

Date: Thu, 29 Aug 2019 21:46:15 GMT

X-Content-Type-Options: nosniff

Set-Cookie: cq-authoring-mode=TOUCH;Path=/;Expires=Thu, 05-Sep-2019 21:46:15 GMT

Expires: Thu, 01 Jan 1970 00:00:00 GMT

Content-Length: 0

Avatar

Community Advisor

That could be due to Response buffer size as well that you always get 200 instead of any other error code. If the rendered response buffer is more than defined one, then server send response back to browser in chunks and once it's sends a part of response, no matter if page works or not, if always return 200.

You can try increasing the buffer size by going into configuration:

Apache Felix Jetty Based Http Service

"Response Buffer Size"

Increase the size and if page throws error then it should get displayed as well.

Avatar

Level 3

Can you try creating the error pages using ACS commons error page handler.

https://adobe-consulting-services.github.io/acs-aem-commons/features/error-handler/index.html

In this article there is step by step process to create custom error pages and also settings in dispatcher.

Error Page Handler

https://adobe-consulting-services.github.io

Best,

Cal

Avatar

Level 2

Hi, Umeshsondhi

Thank you for your reply. I have read the article you mentioned.  In localhost, I do not use a dispatcher. It seems that a blank page would always be returned by Publish for invalid url request. I don't know how this blank page is created.

Avatar

Level 2

Hi himanshusinghal,

Thank you for your response. I tried to increase the Response Buffer Size, then click Save. I got a request error as following:

ajax_error.PNG

Avatar

Level 2

Hello cal-netsolutions,

Thank you for your suggestion. However, we have implemented a custom error handler. It works fine in Publish instance in another computer. It does not work in some computers and the stage. They have the same problem: invalid url always got 200 status code with blank page.

Avatar

Community Advisor

Hi janellic4,

While saving the configuration, it displays the error but it saves the updated value. Try opening the value again and it should show updated "Response Buffer Size".
Even after increasing the response buffer size, do you still get the 200 status code?

Do you get any error as well in logs?

Avatar

Level 2

Hi himanshusinghal,

Yes, I still got the 200 status code even after I doubled the response buffer size.

Avatar

Community Advisor

Could you please try increasing the buffer size to lets say 10000 and try again?