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.
Solved! Go to Solution.
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.
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.
Views
Replies
Total Likes
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.
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?
Views
Replies
Total Likes
You might need to add configuration properties, as such you can define only those URLs that required a specific status.
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
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
Hi, antoniom54959291
Thank you for your response. Do you mean that use this method in the Filter.java?
Views
Replies
Total Likes
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
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.
Views
Replies
Total Likes
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!
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
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
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?
Views
Replies
Total Likes
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() {
}
}
Views
Likes
Replies