In what version(s) of Spring Integration are you seeing this issue?
5.5.19
Describe the bug
I started seeing it after I have updated my Spring Integration based project from Spring Boot v2.6.15 to v2.7.17. After that my /health endpoint started returning "DOWN", showing mail component as culprit. Debugging showed that this happens due to an updated doHealthCheck method in MailHealthIndicator class:
Version in v2.6.15 looks like this:
@Override
protected void doHealthCheck(Builder builder) throws Exception {
builder.withDetail("location", this.mailSender.getHost() + ":" + this.mailSender.getPort());
this.mailSender.testConnection();
builder.up();
}
Version in v2.7.17 looks like this:
@Override
protected void doHealthCheck(Builder builder) throws Exception {
int port = this.mailSender.getPort();
builder.withDetail("location", (port != JavaMailSenderImpl.DEFAULT_PORT)
? this.mailSender.getHost() + ":" + this.mailSender.getPort() : this.mailSender.getHost());
this.mailSender.testConnection();
builder.up();
}
In both cases this.mailSender.getHost() is null, but in the latter one builder.withDetail throws IllegalArgumentException due to value argument being null. In first case it was just setting the location value to null:-1.
So, despite JavaMailSenderImpl works fine (sends e-mails successfully), /health for mail component fails due to host being null. And looks like such JavaMailSenderImpl initialization existed before, it just it surfaced with an update of MailHealthIndicator class.
To Reproduce
- Initialize a mail outbound-channel-adapter using
java-mail-propertiesas documentation instructs:Starting with version 5.1.3, the host, username ane mail-sender can be omitted, if java-mail-properties is provided. However, the host and username has to be configured with appropriate Java mail properties, e.g. for SMTP
<int-mail:outbound-channel-adapter channel="outboundEmailChannel"
java-mail-properties="javaMailProperties"
username="${email.smtp.username}"
password="${email.smtp.password}"/>
<util:properties id="javaMailProperties">
<prop key="mail.smtp.host">${email.smtp.server.host}</prop>
<prop key="mail.smtp.port">${email.smtp.server.port}</prop>
<prop key="mail.debug">${email.smtp.debug}</prop>
<prop key="mail.debug">${email.smtp.debug}</prop>
<prop key="mail.smtp.auth">${email.smtp.auth.enable}</prop>
<prop key="mail.smtp.starttls.enable">${email.smtp.starttls.enable}</prop>
</util:properties>
- Start up the application
- Access /health endpoint with details (using
management.endpoint.health.show-details=always) - Observe "DOWN" status with the following
mailfield:
"mail": {
"status": "DOWN",
"details": {
"error": "java.lang.IllegalArgumentException: Value must not be null"
}
},
Expected behavior
/health endpoint should return UP if JavaMailSenderImpl is correctly initialized via javaMailProperties. I would assume that either MailHealthIndicator should be updated or initialization of the JavaMailSenderImpl should set host/port from javaMailProperties.
Sample
I can come up with something if really needed in this case, but at the moment I hope that information above should be enough. Please let me know if otherwise. Thank you.
Comment From: artembilan
Even if Spring Integration creates that JavaMailSenderImpl internally based on those javaMailProperties, the problem is in Spring Boot.
Your suggestion about updating MailHealthIndicator in regard of consulting JavaMailSenderImpl.javaMailProperties is correct.
Moving the issue into Spring Boot project...
Comment From: wilkinsona
This is a regression that was introduced by the changes for https://github.com/spring-projects/spring-boot/issues/35247.