Announcement Announcement Module
Collapse
No announcement yet.
Downloading file using outbound-gateway Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Downloading file using outbound-gateway

    Hello,
    In my application, I need to download file from an http service.
    I am using an outbound-gateway configured like that:
    Code:
    <int-http:outbound-gateway id="srcFileGateway" 
            request-channel="transformer2gateway-srcFileChannel"
            url="{url}"
            http-method="GET"
            charset="UTF-8"
            expected-response-type="java.io.File"
            reply-timeout="180"
            reply-channel="gateway2transformer-srcFileChannel"
            >
            <int-http:uri-variable name="url" expression="headers['http_requestUrl']" />
        </int-http:outbound-gateway>
    But... it does not work, it seems that it is not possible to extract directly a file from payload, am I right?

    I tried with an expected-reponse-type="byte[]", it seems that I am getting the data in an array of bytes, but I have to convert it in a file? Is it the only way to do it? Or maybe I am doing something wrong?

  • #2
    Hello

    Let me ask you a question:
    1. How are file transfering via network?
    The answer: it is just byte[].
    So, what are you doing is OK: you're expecting byte[] and then just create a File Object and use something like org.apache.commons.io.FileUtils#writeByteArrayToFi le(..).

    2. How do you write your own download Servlet?
    You just plece File's bytes into ServletResponse's outputStream and don't think how browser converts them into a file.

    Good luck,
    Artem Bilan

    Comment


    • #3
      I just used:
      Code:
      tempFile = File.createTempFile("fileDownloaded", ".tmp");
      FileOutputStream fos = new FileOutputStream(tempFile);
      fos.write(m.getPayload());
      fos.close();
      return tempFile
      and I have to deal with these files because I need to download several files and create a zip file, it can't be managed by a browser
      thanks

      Comment

      Working...
      X