It seems that the Spring Boot error page filter changes all my HTTP status codes to 200 OK (different from 4xx) This only happens when the sublet is stationed in the container. Is this a bug or am I doing something wrong?
I have actually created a simple spring boot app to reproduce it:
@PushingBootAppection @contact controller public class ResponseErrorController SpringBootServletInitializer {public static zero main (string [] Argens) {SpringApplication.run (ResponseErrorController.class, args); } @ Override Protected Spring Appleling Builder (Spring Applications Builder Builder) {Return Builder. Source (Response Error Controller Class); } @RequestMapping ("/ 304") Public Zero Lala throws exception (HTTPServe response feedback) {response.sendError (304, "not modified"); }}
When I start to open non-embedded tomacat (or jetty) in the browser, I always get 200 OK (without content).
After some debugging I found that the error page filter does not represent the status code from the actual code wrapped response. I know that I can return ResponeEntity to my controller but my actual problem is with a service of another frame that sends 304 - this controller is only for the demo.
Has anyone seen this? Status codes located below 400 are not an error and should be set via setStatus (int)
instead
sendError (int)
. Therefore handles the ErrorPageFilter
call only with status code> = 400.
Here's how to fix it:
-
If this is your own code: instead of using
setStatus (int)
Please. -
If a third-party servlet or filter is
sendError (int)
: As an alternate solution, you canErrorPageFilter
In yourSpringBootServletInitializer
:Can run protected WebApplicationContext (SpringApplication application) {application.getSources (). Remove (ErrorPageFilter.class); Return super.run (application); }
No comments:
Post a Comment