Java 如何从侦听器类中的service activator消息对象获取文件

Java 如何从侦听器类中的service activator消息对象获取文件,java,spring,spring-integration,sftp,Java,Spring,Spring Integration,Sftp,我需要将文件传递到服务层,我正在SFTP路径中接收该文件。 下面是配置,我在我的service activator中看到消息接收,如 GenericMessage [payload=com.jcraft.jsch.ChannelSftp$2@322906a2, headers={closableResource=org.springframework.integration.sftp.session.SftpSession@379662a7, id=704c58e7-1d93-3bef-03

我需要将文件传递到服务层,我正在SFTP路径中接收该文件。 下面是配置,我在我的service activator中看到消息接收,如

GenericMessage [payload=com.jcraft.jsch.ChannelSftp$2@322906a2, 
headers={closableResource=org.springframework.integration.sftp.session.SftpSession@379662a7, 
id=704c58e7-1d93-3bef-0330-233c0f9af55c, file_remoteDirectory=/tmp/charge/, 
file_remoteFile=Charge.txt, timestamp=1594158522576}]

<bean id="sftpSessionFactory" 
class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
    <property name="host" value="hostname"/>
    <property name="port" value="22"/>
    <property name="user" value="vkp"/>
    <property name="password" value="1234"/>
    <property name="allowUnknownKeys" value="true"/>
</bean>
<int-sftp:inbound-streaming-channel-adapter id="sftpAdapterAutoCreate"
                                  session-factory="sftpSessionFactory"
                                  filename-pattern="*.txt"
                                  channel="receiveChannel"
                                  remote-directory="/tmp/charge/">
</int-sftp:inbound-streaming-channel-adapter>

<int:poller fixed-rate="25000" max-messages-per-poll="1" id="shippingChargePoller" default="true"/>

<int:channel id="receiveChannel">
    <int:queue/>
</int:channel>

<int:stream-transformer id="withCharset" charset="UTF-8"    input- 
channel="receiveChannel" />

<int:service-activator id="FeedListener" input-channel="receiveChannel"  method="onMessage">
    <bean class="com.listener.ChargeFeedListener"/>
</int:service-activator>


   public void onMessage(Message<?> message){
    System.out.println(message.toString());
    System.out.println( " Received File is  "+message.getPayload());
}
GenericMessage[payload=com.jcraft.jsch.ChannelSftp$2@322906a2, 
headers={closableResource=org.springframework.integration.sftp.session。SftpSession@379662a7, 
id=704c58e7-1d93-3bef-0330-233c0f9af55c,文件_remoteDirectory=/tmp/charge/,
文件_remoteFile=Charge.txt,时间戳=1594158522576}]
消息(消息消息)上的公共无效{
System.out.println(message.toString());
System.out.println(“收到的文件是”+message.getPayload());
}

但是我没有在java类中接收文件。获取文件需要做什么?

请阅读文档:。
与文件无关。它确实为远程条目(可能是SFTP上的文件)打开了一个
InputStream
,并允许您随意处理该流。例如(也根据那些文档),有一个
StreamTransformer
,如果您提供
字符集,它允许您将该流读入
字节[]
或字符串。如果你真的想处理文件,那么你需要考虑切换到<代码> <代码>。这一个拉远程条目并将其内容存储到本地文件中。然后将
java.io.File
发送到频道供您考虑

我想我们在另一个问题上和你聊过了你的问题:


请让我们知道我们的文档有什么问题让您感到困惑,所以您必须在这里提出类似的问题。

请阅读文档:。
与文件无关。它确实为远程条目(可能是SFTP上的文件)打开了一个
InputStream
,并允许您随意处理该流。例如(也根据那些文档),有一个
StreamTransformer
,如果您提供
字符集,它允许您将该流读入
字节[]
或字符串。如果你真的想处理文件,那么你需要考虑切换到<代码> <代码>。这一个拉远程条目并将其内容存储到本地文件中。然后将
java.io.File
发送到频道供您考虑

我想我们在另一个问题上和你聊过了你的问题:


请让我们知道我们的文档有什么问题让您感到困惑,因此您必须在这里提出类似的问题。

我添加了转换器,但在消息中看不到转换后的字符串或字节[]。我更新了当前配置。抱歉,我缺少的是。您现在拥有的就像是同一个
receiveChannel
的两个订户。您的
可能根本不会收到任何消息。此外,此转换器上没有可将结果发送到的
输出通道。我不确定您的逻辑是什么,但您可能需要从理论开始,了解什么是端点和通道:。您可能希望将转换器的结果发送到该
FeedListener
服务。因此,将变压器的
输出通道
作为service activator的
输入通道
。我添加了变压器,但在消息中看不到转换后的字符串或字节[]。我更新了当前配置。抱歉,我缺少的是。您现在拥有的就像是同一个
receiveChannel
的两个订户。您的
可能根本不会收到任何消息。此外,此转换器上没有可将结果发送到的
输出通道。我不确定您的逻辑是什么,但您可能需要从理论开始,了解什么是端点和通道:。您可能希望将转换器的结果发送到该
FeedListener
服务。因此,制作变压器的
输出通道
,作为维修激活器的
输入通道