question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`TomcatService` doesn't work Spring Boot error handling

See original GitHub issue

Hi, 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:closed
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
heowccommented, May 12, 2021

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 TomcatService provided 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, ActionHook is empty.

https://github.com/apache/tomcat/blob/9747a3a6334369deb9b5bef1b17b1fe0ce774cdf/java/org/apache/coyote/Response.java#L108

And ActionHook is set only when it is made through Processor.

https://github.com/apache/tomcat/blob/9747a3a6334369deb9b5bef1b17b1fe0ce774cdf/java/org/apache/coyote/AbstractProcessor.java#L83-L92

We should be able to call the intended ErrorController by executing throwable(...) in the code mentioned above. I know the cause, but I’m not sure exactly how to fix it. 🤣

0reactions
heowccommented, Jun 6, 2021

Who registers the exception handler using Armeria? TomcatService or a user?

user? 🤔

What is ‘white label’?

It is one of the features provided by spring boot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handle Embedded Tomcat Exception in Spring Boot
http://localhost:8080/working An IllegalArgumentException is thrown manually in the controller. It is then caught by the ControllerAdvice and will therefore ...
Read more >
Guide to Spring Boot REST API Error Handling - Toptal
Implement consumer-friendly support to a Spring Boot REST API by hiding implementation details and delivering easily digestible fields.
Read more >
Deploy a Spring Boot Application into Tomcat - Okta Developer
I have a Vaadin and Spring Boot app that runs in the Tomcat instance on a local server. Whenever I deploy it to...
Read more >
Web on Servlet Stack - Spring
In turn, the DispatcherServlet uses Spring configuration to discover the delegate components it needs for request mapping, view resolution, exception handling, ...
Read more >
How to Configure Spring Boot Tomcat - Baeldung
2. Common Embedded Tomcat Configurations · 2.1. Server Address and Port · 2.2. Error Handling · 2.3. Server Connections · 2.4. SSL ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found