spring-integration - 在spring集成中成功发送到jms队列后重命名源目录中的文件。使用 ExpressionEvaluatingRequestHandlerAdvice
问题描述
得到以下异常AdviceMessage [payload = org.springframework.expression.spel.SpelEvaluationException:EL1008E:在'java.lang.String'类型的对象上找不到属性或字段'absolutePath' - 可能不是公共的或无效的?
看源代码。。
@Bean
@InboundChannelAdapter(value = "fileInputChannel", poller = @Poller(fixedDelay = "1000"))
public MessageSource<File> fileReadingMessageSource(@Value("${file.poller.path}") final String path,
@Value("${file.poller.fileName-pattern}") final String fileExt) {
CompositeFileListFilter<File> filters = new CompositeFileListFilter<>();
filters.addFilter(new SimplePatternFileListFilter(fileExt));
// filters.addFilter(new AcceptOnceFileListFilter<File>());
FileReadingMessageSource source = new FileReadingMessageSource();
source.setAutoCreateDirectory(false);
source.setDirectory(new File(path));
source.setFilter(filters);
source.setUseWatchService(true);
source.setWatchEvents(WatchEventType.CREATE);
System.out.println(path);
return source;
}
@Bean
public IntegrationFlow processFile() {
return IntegrationFlows
.from("fileInputChannel")
.transform(fileToStringTransformer())
.handle("fileProcessor", "process")//added some data manupilation code and returns Message<String>//
.log(LoggingHandler.Level.INFO, "process file", m -> m.getHeaders().get("Message_Type"))
.channel(this.jmsOutboundChannel())
.get();
}
@Bean
public IntegrationFlow sendToJmsQueue(JmsTemplate wlsJmsTemplate) {
return IntegrationFlows.from(this.jmsOutboundChannel())
.log(LoggingHandler.Level.INFO, "sending to queue", m ->
m.getHeaders().get("Message_Type"))
.handle(Jms.outboundAdapter(wlsJmsTemplate).destination(inboundDataQueue),
e -> e.advice(expressionAdvice()))
}
@Bean
public Advice expressionAdvice() {
ExpressionEvaluatingRequestHandlerAdvice advice = new ExpressionEvaluatingRequestHandlerAdvice();
advice.setSuccessChannelName("success.input");
advice.setOnSuccessExpressionString("payload.delete()");
//advice.setOnSuccessExpressionString("payload.renameTo(new java.io.File(payload.absolutePath + '.Done'))");
advice.setFailureChannelName("failure.input");
advice.setOnFailureExpressionString("payload.renameTo(new java.io.File(payload.absolutePath + '.FailedToSend'))");
advice.setTrapException(true);
return advice;
}
解决方案
使用 aFileReadingMessageSource
时,除了将 放入File
有效负载之外,该文件还作为标头添加,FileHeaders.ORIGINAL_FILE
以便以后发生转换时可用。
所以你的表达式需要使用
headers['file_originalFile'].renameTo(new java.io.File(headers['file_originalFile']).absolutePath + '.failed')
和
headers['file_originalFile'].delete()
推荐阅读
- gmail-api - Gmail API 防火墙设置
- c++ - Microsoft AMP 在 x64 中编译时引发内存错误
- python - 第一次无法使用正则表达式捕获 href 标记内容
- django - 带有 docker/celery/celery-beat 的 dbbackup 不起作用:没有错误但没有存储文件?
- blob - 如何从我的数据库中导出图像?
- java - java web应用中MVC的应用
- ios - 如何将用户在我的应用程序中输入的信息带到基于 Web 的应用程序,然后将结果从基于 Web 的应用程序返回到我的应用程序?
- discord.js - 我无法使用用户 ID 向用户发送 DM
- lua - 结合两个脚本 LUA
- sql - 获取表条件 SQL