简体   繁体   中英

Apache Camel download file through http4

I'm trying to download and save a file using the following URL:

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

I've tried using a processor after the call in order to create the File:

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();
}

This is part of my route:

 <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}}/"/>

In AttachmnetProcessor i create variables for http request. In http response i get Content-Type=application/octet-stream. And i need to save file, that i get. But when i try transfer file to file endpoint, i save only file with ID exchange

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM