Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the actual file object from Camel FTP route exchange

In my Camel router:

from(<SourceURI>)
.process(new Processor() {
    @Override
    public void process(Exchange exchange) throws Exception {
        // I want to extract the file object from the exchange
    }
.to(<targetURI>).

How can I achieve this?

I tried e.g. exchange.getIn().getHeader(Exchange.FILE_NAME, String.class) which gives me the file name. I am searching for something Exchange.FILE which gives me the actual file object. My Ultimate goal is to extract the file in the processor as the routed exchange is an archive file.

like image 284
Suman Dhar Avatar asked Oct 24 '25 06:10

Suman Dhar


1 Answers

Get the file from the body. Camel uses a 'org.apache.camel.component.file.GenericFile' to store as the file body. But you can use Camel's type converters to get the file in a type you want.

For example you can get the content in different types, such as:

String text = exchange.getIn().getBody(String.class);
byte[] bytes = exchange.getIn().getBody(byte[].class);
InputStream is = exchange.getIn().getBody(InputStream.class); 
like image 166
Claus Ibsen Avatar answered Oct 27 '25 01:10

Claus Ibsen