对于我的spring集成流中的错误处理,我希望捕获服务激活器中的异常,它接收来自聚合器的输入,因此它可以处理消息的集合。当抛出异常时,整个集合将作为消息有效负载发送。相反,我希望将抛出异常的实际项作为错误消息的内容。
public Collection<File> move(Collection<File> files){
...
//process all files
for(File file : files){
if(file.getName().equals("file-2.done")){
throw new RuntimeException("SOMETHING WENT WRONG");
}
... process the file
}我的异常处理程序希望检索导致错误的文件。
File file = (File) message.getPayload().getFailedMessage().getPayload();但是在这种情况下,集合是作为有效负载发送的,而不是一个文件。任何帮助都将不胜感激。
发布于 2014-02-10 23:18:51
框架不知道move方法内部会发生什么。
你可以做一些类似..。
public classs MyFileFailureException extends RuntimeException {
private final File file;
public MyFileFailureException(String msg, File file) {
super(msg);
this.file = file;
}
public File getFailedFile() {return this.file}
}然后移动()..。
throw new MyFileFailureException("message", file);然后,用.
message.getPayload().getCause().getFailedFile().https://stackoverflow.com/questions/21689482
复制相似问题