2015-06-10 77 views
2

我正在使用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邮件服务调用。

或者它是单向组件吗?我刚刚发现这个blog的帖子也是这样做的。我也读过this,但没有得到。

回答

1

您可能需要将errorChannel添加到您开始流动的任何东西;您需要向我们展示其余的配置。

或者,您可以将ExpressionEvaluatingAdvice添加到邮件适配器;有关使用建议的示例,请参阅this sample

+0

非常感谢。你指出我的解决方案。我将errorChannel添加到http:入站网关,并解决了问题。 – adi