2015-05-12 32 views
1

在我喝酒之前做了探索性的工作。File Poller FileListFilter施法例外

我想創建一個簡單的入站通道適配器來監視新的ZIP文件的目錄。

爲了應對永無止境的「完成嗎?」問題,我試圖修改發佈的示例here以合併FileListFilter,該文件檢查文件的修改時間。

不過,我收到以下異常:

a boolean result is requiredclass java.util.ArrayList is not assignable to class java.lang.Boolean 
at org.springframework.util.Assert.isAssignable(Assert.java:368) 
at org.springframework.integration.filter.AbstractMessageProcessingSelector.accept(AbstractMessageProcessingSelector.java:61) 
at org.springframework.integration.filter.MessageFilter.handleRequestMessage(MessageFilter.java:103) 
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:134) 
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:73) 

我有這個基於文件擴展名的簡單路由器工作良好,但是當我用此過濾器代替它,它土崩瓦解。似乎文件的實際列表是Assert試圖將其轉換爲布爾值的內容。

無法在入站和出站適配器之間連接過濾器嗎?或者我必須自己在過濾器中將文件移動到目的地嗎? (方式它在鏈接的示例完成)

這裏是配置:

<int-file:inbound-channel-adapter id="filePoller" directory="file:input" channel="filesChannel" filename-pattern="*.zip"> 
    <int:poller fixed-rate="2000" max-messages-per-poll="10" /> 
</int-file:inbound-channel-adapter> 
<int:filter input-channel="filesChannel" ref="lastModifiedFileFilter" output-channel="zipFilesOut"/> 

<bean id="lastModifiedFileFilter" class="FileFilterOnLastModifiedTime"> 
    <property name="timeDifference" value="10000"/>  
</bean> 
<int-file:outbound-channel-adapter id="zipFilesOut" directory="file:target/output/zip" delete-source-files="true" /> 

這裏是過濾器: 進口的java.io.File;

import org.springframework.integration.file.filters.AbstractFileListFilter; 

public class FileFilterOnLastModifiedTime extends AbstractFileListFilter<File> { 

Long timeDifference = 1000L; 

@Override 
protected boolean accept(File file) { 

    long lastModified = file.lastModified(); 
    long currentTime = System.currentTimeMillis(); 

    return (currentTime - lastModified) > timeDifference ; 
} 

public void setTimeDifference(Long timeDifference) { 
    this.timeDifference = timeDifference; 
    } 

} 

回答

0

FileFilterOnLastModifiedTime豆應提供使用filter屬性的入站適配器。

<int-file:inbound-channel-adapter id="filePoller" directory="file:input" channel="zipFilesOut" filename-pattern="*.zip" 
     filter="lastModifiedFileFilter"> 
    <int:poller fixed-rate="2000" max-messages-per-poll="10" /> 
</int-file:inbound-channel-adapter> 

內聯<filter/>元件是一個簡單的POJO,需要一些參數,並返回一個布爾值。

由於您提供的是AbstractFileListFilter,該框架試圖調用filterFiles,該函數接受一個數組並返回List而非布爾值。