春季整合:SMTP服务器
问题描述:
我正在使用Spring Integration 4.1.2。春季整合:SMTP服务器
在程序流程中,在流程结束时,我需要发送一封电子邮件。我正在使用以下:
<int:payload-type-router input-channel="response.in">
<int:mapping type="java.lang.String" channel="response.out"/>
<int:mapping type="org.springframework.mail.SimpleMailMessage" channel="mail.out"/>
</int:payload-type-router>
<mail:outbound-channel-adapter channel="mail.out" mail-sender="mailSender"/>
这工作正常。
我也想处理邮件服务器关闭的情况。
我试过以下解决方案,但它不起作用。
<int:chain input-channel="errorChannel" output-channel="emailErrorChannel">
<int:transformer ref="errorUnwrapper" />
</int:chain>
而解包:
@MessageEndpoint
public class ErrorUnwrapper {
@Transformer
public Message<?> transform(final ErrorMessage errorMessage) {
Message<?> failedMessage = ((MessagingException) errorMessage.getPayload()).getFailedMessage();
return failedMessage;
}
}
但是,这是行不通的。我想捕捉异常并向用户发送有意义的响应而不是堆栈跟踪。我希望在Spring Integration中做到这一点。否则,我将不得不使用服务激活器而不是SI mail
扩展来编写Java邮件服务调用。
答
您可能需要将errorChannel
添加到您开始流动的任何东西;您需要向我们展示其余的配置。
或者,您可以将ExpressionEvaluatingAdvice添加到邮件适配器;有关使用建议的示例,请参阅this sample。
非常感谢。你指出我的解决方案。我将errorChannel添加到http:入站网关,并解决了问题。 – adi