Hi folks,

I'm having a bit of an issue with accessing a file via a CAMEL route. I'm
trying to proxy a call to fetch the following file. The file I'm using to
illustrate this is a simple jpeg hosted on gravatar:

http://0.gravatar.com/avatar/9b62405c463e6be04e6578ae129a6270

When I git this directly using a REST client, the file comes back as
expected, i.e. it is displayable within the REST client and these are the
headers that are returned from this request:

Access-Control-Allow-Origin →*
Cache-Control →max-age=300
Content-Disposition →inline;
filename="9b62405c463e6be04e6578ae129a6270.jpeg"
Content-Length →2569
Content-Type →image/jpeg
Date →Fri, 01 Feb 2013 22:38:56 GMT
Expires →Fri, 01 Feb 2013 22:43:56 GMT
Last-Modified →Mon, 28 Nov 2011 22:02:47 GMT
Server →nginx
Source-Age →12
Via →1.1 varnish
X-Varnish →2352711313 2352700305

When I proxy that call via Jetty using the following route:

                <route trace="true" id="ProxyRepo">
                        <from
uri="jetty:http://0.0.0.0:8399/test2?matchOnUriPrefix=true&amp;chunked=false";
/>
                        <to
                        
uri="http://0.gravatar.com/avatar/9b62405c463e6be04e6578ae129a6270?bridgeEndpoint=true";
/>
                </route>

The file is not displayed within the REST client and instead you have the
malformed image symbol. The following are the headings returned by this
proxied route:

Accept →*/*
Accept-Charset →ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding →gzip,deflate,sdch
Accept-Language →en-GB,en-US;q=0.8,en;q=0.6
Accept-Ranges →bytes
Access-Control-Allow-Origin →*
Content-Disposition →inline;
filename="9b62405c463e6be04e6578ae129a6270.jpeg"
Content-Length →2423
Content-Type →image/jpeg;charset=ISO-8859-1
Cookie →session_id_8000=65a897a84e935d6e23715699b4f5a71c5843e477
Expires →Fri, 01 Feb 2013 23:19:43 GMT
Host →nb213:8399
Last-Modified →Mon, 28 Nov 2011 22:02:47 GMT
Server →ECS (lhr/478C)
Source-Age →12
User-Agent →Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.17 (KHTML, like
Gecko) Chrome/24.0.1312.57 Safari/537.17
X-Cache →HIT
X-Varnish →2352711313 2352700305
breadcrumbId →ID-nb213-59407-1359760442695-0-2

I'm not sure why the file is no longer displayable when proxied. This also
happens when instead of pulling the file from a remote location and instead
pull it off a location directory. The following is the route I use for that:

                <route trace="true" id="SimpleProxy">
                        <from
                        
uri="jetty:http://0.0.0.0:8299/test2?matchOnUriPrefix=true&amp;chunked=false";
/>
                        <to uri="direct:processFile" />
                </route>
                <route trace="true" id="FileRepo">
                        <from uri="direct:processFile" />
                        <to uri="bean:fileProcessor" />
                </route>

and my fileProcessor bean is simply:

import java.io.File;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;

public class FileProcessor implements Processor {

    public void process(Exchange exchange) throws Exception {
        String fileName = "tux.png";
        String finalFile = "";

        finalFile = "/data/9b62405c463e6be04e6578ae129a6270.jpeg";
        File file = new File(finalFile);
        if (file.exists()) {
            exchange.getIn().setBody(file);
        } else {
            exchange.getIn().setBody("File does not exist");
        }
        exchange.getIn().setHeader("Content-Disposition",
"inline;filename*=UTF-8''9b62405c463e6be04e6578ae129a6270.jpeg");
        exchange.getIn().setHeader("Content-Type", "image/jpeg");
    }
}

And again, the headers are:

Accept →*/*
Accept-Charset →ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding →gzip,deflate,sdch
Accept-Language →en-GB,en-US;q=0.8,en;q=0.6
Content-Disposition
→inline;filename*=UTF-8''9b62405c463e6be04e6578ae129a6270.jpeg
Content-Length →2423
Content-Type →image/jpeg;charset=ISO-8859-1
Cookie →session_id_8000=65a897a84e935d6e23715699b4f5a71c5843e477
Host →nb213:8299
Server →Jetty(7.5.3.v20111011)
User-Agent →Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.17 (KHTML, like
Gecko) Chrome/24.0.1312.57 Safari/537.17
breadcrumbId →ID-nb213-54075-1359761606244-0-2



--
View this message in context: 
http://camel.465427.n5.nabble.com/Camel-and-file-handling-tp5726797.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to