Spring integration Spring集成文件出站通道适配器和文件上次修改日期

Spring integration Spring集成文件出站通道适配器和文件上次修改日期,spring-integration,Spring Integration,我正在尝试使一个文件出站通道适配器写入一个文件,该文件的last modified date属性设置为自定义值,而不是系统当前时间 根据文档(),我应该在出站时将preserve timestamp属性设置为true,并将标题file\u setModified设置为消息中所需的时间戳 无论如何,我做了几次尝试都没有成功 这是一段代码片段,显示我现在正在做什么: <int:inbound-channel-adapter channel="msg.channel" expre

我正在尝试使一个文件出站通道适配器写入一个文件,该文件的last modified date属性设置为自定义值,而不是系统当前时间

根据文档(),我应该在出站时将
preserve timestamp
属性设置为
true
,并将标题
file\u setModified
设置为消息中所需的时间戳

无论如何,我做了几次尝试都没有成功

这是一段代码片段,显示我现在正在做什么:

<int:inbound-channel-adapter
    channel="msg.channel"
    expression="'Hello'">
    <int:poller fixed-delay="1000"/>
</int:inbound-channel-adapter>

<int:header-enricher
    input-channel="msg.channel"
    output-channel="msgEnriched.channel">

    <int:header
        name="file_setModified"
        expression="new Long(1473897600)"/>
</int:header-enricher>

<int-file:outbound-channel-adapter
    id="msgEnriched.channel"
    preserve-timestamp="true"
    directory="/tmp/foo"/>

怎么了


(使用Spring Integration 4.3.11)

如果您的
有效载荷
是一个
文件,则会覆盖
时间戳
值:

Object timestamp = requestMessage.getHeaders().get(FileHeaders.SET_MODIFIED);
...
if (payload instanceof File) {
    resultFile = handleFileMessage((File) payload, tempFile, resultFile);
    timestamp = ((File) payload).lastModified();
}
...
if (this.preserveTimestamp) {
    if (timestamp instanceof Number) {
        resultFile.setLastModified(((Number) timestamp).longValue());
    }
}
为了避免这种覆盖并真正从修改的文件中获得收益,您应该将
文件
转换为其
输入流

<transformer expression="new java.io.FileInputStream(payload)"/>

而不是那种定义。

感谢阿尔特姆的澄清。然而,当有效负载不是一个文件时,比如我发布的示例(以及在我的实际用例中发生的情况),情况又如何呢?无论如何,它似乎都不起作用。您发布的示例正是关于
文件
有效负载
生成文件的。您可以调试
FileWritingMessageHandler.HandlerRequestMessage()
并检查有效负载的情况。有些内容我不了解。入站通道适配器中的
表达式=“'Hello'”
是否产生
字符串。。。我现在看到你的代码了。让我在本地测试一下!无论如何:如何调试提到的代码?请参阅我的答案中的另一个更新。
<int:outbound-channel-adapter id="msgEnriched.channel">
    <bean class="org.springframework.integration.file.FileWritingMessageHandler">
        <constructor-arg value="/tmp/foo"/>
        <property name="preserveTimestamp" value="true"/>
        <property name="expectReply" value="false"/>
    </bean>
</int:outbound-channel-adapter>