Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Boot in standalone Tomcat ignores exceptions set in DeferredResults #2711

Closed
maddy-markovitz opened this issue Mar 25, 2015 · 5 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@maddy-markovitz
Copy link

When a controller returning a DeferredResult throws an exception, as in the example below, Tomcat will ignore the exception and return an HTTP 200 with no response body.

    @RequestMapping(value = "html/start", method = RequestMethod.POST, consumes =APPLICATION_FORM_URLENCODED)
    public DeferredResult<String> start(final HttpServletResponse response,
                                    @Valid @ModelAttribute final InitialisationStartAttributes model,
                                    final SessionData sessionExisting) throws MyRequestProcessingException {
    final DeferredResult<String> finalResult = new DeferredResult<>(5000);
                // Just return an error, so we can test
                if (true) {
                    finalResult.setErrorResult(new MyRequestProcessingException(
                            "Something went wrong processing request"));
                }
    return finalResult;
}

The exception is annotated with @ResponseStatus.

@ResponseStatus(value=HttpStatus.INTERNAL_SERVER_ERROR)
public class MyRequestProcessingException extends Exception {

public MyRequestProcessingException(String message) {
    super(message);
}   
}

If this is executed in a Spring Boot embedded context it will return 500 as one would expect.

I'm running 1.2.1 RELEASE.

@philwebb philwebb added the type: bug A general bug label Mar 25, 2015
@philwebb philwebb added this to the 1.2.3 milestone Mar 25, 2015
@maddy-markovitz
Copy link
Author

I've managed to work around this to some extent by defining my own @ExceptionHandler for all exceptions, which I can use to return the correct status, but it's pervasive - affects the response status throughout the whole filter chain. Thus filters and interceptors which are supposed to log the response status will not work.

@wilkinsona
Copy link
Member

This sounds somewhat similar to #1920. @maddy-markovitz, what version of Tomcat are you using?

@philwebb philwebb added status: waiting-for-feedback We need additional information before we can continue and removed type: bug A general bug labels Mar 25, 2015
@maddy-markovitz
Copy link
Author

7.0.52, also tested and confirmed this occurs on Tomcat 8.

@maddy-markovitz
Copy link
Author

It does look similar to #1920, but he says it's happening with embedded Tomcat and I'm only seeing this when I deploy into standalone Tomcat. Also not sure (without running the example) whether the expected status code is being returned.

@philwebb philwebb removed the status: waiting-for-feedback We need additional information before we can continue label Mar 25, 2015
@wilkinsona wilkinsona self-assigned this Mar 26, 2015
@wilkinsona wilkinsona added the type: bug A general bug label Mar 26, 2015
@maddy-markovitz
Copy link
Author

Thanks for the bug fix :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants