【问题标题】:How to get the actual file object from Camel FTP route exchange如何从 Camel FTP 路由交换中获取实际的文件对象
【发布时间】:2015-10-25 02:30:40
【问题描述】:

在我的 Camel 路由器中:

from(<SourceURI>)
.process(new Processor() {
    @Override
    public void process(Exchange exchange) throws Exception {
        // I want to extract the file object from the exchange
    }
.to(<targetURI>).

我怎样才能做到这一点?

我试过了,例如exchange.getIn().getHeader(Exchange.FILE_NAME, String.class) 这给了我文件名。 我正在寻找 Exchange.FILE 的东西,它给了我实际的文件对象。我的最终目标是在处理器中提取文件,因为路由交换是存档文件。

【问题讨论】:

    标签: apache-camel camel-ftp


    【解决方案1】:

    从正文中获取文件。 Camel 使用 'org.apache.camel.component.file.GenericFile' 作为文件体存储。但是你可以使用 Camel 的类型转换器来获取你想要的类型的文件。

    例如可以获取不同类型的内容,如:

    String text = exchange.getIn().getBody(String.class);
    byte[] bytes = exchange.getIn().getBody(byte[].class);
    InputStream is = exchange.getIn().getBody(InputStream.class); 
    

    【讨论】:

    • 如果你想要文件名使用String filename = exchange.getIn().getBody(GenericFile.class).getFileName();
    • 也许您的邮件正文为空?
    【解决方案2】:

    对于那些拥有from("file:...") 的人,以下作品:

    File in = exchange.getIn().getBody(File.class);
    

    【讨论】:

      猜你喜欢
      • 2018-03-27
      • 1970-01-01
      • 2018-07-25
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 2011-01-10
      • 1970-01-01
      相关资源
      最近更新 更多