Apache的骆驼下载文件http4

问题描述:

我尝试下载并使用以下URL保存文件:Apache的骆驼下载文件http4

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

您的路线看起来如何?你是否有任何例外或你的处理器失败?此外,您的网址应该可能以'http4://'而不是'http://' – noMad17

+0

//开头//我无法获取文件。告诉确切的错误可以很容易地找出实际问题。 – niyasc

这是我的路线的一部分:

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

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