我想在完成SFTP上传后发送电子邮件...
我有一个SFTP上传器:
<sftp:outbound-channel-adapter
id="sftpOutboundAdapter"
channel="inputFiles"
charset="UTF-8"
remote-directory="${directory.remote}"
session-factory="sftpSessionFactory">
<sftp:request-handler-advice-chain>
<bean class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
<property name="onSuccessExpression" value="payload.delete()"/>
<property name="successChannel" ref="successChannel"/>
<property name="onFailureExpression" value="payload.renameTo(payload.absolutePath + '.error')"/>
<property name="failureChannel" ref="failChannel"/>
</bean>
</sftp:request-handler-advice-chain>
</sftp:outbound-channel-adapter>
完成后,将有效负载发送到successChannel:
<int:channel id="successChannel">
<int:interceptors>
<int:wire-tap channel="successLogChannel"/>
</int:interceptors>
</int:channel>
...然后通过窃听记录它。
<int:channel id="successLogChannel"/>
<int:transformer input-channel="successLogChannel" output-channel="logChannel"
expression="'Successfully transferred ' + inputMessage.payload.absolutePath + ' [result=' + payload + ']'"/>
<int:logging-channel-adapter id="logChannel" level="INFO"/>
这里它正在破碎,我不认为属性是正确的元素使用,我基本上需要突破到java类,并能够传入参数,包括我刚刚上传的文件的名称。
<int:service-activator input-channel="successChannel" ref="Email" method="sendSuccessMail">
<property name="to" value="test@gmail.com" />
<property name="from" value="me@me.com" />
<property name="filename" ref="'inputMessage.payload.absolutePath'" />
</int:service-activator>
Java类:
@Component(value = "Email")
public class Email extends AbstractMessaging<EmailRequest, EmailResponse> {
....
public void sendSuccessMail(String to, String from, String filename){
log.info("--------------------------------------------");
log.info("Success Mail will be sent here to" + to + ", from " + from + " for " + filename);
log.info("--------------------------------------------");
}
}
FactoryBean在对象创建时抛出异常;嵌套异常是 java.lang.IllegalArgumentException:类型为[class]的目标对象 .email.Email]没有合格的方法来处理消息。
如果我不能使用方法sendSuccessMail
,那么是否可以传递params或仅传递有效负载?
答案 0 :(得分:1)
使用<header-enricher/>
在标题中创建所需的值;然后...
public void sendSuccessMail(@Header("to") String to, @Header("from") String from, @Payload String filename){
...
}
<int:chain ...>
<int:header-enricher>
<int:header name="to" value="test@gmail.com">
...
<int:header name="inputMessage" expression="inputMessage">
</int:header-enricher>
<int:transformer expression="headers['inputMessage'].payload.absolutePath">
<int:service-activator ... />
</int:chain>