Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jhipster Health Endpoint fails when mailserver not connected

JHipster / Spring boot provides a nice endpoint /management/health, where it aggregates health information for subsystems like db, disk, and mail. Unfortunately, when the connection to the mail server fails, the whole endpoint fails. So you do not get information what has failed.

I get a strack trace like this:

o.s.b.a.health.MailHealthIndicator       : Health check failed

com.sun.mail.util.MailConnectException: Couldn't connect to host, port: XXXX, NNNN25025; timeout -1
...
   at org.springframework.boot.actuate.health.MailHealthIndicator.doHealthCheck(MailHealthIndicator.java:40)
    at org.springframework.boot.actuate.health.AbstractHealthIndicator.health(AbstractHealthIndicator.java:43)
    at org.springframework.boot.actuate.health.CompositeHealthIndicator.health(CompositeHealthIndicator.java:68)
    at org.springframework.boot.actuate.endpoint.HealthEndpoint.invoke(HealthEndpoint.java:85)
    at org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.getCurrentHealth(HealthMvcEndpoint.java:177)
    at org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.getHealth(HealthMvcEndpoint.java:166)
    at org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.invoke(HealthMvcEndpoint.java:143)

This is spring boot 1.5.9 Where should I fix this, so that the exception is catched and instead a an error status is returned?

like image 959
Meier Avatar asked Jul 27 '18 09:07

Meier


People also ask

What is actuator health endpoint?

Actuator endpoints let you monitor and interact with your application. Spring Boot includes a number of built-in endpoints and lets you add your own. For example, the health endpoint provides basic application health information. Each individual endpoint can be enabled or disabled.

Which of the following actuator endpoint is not enabled by default?

In order to access the actuator endpoints using HTTP, we need to both enable and expose them. By default, all endpoints but /shutdown are enabled. Only the /health and /info endpoints are exposed by default.

What is the default health check URL in spring boot?

The application will start on port 8080 by default. Once the application has started, you can list all the actuator endpoints exposed over HTTP from the URL http://localhost:8080/actuator . The status will be UP as long as the application is healthy.


1 Answers

You have to turn on your SMTP server or disable checks to it.

To disable checks to SMTP server:

management.health.mail.enabled=false

To disable checks to all server:

management.health.defaults.enabled=false

for more information, see http://www.briansjavablog.com/2017/09/health-checks-metric-s-more-with-spring.html

I believe you can handle this error with the ExceptionHandler for 1.5.9 version of Spring Boot since the newer version there is no such problem:

     @ControllerAdvice
     public class ExceptionController {

        @ExceptionHandler(MailConnectException.class)
        public ResponseEntity<?> mailExceptionHandler(MailConnectException e) {
              // Do your treatment ...
            } ... 
    }
like image 134
Guilherme Alencar Avatar answered Oct 13 '22 20:10

Guilherme Alencar