`TomcatService` doesn't work Spring Boot error handling
See original GitHub issueHi, Armeria team.
I migrated a synchronous Spring Boot application with embedded Tomcat to use Armeria server. As I can’t migrate all synchronous code to asynchronous and reactive code, I used TomcatService to connect with Armeria and Tomcat. And I found that the TomcatService does not handle error handling describe in the Spring Boot’s document:
By default, Spring Boot provides an /error mapping that handles all errors in a sensible way, and it is registered as a “global” error page in the servlet container. For machine clients, it produces a JSON response with details of the error, the HTTP status, and the exception message. For browser clients, there is a “whitelabel” error view that renders the same data in HTML format (to customize it, add a View that resolves to error).
Similarly, @ControllerAdvice does not work well:
You can also define a class annotated with @ControllerAdvice to customize the JSON document to return for a particular controller and/or exception type, as shown in the following example: …
Any JSON response is not respond from the Armeria server. And I guess it’s because the “global” error page in the servlet container does not called.
I made an example in my repository. The example have two applications, one is a Spring Boot application with embedded Tomcat. And the other one is similar application but integrated with the Armeria. Tests in both applications describe expected behavior and the Armeria application’s test is failed because JSON response does not exist.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (5 by maintainers)

Top Related StackOverflow Question
I am interested in this issue and have tried debugging it. 😎
As a result of doing this, the problematic parts are as follows. Each module in the example produces different results here.
https://github.com/apache/tomcat/blob/9747a3a6334369deb9b5bef1b17b1fe0ce774cdf/java/org/apache/catalina/core/StandardHostValve.java#L157-L165
https://github.com/apache/tomcat/blob/9747a3a6334369deb9b5bef1b17b1fe0ce774cdf/java/org/apache/coyote/Response.java#L207-L215
I think this is because we made a pure response from
TomcatServiceprovided by Armeria.https://github.com/line/armeria/blob/922d60304651f2e65fcf63a6f9090528fb937da7/tomcat9/src/main/java/com/linecorp/armeria/server/tomcat/TomcatService.java#L366
When we create a pure response,
ActionHookis empty.https://github.com/apache/tomcat/blob/9747a3a6334369deb9b5bef1b17b1fe0ce774cdf/java/org/apache/coyote/Response.java#L108
And
ActionHookis set only when it is made throughProcessor.https://github.com/apache/tomcat/blob/9747a3a6334369deb9b5bef1b17b1fe0ce774cdf/java/org/apache/coyote/AbstractProcessor.java#L83-L92
We should be able to call the intended
ErrorControllerby executingthrowable(...)in the code mentioned above. I know the cause, but I’m not sure exactly how to fix it. 🤣user? 🤔
It is one of the features provided by spring boot.