Apache Camel通过http4下载文件

时间:2017-03-03 19:07:41

标签: http apache-camel jbossfuse

我正在尝试使用以下网址下载并保存文件:

http://{{host}}:{{port}}/pls/apex/edoapi/getfile/{{idattachment}}

我在调用后尝试使用处理器来创建文件:

if (exchange.getIn().getBody() != null) {

    InputStream stream = exchange.getIn().getBody(InputStream.class);
    String disposition= (String) exchange.getIn().getHeader("Content-Disposition");
    int index = disposition.indexOf("filename=");
    if (index > 0) {
        String filename = disposition.split("=")[1].trim().replaceAll("\"","");
        LOGGER.info("filename:" + filename);
        String name = URLDecoder.decode(filename,"UTF-8");
        LOGGER.info("name:" + name);
        filePath = path+name;
    }
    LOGGER.info("filepath:" + filePath);        

    FileOutputStream outputStream = new FileOutputStream(new File(filePath));
    int bytesRead = -1;
    byte[] buffer = new byte[BUFFER_SIZE];
    while ((bytesRead = stream.read(buffer)) != -1) {
        outputStream.write(buffer, 0, bytesRead);
    }

    outputStream.close();
    stream.close();
}

1 个答案:

答案 0 :(得分:0)

这是我路线的一部分:

 <process id="_cprocess13" ref="AttachmentProcessor"/>
            <toD id="_to10" uri="http4://{{host}}:{{port}}/pls/apex/edoapi/getfile/${property.token}/${property.md5hashsum.toUpperCase()}/{{idattachment}}"/>
            <!--<process id="_cprocess14" ref="SaveAttachments"/>
            <convertBodyTo type="java.io.File" charset="utf-8"/>-->
            <to id="_to11" uri="file:/home/public/attachmnets/{{idattachment}}/"/>

在AttachmnetProcessor中,我为http请求创建变量。 在http响应中,我得到Content-Type = application / octet-stream。我需要保存文件,我得到。 但是当我尝试将文件传输到文件端点时,我只保存带有ID交换的文件

相关问题